matlab dsp toolbox

798
7/27/2019 Matlab DSP Toolbox http://slidepdf.com/reader/full/matlab-dsp-toolbox 1/798 Computation Visualization Programming For Use with M ATLAB ® User’s Guide Ver si on 5 Signal Processing Toolbox

Upload: christian-fonseca-rodriguez

Post on 14-Apr-2018

361 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 1/798

Computation

Visualization

Programming

For Use with MATLAB ®

U ser’s G uideVer si on 5

Signa l P rocessingToolbox

Page 2: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 2/798

How to Contact The M athW orks:

www.mathworks.com Webcomp.soft-sys.matlab Newsgroup

[email protected] Technica l s [email protected] P roduct enhan cement [email protected] B ug [email protected] Documentation error reports

[email protected] Order status, license renewals, [email protected] Sa les, pricing, an d general informa tion

508-647-7000 P hone

508-647-7001 Fa x

The Ma t hWorks, Inc. Ma il

3 Apple Hill D riveNatick, MA 01760-2098

For cont a ct informat ion about w orldwide offices, see the Ma th Works Web site.

Sign al Pr ocessin g Toolbox U ser ’s Gu id e ©COPYRIGHT 1988 - 2001 by The MathWorks, Inc.The softwa re described in this document is furnish ed under a license agr eement. The softwa re may be usedor copied only und er the t erms of the license agreement. No pa rt of th is ma nua l ma y be photocopied or repro-duced in a ny form w ithout prior writt en consent from The Mat hWorks, Inc .

FED ERAL ACQUI SITION: This provision a pplies to all a cquisitions of the Progra m a nd Documentation byor for the federal government of the U nited Sta tes. By accepting delivery of the Pr ogram, the governmenthereby agrees that this softwa re qualifies a s "commercial" computer softwa re within t he meaning of FARP a rt 12.212, DFARS P a rt 227.7202-1, DFARS P a rt 227.7202-3, DFARS P ar t 252.227-7013, and D FARS P ar t252.227-7014. The term s a nd conditions of The Ma th Works, Inc. Softw ar e License Agreement sha ll perta into the government’s use a nd disclosure of the P rogram a nd Documenta tion, and shall supersede anyconflicting contr a ctua l terms or conditions. If this license fails to meet the government ’s minimum n eeds oris inconsistent in any respect with federal procurement law , the government a grees to return t he Progra mand Documenta tion, unused, to MathWorks.

MATLAB, Simulink, Sta teflow, Ha ndle Gra phics, a nd Rea l-Time Workshop a re registered tra demarks, a nd

Tar get La nguage C ompiler is a tra demark of The Mat hWorks, Inc.Other product or bra nd na mes are t radema rks or registered tra demarks of their respective holders.

P rin t ing H ist ory : 1988 Origina l pr in t ingJ a n u a r y 1997 F ir s t p ri nt in g N ew f or M ATL AB 5. 1J anua ry 1998 Second p rint i ng Rev ised for MATLAB 5.2J a n ua r y 1999 (On lin e on ly ) R ev is ed for Ver sion 4.2 (R elea s e 11)Au gu st 1999 (On lin e on ly ) R ev is ed for Ver sion 4.3 (R elea s e 11. 1)September 2000 Third printing Revised for Version 5.0 (Release 12)J u ne 2001 (On line on ly ) R evised for Ver sion 5.1 (R elea se 12.1)

Page 3: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 3/798

i

Contents

Preface

Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xvi

What Is the Signal Processing Toolbox? . . . . . . . . . . . . . . . . xvii

R12 Related Products List . . . . . . . . . . . . . . . . . . . . . . . . . . . .xviii

How to Use This Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiIf You Are a New U ser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiIf You Are an E xperienced Toolbox User . . . . . . . . . . . . . . . . . xxiiAll Toolbox U sers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii

Installing the Signal Processing Toolbox . . . . . . . . . . . . . . . xxiii

Technical Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiv

Typographical Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . .xxv

1Signal Processing Basics

Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-2

Signal Processing Toolbox Central Features . . . . . . . . . . . . 1-3Filt ering a nd F FTs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3Sign a ls a nd S yst ems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3Key Area s: Filter Design a nd S pectr a l Ana lysis . . . . . . . . . . . . 1-3In ter a ctive Tools: S P Tool a nd F DATool . . . . . . . . . . . . . . . . . . . 1-4E xten sibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-4

Page 4: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 4/798

ii Contents

Representing Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-5Vector R epresent a tion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5

Waveform Generation: Time Vectors and Sinusoids . . . . . . 1-7Common Sequences: Unit Im pulse, U nit St ep, and U nit Ra mp 1-8Mult icha nn el Signa ls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-8Comm on P eriodic Wa veform s . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9Comm on Aperiodic Wa veforms . . . . . . . . . . . . . . . . . . . . . . . . . 1-10The pulst ra n F unct ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-11The S inc Fu nction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-12The Dir ichlet Fu nction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-13

Working with Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-14

Filter Implementation and Analysis . . . . . . . . . . . . . . . . . . . 1-15Convolut ion a nd F ilterin g . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-15Filters a nd Tra nsfer Fu nctions . . . . . . . . . . . . . . . . . . . . . . . . . 1-16

Filter C oefficients a nd F ilter Na mes . . . . . . . . . . . . . . . . . . 1-16

Filtering w ith t he filter Function . . . . . . . . . . . . . . . . . . . . . . . 1-17

The filter Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-18

Other Functions for Filtering . . . . . . . . . . . . . . . . . . . . . . . . . 1-20Multira te Filter B a nk Implementa tion . . . . . . . . . . . . . . . . . . 1-20Ant i-Ca usa l, Zero-P ha se Filter Implementa tion . . . . . . . . . . . 1-21Frequ ency Domain Filter I mplementa tion . . . . . . . . . . . . . . . . 1-23

Impulse Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-24

Frequency Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-25Digit a l Doma in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-25Ana log Doma in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-27Ma gnitu de an d P ha se . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-27Dela y . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-29

Zero-Pole Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-31

Linear System Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-33Dis crete-Time S yst em Models . . . . . . . . . . . . . . . . . . . . . . . . . . 1-33

Page 5: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 5/798

iii

Tra nsfer F unct ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-33Zero-P ole-G a in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-34St a te-Spa ce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-35

P a rt ial Fr a ction Expa nsion (Residue Form) . . . . . . . . . . . . 1-36Second-Order Sections (SOS ) . . . . . . . . . . . . . . . . . . . . . . . . 1-38La t tice St ruct ure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-38Convolut ion Ma tr ix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-41

Cont inuous-Time Sy st em Models . . . . . . . . . . . . . . . . . . . . . . . 1-42Linea r S yst em Tra nsforma tions . . . . . . . . . . . . . . . . . . . . . . . . 1-43

Discrete Fourier Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-45

Selected Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-48

2Filter Design

Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-2

Filter Requirements and Specification . . . . . . . . . . . . . . . . . . 2-3

IIR Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-5Cla ssica l IIR Fil ter Design U sing Ana log Pr ototyping . . . . . . . 2-7

Complete C lass ica l IIR Filter D esign . . . . . . . . . . . . . . . . . . . 2-7Designing IIR Filters to Frequ ency Doma in Specifica tions . 2-8

Compa rison of Cla ssical II R Filt er Types . . . . . . . . . . . . . . . . . . 2-9B ut terw orth F ilter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-9Ch ebysh ev Type I F ilter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10Ch ebysh ev Type II Filt er . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11E lliptic Filt er . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-11

B essel Filt er . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-12Dir ect II R Filt er Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-14G eneralized B ut terw orth Filt er Design . . . . . . . . . . . . . . . . 2-15

FI R Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-17Lin ea r P ha se Filt ers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-18Window ing Met hod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-19

Page 6: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 6/798

iv Contents

St a nda rd B a nd FIR F il ter Design: f ir1 . . . . . . . . . . . . . . . . 2-21Multiba nd F IR F ilter Design: fir2 . . . . . . . . . . . . . . . . . . . . 2-22

Multiband FIR Fil ter Design wit h Tra nsit ion B a nds . . . . . . . 2-23

B a sic Configur a t ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-23The Weigh t Vect or . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-26Ant i-Sym metric Filters /Hilbert Tra nsformers . . . . . . . . . . 2-26Differen tia t ors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-27

Constra ined Lea st S qua res FIR Fil ter Design . . . . . . . . . . . . . 2-28B a sic Lowpass a nd H ighpass CLS Filter Design . . . . . . . . . 2-29Multiba nd C LS Filter D esign . . . . . . . . . . . . . . . . . . . . . . . . 2-30Weight ed CL S F ilter D esign . . . . . . . . . . . . . . . . . . . . . . . . . 2-31

Arbit ra ry-Response F ilter D esign . . . . . . . . . . . . . . . . . . . . . . . 2-32Mult iba nd F ilter D esign . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-33Filter D esign wit h Reduced Delay . . . . . . . . . . . . . . . . . . . . 2-35

Special Topics in IIR Filter Design . . . . . . . . . . . . . . . . . . . . 2-38Ana log Pr ototype D esign . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-39Fr equen cy Tra nsform a tion . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-39

Filt er D iscretiza tion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-42Im pulse In va ria nce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-42B ilinea r Tra nsform a tion . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-43

Selected Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-46

3Statistical Signal Processing

Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-2

Correlation and Covariance . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3B ia s a nd Norma lizat ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-4Mult iple Cha nn els . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-5

Spectral Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-6Spectra l Est ima tion Method Overview . . . . . . . . . . . . . . . . . . . . 3-8Nonpa ra met ric Meth ods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-10

The P eriodogra m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-10

Page 7: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 7/798

v

P erforma nce of th e P eriodogra m 3-12The Modified P eriodogra m . . . . . . . . . . . . . . . . . . . . . . . . . . 3-18Welch’s Meth od . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-20

B ias a nd Norma lizat ion in Welch’s Meth od . . . . . . . . . . . . . 3-23Mult ita per Meth od . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-24Cross-Spectr a l Densit y Fun ction . . . . . . . . . . . . . . . . . . . . . 3-27Confiden ce Int erva ls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-27Tra nsfer Fun ction E stima te . . . . . . . . . . . . . . . . . . . . . . . . . 3-28Coheren ce Funct ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-29

P a ra met ric Meth ods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-30Yule-Wa lker AR Met hod . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-32B urg M eth od . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-33Covar ian ce a nd Modified Covar ia nce Methods . . . . . . . . . . 3-36MU SI C a nd E igenvector Ana lysis Methods . . . . . . . . . . . . . 3-36E igena na lysis Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-37

Selected Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-39

4Special Topics

Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2

Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3B a sic Sh a pes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3G enera lized Cosine Window s . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-5Ka iser Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-6

Ka iser Window s in F IR D esign . . . . . . . . . . . . . . . . . . . . . . . . 4-8Ch ebyshev Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-10

Parametric Modeling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-12Time-Doma in B a sed Modeling . . . . . . . . . . . . . . . . . . . . . . . . . 4-14

Linea r P rediction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-14P rony’s Meth od (ARMA Modeling) . . . . . . . . . . . . . . . . . . . . 4-15St eiglitz-McB ride Met hod (ARMA Modeling) . . . . . . . . . . . 4-17

Fr equency-Doma in B a sed Modeling . . . . . . . . . . . . . . . . . . . . . 4-19

Page 8: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 8/798

vi Contents

Resampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-22

Cepstrum Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-25

In verse Complex Cepst ru m . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-27

FFT-Based Time-Frequency Analysis . . . . . . . . . . . . . . . . . . 4-29

Median Filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-30

Communications Applications . . . . . . . . . . . . . . . . . . . . . . . . . 4-31

Deconvolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-35

Specialized Transforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-36Ch irp z-Tra nsform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-36Dis crete Cosine Tra nsform . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-38H ilbert Tra nsform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-40

Selected Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-42

5Filter Design and Analysis Tool

Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-2Filt er Design Meth ods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3U sing t he Filter Design a nd Ana lysis Tool . . . . . . . . . . . . . . . . . 5-4Ana lyzing Filt er Responses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4Filt er Design a nd Ana lysis Tool Modes . . . . . . . . . . . . . . . . . . . 5-4G ett ing H elp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-5

Opening the Filter Design and Analysis Tool . . . . . . . . . . . . 5-6

Choosing a Filter Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-7

Choosing a Filter Design Method . . . . . . . . . . . . . . . . . . . . . . . 5-8

Page 9: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 9/798

vii

Setting the Filter Design Specifications . . . . . . . . . . . . . . . . . 5-9B a ndpa ss Filter Fr equency Specifica tions . . . . . . . . . . . . . . . . . 5-9B a ndpa ss Filter Ma gnitu de Specifica tions . . . . . . . . . . . . . . . . 5-10

Filt er Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-11

Computing the Filter Coefficients . . . . . . . . . . . . . . . . . . . . . 5-12

Analyzing the Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-13

Converting the Filter Structure . . . . . . . . . . . . . . . . . . . . . . . 5-15

Importing a Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-17Filt er St ruct ures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-18

Dir ect Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-18Dir ect Form I I (Second -Order S ections) . . . . . . . . . . . . . . . . 5-19St a te-Spa ce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-19La t tice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-19Qua nt ized Filt er (Qfilt Object) . . . . . . . . . . . . . . . . . . . . . . . 5-20

Exporting a Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-21E xportin g Filt er Coefficient s to th e Workspa ce . . . . . . . . . . . . 5-21E xportin g Filt er Coefficient s to a Text File . . . . . . . . . . . . . . . 5-22Exporting t o a C H eader F ile . . . . . . . . . . . . . . . . . . . . . . . . . . 5-22

Saving and Opening Filter Design Sessions . . . . . . . . . . . . . 5-25

6SPTool: A Signal Processing GUI Suite

Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-2

SPTool: An Interactive Signal Processing Environment . . 6-3SP Tool Da ta St ructur es . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-3

Opening SPTool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-5

Page 10: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 10/798

viii Contents

Getting Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-7Cont ext-Sen sit ive H elp: The Wha t ’s This? Bu tt on . . . . . . . . . . 6-7

Overview of the Signal Browser: Signal Analysis . . . . . . . . . 6-8Opening t he Signa l B rowser . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-8

Overview of the Filter Designer: Filter Design . . . . . . . . . . 6-11Filt er Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-11FI R Filt er Meth ods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-11II R Filt er Meth ods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-11P ole/Zero Ed it or . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-12Spectra l Overla y Fea tur e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-12Opening t he Filt er Design er . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-12

Overview of the Filter Viewer: Filter Analysis . . . . . . . . . . 6-14Opening t he F ilter Viewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-14

Overview of the Spectrum Viewer: Spectral Analysis . . . . 6-17

Opening t he Spectr um Viewer . . . . . . . . . . . . . . . . . . . . . . . . . 6-17

Using SPTool: Filtering and Analysis of Noise . . . . . . . . . . 6-20Im port ing a Sig na l int o SP Tool . . . . . . . . . . . . . . . . . . . . . . . . . 6-20Design ing a Filt er . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-22

Opening t he Filt er Design er . . . . . . . . . . . . . . . . . . . . . . . . . 6-22Specifying th e Ba ndpa ss Filt er . . . . . . . . . . . . . . . . . . . . . . . 6-22

Applying a Filter t o a S igna l . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-24Ana lyzing Signa ls: Opening the Sign a l Br owser . . . . . . . . . . . 6-26

P lay ing a Signa l . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-27P rint ing a Signa l . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-27

Spectra l Ana lysis in th e Spectr um View er . . . . . . . . . . . . . . . . 6-28Crea ting a P SD Object F rom a S igna l . . . . . . . . . . . . . . . . . 6-29Opening t he Spectr um View er wit h Tw o Spectra . . . . . . . . 6-29P rint ing t he Spectr a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-30

Exporting Signals, Filters, and Spectra . . . . . . . . . . . . . . . . 6-32Opening t he E xport Dia log Box . . . . . . . . . . . . . . . . . . . . . . 6-32E xport ing a Filt er to th e MATLAB Workspa ce . . . . . . . . . . 6-33

Accessing Filter Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . 6-34

Page 11: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 11/798

ix

Accessing Filter P a ra meters in a Sa ved Filter . . . . . . . . . . . . . 6-34The t f Field: Accessing Filt er Coefficient s . . . . . . . . . . . . . . 6-34The Fs F ield: Accessing F ilter S a mple Freq uency . . . . . . . . 6-34

The specs Field: Accessing oth er Filter P a ra meters . . . . . . 6-35Accessing Pa ra meters in a S a ved Spectr um . . . . . . . . . . . . . . 6-37

Importing Filters and Spectra into SPTool . . . . . . . . . . . . . 6-39Im portin g Filt ers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-39Im portin g S pectr a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-41

Loading Variables from the Disk . . . . . . . . . . . . . . . . . . . . . . 6-43

Selecting Signals, Filters, and Spectra in SPTool . . . . . . . . 6-44

Editing Signals, Filters, or Spectra in SPTool . . . . . . . . . . . 6-45

Designing a Filter with the Pole/Zero Editor . . . . . . . . . . . . 6-46P ositioning P oles a nd Zeros . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-47

Redesigning a Filter Using the Magnitude Plot . . . . . . . . . 6-49

Setting Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-50

Making Signal Measurements: Using Markers . . . . . . . . . . 6-52

7Function Reference

Function Category List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-3

Alphabetical List of Functions . . . . . . . . . . . . . . . . . . . . . . . . . .20a bs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-26a c2poly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-27a c2rc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-28a ngle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-29a rbur g . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-30

Page 12: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 12/798

x Contents

a rcov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-31a rmcov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-32a ryu le . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-33

ba rt ha nn w in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-34ba rt lett . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-36bessela p . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-38besself . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-39bilinea r . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-42bitr evorder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-47bla ckma n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-49bla ckma nh a rr is . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-51

bohma nw in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-53buffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-55but ta p . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-64but ter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-65but tord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-70cceps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-75cell2sos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-77cheb1ap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-78cheb1ord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-79cheb2ap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-83cheb2ord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-84chebwin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-89cheby1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-90cheby2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-95chir p . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-100

cohere . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-106conv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-110conv2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-111convm t x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-113corrcoef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-115corr mt x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-116cov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-119cplxpa ir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-120cremez . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-121csd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-129czt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-133dct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-136decima te . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-138deconv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-141

Page 13: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 13/798

xi

dem od . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-142dft mt x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-144dir ic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-145

down sa mple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-146dps s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-148dpssclea r . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-151dpssd ir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-152dpssloa d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-153dpsssa ve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-154ellip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-155ellipap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-161

ellipord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-162eqt flengt h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-167fda tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-168fft . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-170fft 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-173fftfilt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-174ffts hift . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-176filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-177filter2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-180filtern orm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-181filtfilt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-183filt ic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-184fir1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-186fir2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-190fircls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-193

fircls 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-196firls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-199firr cos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-204freqs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-206freqs pa ce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-208freqz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-209freqz plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-213fvt ool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-216ga uspuls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-220ga ussw in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-222gmonopuls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-224goertzel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-226grpd elay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-231ha mmin g . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-234

Page 14: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 14/798

xii Contents

ha nn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-236hilbert . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-238icceps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-242

idct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-243ifft . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-244ifft 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-245impinva r . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-246impz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-248int erp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-251int filt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-253invfr eqs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-255

invfr eqz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-259is2rc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-262ka iser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-263ka iserord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-265la r2rc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-270la t c2t f . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-271la t cfilt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-272levinson . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-274lp2bp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-276lp2bs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-279lp2hp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-281lp2lp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-283lpc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-285lsf2poly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-289ma xfla t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-290

medfilt 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-292modula te . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-293nu tt a llwin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-296pburg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-299pcov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-304peig . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-309periodogra m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-316pmcov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-321pmt m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-326pmu sic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-331poly2a c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-339poly2lsf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-340poly2rc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-341polyscale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-343

Page 15: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 15/798

xiii

polysta b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-344prony . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-345psdplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-347

pulst ra n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-349pw elch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-353pyulea r . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-359rc2a c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-364rc2is . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-365rc2lar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-366rc2poly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-367rceps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-368

rectpuls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-369rectw in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-370remez . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-371remezord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-378resa mple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-381residu ez . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-384rlevinson . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-387rooteig . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-390rootmu sic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-393sa w tooth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-396schur rc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-397seqperiod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-398sgola y . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-400sgola yfilt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-404sin c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-406

sos2cell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-408sos2ss . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-409sos2t f . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-411sos2zp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-413sosfilt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-415specgra m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-416spt ool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-420squ a re . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-425ss2sos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-426ss2tf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-430ss2zp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-431st mcb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-433st rips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-436t f2lat c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-438

Page 16: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 16/798

xiv Contents

t f2sos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-439t f2ss . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-442t f2zp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-444

t fe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-447t ria ng . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-451t ripuls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-453t ukeyw in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-454ud ecode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-456uen code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-459un w ra p . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-462upfird n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-463

upsa mple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-467vco . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-469w indow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-471xcorr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-473xcorr2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-477xcov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-478yulew a lk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-481zp2sos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-483zp2ss . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-487zp2tf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-488zpla ne . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-489

Page 17: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 17/798

Preface

Overview . . . . . . . . . . . . . . . . . . . . . xvi

What Is the Signal Processing Toolbox? . . . . . . . xvii

R12 Related Products List . . . . . . . . . . . . . . xviii

How to Use This Manual . . . . . . . . . . . . . . xxiIf You Are a New U ser . . . . . . . . . . . . . . . . xxiIf You Are a n E xperienced Toolbox U ser . . . . . . . . . xxiiAll Toolbox U sers . . . . . . . . . . . . . . . . . . xxii

Installing the Signal Processing Toolbox . . . . . . . xxiii

Technical Conventions . . . . . . . . . . . . . . . xxiv

Typographical Conventions . . . . . . . . . . . . . xxv

Page 18: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 18/798

Preface

xvi

OverviewThis cha pter provides a n int roduction t o the Signa l P rocessing Toolbox an d t hedocument a tion. It cont a ins th e follow ing sections:

• “Wha t Is th e Sign a l P rocessing Toolbox?”• “R12 Rela ted P roducts List”• “How t o Use This Man ual”• “Inst a lling the S igna l P rocessing Toolbox”• “Technical Conventions”• “Typogra phica l Conventions”

Page 19: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 19/798

W hat Is the Signal Processing Toolbox?

xvii

What Is the Signal Processing Toolbox?The S igna l P rocessing Toolbox is a collect ion of tools built on t he MATLAB ®

num eric computin g environment. The toolbox support s a wide r a nge of signalprocessing operat ions, from wa veform genera tion to filter design a ndimplement a tion, para metric modeling, and spectra l ana lysis. The toolboxprovides two categories of tools:

• Signa l processing comma nd line functions• A suite of graph ica l user interfa ces for:

- Interactive filter design- Signal plott ing and analysis- Spectral analysis- Filtering signals- Ana lyzing filter designs

Page 20: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 20/798

Preface

xviii

R12 Related Products ListThe Ma th Works provides severa l products t ha t a re especia lly releva nt to th ekinds of ta sks you ca n perform w ith t he Signa l P rocessing Toolbox.

For more informa tion a bout a ny of these products, see either:

• The online document a tion for th a t product if it is insta lled or if you a rereading t he documenta tion from th e CD

• The Ma th Works Web site, a t http://www.mathworks.com ; see the “products”section

Note The t oolboxes list ed below a ll include functions t ha t ext end MATLAB’scapa bilities. The blocksets a ll include blocks t ha t extend S imulink’scapabilities.

Product Description

CommunicationsBlockset

Simulink block libra ries for m odeling t hephysical lay er of communicat ions syst ems

Communica tions Toolbox MATLAB functions for modeling the physica llayer of communicat ions syst ems

Da ta Acquisit ion Toolbox MATLAB funct ions for direct a ccess t o live,mea sured da ta from MATLAB

Da ta ba se Toolbox Tool for connecting to, a nd intera cting wit h,most ODB C/J DB C da ta bases from wit hinMATLAB

Page 21: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 21/798

R12 Related Products List

xix

Developer’s K it for Texa sIns t rumen t s™ DSP

Developer’s kit that unites MATLAB,Sim ulink, a nd Rea l-Time Workshop codegenera tion with the Texa s Inst ruments C odeComposer Studio™ to provide DSP softwa re/syst ems ar chitects w ith suit e of tools for DS Pdevelopment, from simulat ing signa l

processing a lgorith ms t o optimizing a ndrunn ing code on Texas In str ument s DSP s

D SP B lockset S imulink block libra ries for t he design ,simulat ion, a nd prototyping of digita l signalprocessing syst ems

F uz zy L og ic Toolbox Tool t o h elp ma s t er fu zz y log ic t ech niq ues a n dth eir a pplica tion t o pra ctica l cont rol problems

Ima ge P rocessingToolbox

Complete suite of digita l ima ge processing a nda na lysis t ools for MATLAB

Neural Netw ork Toolbox Comprehensive environment for neura lnetwork research, design, a nd simula tionw ith in MATLAB

Motorola DSP

Developer’s Kit

Developer's kit for co-simulating and verifying

Motorola 56300 a nd 56600 fixed-point DS Pcode. Combines th e a lgorith m development,simulation, and verification capabilities of theMa th Works system-level design tools w ith th eMotorola S uite 56® assembly langua gedevelopment a nd debugging t ools

Opt imiza t ion Toolbox Tool for genera l and l a rge-sca le op t imiza t ion ofnonlinear problems, as w ell a s for linearprogra mming, quadra tic programming,nonlinear least squa res, and solving nonlinea requations

Product Description

Page 22: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 22/798

Preface

xx

S imulink Int era ct ive, gra ph ica l environment formodeling, simulating, and prototypingdyna mic systems

S t at ist ics Toolbox Tool for a na lyzin g h ist or ica l da t a , m odelin gsystems, developing sta tist ical a lgorithms, a ndlearning and teaching statist ics

Syst em Ident ificationToolbox

Tool for buildin g a ccura te, sim plified models ofcomplex systems from noisy t ime-series da ta

Wa velet Toolbox Tool for signa l a nd ima ge a na lysis,compression, and de-noising

Product Description

Page 23: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 23/798

H ow to Use This M anual

xxi

How to Use This ManualThis section explains h ow to use the document a tion to get help a bout t he Signa lP rocessing Toolbox. Read th e topic th a t best fits your skill level:

• “If You Are a New U ser”• “If You Are a n E xperienced Toolbox User ”• “All Toolbox U ser s”

If You Are a New UserB egin with C ha pter 1, “Signa l Pr ocessing B a sics .” This cha pter int roduces t heMATLAB sign a l processing environment th rough t he t oolbox functions. Itdescribes th e ba sic functions of t he S igna l P rocessing Toolbox, reviewin g it s usein ba sic waveform generat ion, f i l ter implementa tion an d a na lysis, impulse andfrequency response, zero-pole an a lysis, linea r syst em models, a nd t he discreteFourier tra nsform.

When you feel comforta ble with th e basic functions, move on t o Cha pter 2 an dCh a pter 3 for a more in-depth int roduction t o using t he Signa l Pr ocessingToolbox:

• Chapter 2, “Filter Design,” for a detailed explan a tion of using the Signa lProcessing Toolbox in infinite impulse response (IIR) and finite impulseresponse (FIR) filter d esign a nd implement a tion, including special topics inIIR filter design.

• Cha pter 3, “Sta tist ical Signa l Processing,” for how to use the correla tion,covaria nce, a nd spectra l a na lysis tools to est imat e importan t functions ofdiscrete ra ndom signals.

Once you underst a nd t he genera l principles a nd a pplicat ions of the t oolbox,learn how t o use the intera ctive tools:

• Ch a pter 5, “Filter Design a nd Ana lysis Tool,” a nd Ch a pter 6, “SP Tool: A

Signa l Processing GU I Suite,” for a n overview of the int eractive GU Ienvironments a nd exam ples of how t o use th em for signa l explora tion, filterdesign a nd implementa tion, a nd spectral a na lysis.

Fina lly, see the follow ing chapt er:

P f

Page 24: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 24/798

Preface

xxii

• Ch a pter 4, “Specia l Topics,” for specialized functions, including filterwindows, pa ra metric modeling, resampling, cepstrum a na lysis,time-dependent Fourier transforms and spectrograms, median filtering,communica tions a pplica tions, deconvolution, an d specia lized t ra nsforms.

If You Are an Experienced Toolbox UserS ee Cha pter 5, “Filter Design a nd Ana lysis Tool,” a nd Cha pter 6, “SP Tool: ASigna l Processing GU I Suite,” for a n overview of the interactive GU Ienvironment s a nd exam ples of how t o use th em for signa l viewin g, filter designa nd implementa tion, an d spectral a na lysis.

All Toolbox UsersU se Chapter 7, “ Function Reference, ” for loca ting informa tion on specificfunctions. Reference descriptions include a synopsis of th e function’s syn ta x, a sw ell a s a complete expla na tion of options a nd opera tions. Man y reference

descriptions also include helpful examples, a description of the function’sa lgorithm, a nd references to addit ional reading ma terial .

U se this ma nua l in conjunction with the softw a re to lea rn a bout t he powerfulfeat ures th a t MATLAB provides. Ea ch chapter provides numerous exam plesthat apply the toolbox to representative signal processing tasks.

Some examples use MATLAB’s r a ndom n umber genera tion function randn . Inth ese ca ses, to duplica te th e results in the exam ple, type

randn('state',0)

before runn ing t he example.

ll h l lb

Page 25: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 25/798

Installing the Signal Processing Toolbox

xxiii

Installing the Signal Processing ToolboxTo determine if t he S igna l P rocessing Toolbox is inst a lled on your syst em, ty peth is comma nd a t t he MATLAB prompt.

ver

When you enter th is comma nd, MATLAB display s informa tion a bout th eversion of MATLAB y ou ar e runn ing, including a list of a ll toolboxes insta lledon your syst em a nd t heir version n umbers.

For informa tion a bout inst a lling the toolbox, see the M AT L A B I n st a l l a t i on G u i d e for your plat form.

Preface

Page 26: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 26/798

Preface

xxiv

Technical ConventionsThis ma nua l a nd t he Sign a l P rocessing Toolbox functions use th e follow ingtechnical notat ions.

Nyquist frequency One-ha lf t he sa mpling frequency. S ometoolbox functions norma lize this va lue to 1.

x(1) The first element of a da ta sequence orfilter, corresponding to zero lag.

Ω or w Ana log frequency in ra dia ns per second.

ω or w Digita l frequency in ra dians per sa mple.

f Digita l frequency in hertz.

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

... Ellipses in the a rgument l ist for a givensynt a x on a function reference pageindica te a ll possible argument l ists for t ha tfunction appear ing prior t o the givensyntax a re val id .

Typographical C onventions

Page 27: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 27/798

Typographical C onventions

xxv

Typographical ConventionsThis ma nua l uses some or a ll of th ese convent ions.

Item Convention Used Example

Exa mple code Monospace font To a ssign t he va lue 5 t o A ,enter

A = 5

Fun ction na mes/synt a x Monospace font The cos function finds thecosine of each a rra y element .Synt a x l ine exa mple isMLGetVar ML_var_name

Keys Boldface with a n in it ia l capita lletter

P ress the Return key.

Literal str ings (in synta xdescriptions in referencechapters)

Monospace bold for literals f = freqspace(n,' whole ')

Mathemat icalexpressions

I t a l i c s for variablesSt a nda rd text font for functions,operat ors, and consta nts

This vector represents th epolynomial

p = x 2 + 2x + 3

MATLAB outpu t Monospace font MATLAB responds w it h A =

5

Menu tit les, menu items,dia log boxes, a nd cont rols

Boldface with a n in it ia l capita lletter

Ch oose the File menu.

New terms I t a l i c s An a r r a y is an orderedcollection of information.

O mit t ed in pu t a rgu m en t s (.. .) ell ip sis den ot es a ll of t heinput/output a rgument s frompreceding syntaxes.

[c,ia,ib] = union(...)

String variables (from afinite list)

Monospace italics sysc = d2c(sysd,' method ')

Preface

Page 28: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 28/798

xxvi

1

Page 29: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 29/798

1

S igna l P rocessing B a sics

Overview . . . . . . . . . . . . . . . . . . . . . 1-2

Signal Processing Toolbox Central Features . . . . . 1-3

Representing Signals . . . . . . . . . . . . . . . . 1-5

Waveform Generation: Time Vectors and Sinusoids . . 1-7

Working with Data . . . . . . . . . . . . . . . . . 1-14

Filter Implementation and Analysis . . . . . . . . . 1-15

The filter Function . . . . . . . . . . . . . . . . . 1-18

Other Functions for Filtering . . . . . . . . . . . . 1-20

Impulse Response . . . . . . . . . . . . . . . . . 1-24

Frequency Response . . . . . . . . . . . . . . . . 1-25

Zero-Pole Analysis . . . . . . . . . . . . . . . . . 1-31

Linear System Models . . . . . . . . . . . . . . . 1-33

Discrete Fourier Transform . . . . . . . . . . . . . 1-45

Selected Bibliography . . . . . . . . . . . . . . . 1-48

1 Signal Processing Basics

Page 30: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 30/798

1-2

OverviewThis cha pter describes how t o begin using MATLAB a nd t he Signa l P rocessingToolbox for y our signa l processing a pplicat ions. I t a ssumes a ba sic knowledgea nd understa nding of signals a nd systems, including such t opics a s f i lter a ndlinear system theory and basic Fourier analysis. The chapter covers thefollow ing t opics:

• “Signa l P rocessing Toolbox Centr a l Feat ures”• “Representing Signa ls”• “Wa veform G enera tion: Time Vectors a nd Sinusoids”• “Working with Da ta ”• “Fil ter Implementa tion an d Analysis”• “The filter Function”• “Other Fu nctions for Filtering”•

“Impulse Response”• “Frequency Response”• “Zero-P ole Ana lysis”• “Linear System Models”• “Discrete Fourier Tra nsform”• “Selected Bibliography”

Many examples throughout the chapter demonstrate how to apply toolboxfunctions. If you a re not a lready fa miliar w ith MATLAB’s signa l processingcapa bilities, use th is cha pter in conjunction with th e softw a re to try examplesa nd learn a bout t he powerful fea tures a vailable to you.

Signal Processing Toolbox C entral Features

Page 31: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 31/798

1-3

Signal Processing Toolbox Central FeaturesThe S igna l P rocessing Toolbox functions a re a lgorith ms, expressed mostly inM-files, th a t implement a va riety of signa l processing ta sks. These toolboxfunctions a re a specia lized extension of th e MATLAB comput a tiona l a ndgra phica l environment.

Filtering and FFTsTw o of th e most importa nt fu nctions for signa l processing a re not in the Sign a lProcessing Toolbox at all, but are built-in MATLAB functions:

• filter a pplies a digita l f il ter to a da ta sequence.• fft calculat es the discrete Fourier tra nsform of a sequence.

The operat ions th ese functions perform ar e the ma in comput a tiona lw orkhorses of cla ssical signa l processing. B oth a re described in this cha pter.The S igna l P rocessing Toolbox uses ma ny other st a nda rd MATLAB fun ctionsa nd la ngua ge fea tur es, including polynomial root finding, complex a rith metic,ma trix inversion a nd ma nipula tion, and gra phics tools.

Signals and SystemsThe basic enti t ies tha t toolbox functions w ork w ith ar e signals a nd syst ems.The functions empha size digita l, or discrete, signa ls a nd filters, a s opposed t oa na log, or cont inuous, signa ls. The principal filter t ype th e toolbox support s is

the l inear, t ime-invaria nt d igita l f il ter with a single input a nd a single output.You can r epresent linear t ime-inva ria nt syst ems using one of severa l models(such as transfer function, state-space, zero-pole-gain, and second-ordersection) a nd convert betw een representa tions.

Key Areas: Filter Design and Spectral AnalysisIn a ddition t o its core functions, t he t oolbox provides rich, customizable support

for t he key a reas of f il ter design a nd spectra l a na lysis. I t is easy t o implementa d esign techniq ue tha t suit s your a pplicat ion, design digita l filters directly, orcreat e an a log prototypes an d discretize them. Toolbox functions also estima tepower spectral density and cross spectral density, using either parametric ornonpar a metric t echniques. “Filter Design” on pa ge 2-1 a nd “Sta t is t ica l SignalP rocessing” on pa ge 3-1 , respectively detail toolbox functions for filter designan d spect ra l a nalys is.

1 Signal Processing Basics

Page 32: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 32/798

1-4

Some filter design an d spectr a l an a lysis functions included in th e toolbox are

• computation and graphical display of frequency response• system identification• genera ting signals• discret e cosine, chirp- z, an d H i lber t t ra nsforms• lattice filters• resampling• time-frequency analysis• basic communication systems simulation

Interactive Tools: SPTool and FDAToolThe power of th e Signa l P rocessing Toolbox is grea tly enha nced by itseasy -to-use int era ctive tools. SP Tool provides a rich gra phical environment forsignal viewing, f i lter design, an d spectra l a na lysis. The Fil ter Design a ndAna lysis Tool (FDATool) provides a more comprehen sive collection of fea tu resfor addressing the problem of filter design. The FDATool also offers seamlessa ccess to the add it iona l f i lter design methods a nd qu an tizat ion feat ures of theFilter D esign Toolbox wh en th a t product is insta lled.

ExtensibilityP erhaps t he most importa nt fea ture of the MATLAB environment is tha t i t is

extensible: MATLAB lets you create your own M-files to meet numericcomput a tion n eeds for resea rch, design, or engineering of signa l processingsyst ems. Simply copy t he M-files provided w ith th e Sign a l P rocessing Toolboxa nd modify them a s needed, or creat e new functions t o expa nd t he functiona li tyof th e t oolbox.

Representing Signals

Page 33: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 33/798

1-5

Representing SignalsThe cent ra l da ta const ruct in MATLAB is th e num er i c ar r ay , an orderedcollection of rea l or complex numeric dat a wit h t w o or m ore dimensions. Thebas ic dat a objects of signa l processing (one-dimensional signa ls or sequences,multicha nnel signa ls, and t wo-dimensional signals) a re all na tura lly suited toarray representation.

Vector RepresentationMATLAB represents ordina ry one-dimensional sa mpled dat a signa ls, orsequences, a s vectors . Vectors a re 1-by- n or n -by-1 ar ra ys, w here n is thenum ber of sa mples in t he sequence. One wa y to intr oduce a sequence intoMATLAB is t o ent er it a s a list of elements a t t he comma nd prompt. Thesta tement

x = [4 3 7 -9 1]

creat es a simple five-element rea l sequence in a row vector. Tra nspositiontu rns t he sequence into a column vector

x = x'

resulting in

x =437

-91

Column orienta tion is prefera ble for single cha nnel signa ls because it extendsna tura lly to the multicha nnel case. For multicha nnel dat a, ea ch column of ama trix represents one cha nnel. Ea ch row of such a ma trix th en corresponds t oa sa mple point. A th ree-chan nel signal t ha t consist s of x , 2x , and x /π is

y = [x 2*x x/pi]

1 Signal Processing Basics

Page 34: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 34/798

1-6

This results 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

W aveform G eneration: Time Vectors and Sinusoids

Page 35: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 35/798

1-7

Waveform Generation: Time Vectors and SinusoidsA va riety of toolbox functions genera te w a veforms. Most r equire you to beginwit h a vector representing a t ime ba se. Consider generat ing dat a wit h a 1000H z sa mple frequency, for exa mple. An a ppropriat e time vector is

t = (0:0.001:1)';

where MATLAB ’s colon operator creates a 1001-element row vector thatrepresent s t ime runn ing from zero t o one second in st eps of one millisecond.The t ra nspose operat or (') chan ges the row vector into a column; th esemicolon ( ; ) tells MATLAB t o compute but n ot display th e result.

Given t you can create a sam ple signa l y consist ing of tw o sinusoids, one at 50Hz a nd one a t 120 Hz with tw ice the amplitude.

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

The new va ria ble y , formed from vector t , is a lso 1001 element s long. You can

a dd normally distr ibuted white noise to the signal a nd gra ph the f irst f if typoints using

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

0 0.01 0.02 0.03 0.04 0.05−3

−2

−1

0

1

2

3

4

1 Signal Processing Basics

Page 36: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 36/798

1-8

Common Sequences: Unit Impulse, Unit Step, andUnit RampSince MATLAB is a program ming la ngua ge, an endless va riety of differentsigna ls is possible. Here a re some sta tement s tha t genera te severa l commonlyused sequences, including th e unit impulse, unit st ep, a nd unit r a mp functions.

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 th ese sequences ar e column vectors. The la st th ree inherit t heir sha pesfrom t .

Multichannel SignalsU se sta nda rd MATLAB a rra y synta x to work with multichann el signals. Forexa mple, a multicha nnel signal consist ing of the last three signals generat edabove is

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

You can genera te a mu lticha nnel unit sa mple function using the outer productopera tor. F or example, a six-element column vector w hose first element is one,a nd w hose rema ining five element s ar e zeros, is

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

To duplica te column vector a into a ma trix without performing an ymult iplica tion, u se MATLAB ’s colon opera tor a nd t he ones function.

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

W aveform G eneration: Time Vectors and Sinusoids

Page 37: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 37/798

1-9

Common Periodic WaveformsThe t oolbox provides fun ctions for genera ting w idely used periodic wa veforms:

• sawtooth generates a sa wt ooth w ave wi th peaks a t ±1 a nd a period of . Anoptional width para meter specifies a fractiona l multiple of a t wh ich thesigna l’s ma ximum occurs.

• square genera tes a square wa ve wit h a period of . An optiona l para meterspecifies du ty cycle , th e percent of the period for wh ich t he signa l is positive.

To genera te 1.5 seconds of a 50 Hz sa w tooth w a ve with a sa mple rat e of 10 kHza nd plot 0.2 seconds of th e generat ed wa veform, use

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

2π2π

0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2-1

-0.5

0

0.5

1

1 Signal Processing Basics

Page 38: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 38/798

1-10

Common Aperiodic WaveformsThe t oolbox a lso provides functions for genera ting several w idely useda periodic wa veforms:

• gauspuls genera tes a G a ussian-modula ted sinusoida l pulse with a specifiedtime, center frequency, a nd fra ctiona l bandw idth. Optiona l para metersreturn in-phase a nd qua dra ture pulses, the RF signa l envelope, an d th ecutoff time for th e tr a iling pulse envelope.

• chirp genera tes a linear sw ept-frequency cosine signa l. An optiona lparameter specifies alternative sweep methods. An optional parameter phi a llow s initia l pha se to be specified in degrees.

To compute 2 seconds of a l inear chirp signal with a sam ple ra te of 1 kHz, tha ts tar t s a t DC a nd crosses 150 Hz a t 1 second, use

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

To plot the spectrogram, use

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

Time

F r e q u e n c y

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.60

50

100

150

200

250

300

350

400

450

500

W aveform G eneration: Time Vectors and Sinusoids

Page 39: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 39/798

1-11

The pulstran FunctionThe pulstran function generat es pulse tr a ins from eith er cont inuous orsa mpled prototy pe pulses. The follow ing example genera tes a pulse tra inconsistin g of the sum of mult iple delayed int erpolat ions of a G a ussia n pulse.The pulse tra in is defined to have a sam ple ra te of 50 kHz, a pulse tra in lengthof 10 ms, and a pulse repeti t ion rat e of 1 kHz; Dspecifies t he delay to each pulserepeti t ion in column 1 and a n optional a t t enuat ion for ea ch repeti t ion incolumn 2. The pulse tra in is constructed by pa ssing the na me of th e gauspuls function to pulstran , a long wi th addi t ional para meters tha t speci fy a 10 kHzG aussian pulse wi th 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)

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

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

1 Signal Processing Basics

Page 40: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 40/798

1-12

The Sinc FunctionThe sinc function computes the ma th emat ica l sinc function for a n input vectoror ma tr ix x . The sinc function is t he cont inuous inverse Fourier t ra nsform oft h e r ect a n gu la r pu ls e of w i dt h a n d h eig ht 1.

The sinc function has a value of 1 where x is zero, an d a va lue of

for a ll oth er element s of x .

To plot t he sinc function for a linearly spaced vector w ith va lues ra nging from-5 to 5, use th e followin g comma nds.

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

2 π

πx ( )sinπx

--------------------

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

-0.2

0

0.2

0.4

0.6

0.8

1

W aveform G eneration: Time Vectors and Sinusoids

Page 41: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 41/798

1-13

The Dirichlet FunctionThe toolbox function diric comput es th e Dirichlet function, sometimes calledt he per iodi c sin c or ali ased sin c function, for an input vector or mat rix x . TheDirichlet function is

where n is a user-specified positive int eger. For n odd, the D irichlet fun ctionha s a period of ; for n even, its period is . The ma gnitu de of th is functionis (1/ n ) times t he ma gnitu de of the discrete-time Fourier tr a nsform of th en -point recta ngular window.

To plot th e Dirichlet fun ction over th e ra nge 0 to 4 π for n = 7 a nd n = 8 , use

x = linspace(0,4*pi,300);

plot(x,diric(x,7))plot(x,diric(x,8))

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

n x 2 ⁄ ( )sinn x 2 ⁄ ( )sin---------------------------- otherwise

=

2 π 4π

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

1 Signal Processing Basics

Page 42: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 42/798

1-14

Working with DataThe exa mples in t he preceding sections obta in da ta in one of tw o wa ys:

• B y direct input , tha t i s , enter ing the dat a manua l ly a t t he keyboard• B y usin g a MATLAB or t oolbox function, such a s sin , cos , sawtooth , square ,

or sinc

Some applica tions, however, may need to import da ta from outs ide MATLAB.

Depending on your da ta forma t, you ca n do this in th e following w a ys:• Load data from an ASCII file or MAT-file with MATLAB ’s load command.• Rea d t he da ta into MATLAB w ith a low -level file I/O function, such a s fopen ,

fread , and fscanf .• Develop a ME X-file to read t he da ta .

Other r esources are a lso useful, such a s a high-level lan gua ge progra m (inFortr a n or C, for exa mple) th a t converts your da ta into MAT-file format – seeth e MATLAB E xter na l Int erfa ces/AP I Reference for det a ils. MATLAB rea dssuch files using t he load command.

Similar t echniques are a vailable for exporting da ta genera ted wit hinMATLAB. S ee the MATLAB d ocumenta tion for more deta ils on import ing a ndexporting da ta .

Filter Implementation and A nalysis

Page 43: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 43/798

1-15

Filter Implementation and AnalysisThis section describes how to filter discrete signals using MATLAB ’s filter function a nd oth er functions in th e Signa l P rocessing Toolbox. It a lso discusseshow t o use the toolbox functions to an a lyze filter cha ra cteristics, includingimpulse response, magn itude a nd pha se response, group delay, a nd zero-polelocations.

Convolution and FilteringThe mathematical foundation of filtering is convolution. MATLAB’s conv function performs sta nda rd one-dimensional convolution, convolving onevector with a nother.

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

ans =

1 2 3 2 1

Note Convolve recta ngula r ma tr ices for t w o-dimensional signa l processingusing the conv2 function.

A digita l filter ’s output y (k ) is relat ed to its input x (k ) by convolution w ith itsimpulse response h (k ).

If a digita l filter ’s impulse response h (k ) is finite lengt h, a nd t he input x (k ) isa lso finite lengt h, you ca n implement t he filter using conv . Store x (k ) in a vectorx , h (k ) in a vector h , an d convolve the t wo.

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

y k ( ) h k ( ) x k ( )∗ h k l –( ) x l ( )

l ∞–=

∑= =

1 Signal Processing Basics

Page 44: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 44/798

1-16

Filters and Transfer FunctionsIn general , the z -transform Y (z ) of a d igita l filter ’s output y (n ) is relat ed to thez -transform X (z ) of the input by

where H (z ) is t he filt er ’s tr ansfer fu nction . Here, the consta nts b (i ) a nd a (i ) a reth e filter coefficients a nd t he order of th e filter is t he ma ximum of n a nd m .

Note The filter coefficient s sta rt wit h subscript 1, rat her t ha n 0. This reflectsMATLAB’s s ta nda rd indexing scheme for vectors.

MATLAB st ores t he coefficients in t w o vectors, one for th e numera tor a nd onefor t he denomina tor. B y convent ion, MATLAB uses r ow vectors for filter

coefficients.

Filter Coefficients and Filter NamesMan y sta nda rd na mes for f i l ters reflect the number of a a nd b coefficientspresent:

• When n = 0 (t h a t i s, b is a scala r), the filter is a n Infinit e Impulse Response(II R), all-pole, recurs ive, or a ut oregressive (AR) filter.

When m= 0 (t h a t i s, a is a sca lar ), the filter is a F inite Impulse Response(FI R), all-zero, nonrecurs ive, or m oving a vera ge (MA) filter.• If both n a nd ma re great er th a n zero, the filter is an IIR , pole-zero, recursive,

or autoregressive moving average (ARMA) filter.

The a cronym s AR, MA, a nd ARMA a re usua lly a pplied to filters a ssocia tedw ith filtered st ocha stic processes.

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

a 1( ) a 2( ) z 1– L a m 1+( ) z m –+ + +---------------------------------------------------------------------------------------- X z ( )= =

Filter Implementation and A nalysis

Page 45: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 45/798

1-17

Filtering with the filter FunctionIt is simple to work back to a difference equa tion from the z -transform relationshown ea rlier. Assume tha t a (1) = 1. Move the denomina tor to the left-ha ndside a nd ta ke the inverse z -transform.

In terms of current a nd past inputs, an d past outputs, y (n ) is

This is the sta nda rd t ime-doma in represent a tion of a d igita l filter, computedstar t ing wi th y (1) a nd a ssuming zero initial condit ions. This representa tion’sprogression is

A filter in this form is easy t o implement w ith t he filter function. Forexa mple, a simple single-pole filter (low pa ss) is

b = 1; % Numeratora = [1 -0.9]; % Denominator

w here the vectors b a nd a represent th e coefficients of a filter in tr a nsferfunction form. To apply this filter t o your da ta , use

y = filter(b,a,x);

filter gives you a s ma ny output samples as th ere a re input sa mples, tha t is ,the length of y is the same a s the length of x . If th e first element of a i s not 1,filter divides the coefficients by a(1) before implementing th e difference

equation.

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

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

y 1( ) b 1 x 1( )=

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

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

M M=

1 Signal Processing Basics

Page 46: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 46/798

1-18

The filter Functionfilter is implemented a s the tr a nsposed direct-form II str ucture shown below ,where n -1 is th e filter order. This is a ca nonica l form t ha t h a s th e minimumnumber of dela y element s.

At sample m , filter comput es th e difference equa tions

In it s most basic form, filter init ial izes t he delay outputs z i (1), i = 1, ... ,n -1

to 0. This is equivalent t o assuming both past inputs a nd outputs a re zero. Setthe init ial dela y outputs using a fourth input par a meter to filter , or a ccessthe final delay outputs using a second output para meter.

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

Access to initia l a nd fina l condit ions is useful for filtering da ta in sections,especia lly if memory limita tions a re a considerat ion. Suppose you ha vecollected da ta in t wo segment s of 5000 point s each.

x1 = randn(5000,1); % Generate two random data sequences.x2 = randn(5000,1);

P erhaps t he first sequence, x1 , corresponds t o th e first 10 minutes of da ta a ndth e second, x2 , to a n a ddit iona l 10 minutes. The w hole sequence is x = [x1;x2] .If t here is not su fficient memory t o hold t he combined sequence, filter t he

Σ Σ Σ 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 ( ) z 1

m 1–( )+=

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

M M=

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

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

The fi lter Function

Page 47: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 47/798

1-19

subsequences x1 a nd x2 one at a time. To ensur e continuit y of the filtered

sequences, use the fina l condit ions fr om x1 a s initia l conditions to filter x2 .[y1,zf] = filter(b,a,x1);y2 = filter(b,a,x2,zf);

The filtic function generat es initia l condit ions for filter . filtic computesth e dela y vector to ma ke the beha vior of th e filter reflect past inputs a ndoutputs t ha t you specify. To obta in th e same output dela y va lues zf a s aboveusing filtic , use

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

This can be useful when fi l tering short da ta sequences, as a ppropriat e init ialconditions help reduce transient startup effects.

1 Signal Processing Basics

Page 48: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 48/798

1-20

Other Functions for FilteringIn a ddi t ion to filter , severa l other fun ctions in th e Signa l P rocessing Toolboxperform th e ba sic filtering opera tion. These functions include upfirdn , wh ichperforms FIR fi ltering w ith resampling, filtfilt , which eliminat es phasedistort ion in t he filtering process, fftfilt , which performs t he FIR filteringopera tion in t he frequency domain, a nd latcfilt , which fi lters using a lat t iceimplementation.

Multirate Filter Bank ImplementationThe function upfirdn a lters the sampling rate of a signa l by a n integer ra tioP /Q. It comput es the result of a ca scade of three systems t ha t performs thefollowing tasks:

• U psa mpling (zero insert ion) by integer fa ctor p• Filtering by FIR filter h•

Downsa mpling by integer fa ctor q

For example, to cha nge the sample rat e of a signa l from 44.1 kHz to 48 kHz, wefirst find the smallest integer conversion ratio p/q . Set

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

In t his exa mple, p = 160 a nd q = 147 . Sa mple rat e conversion is thena ccomplished by t yping

y = upfirdn(x,h,p,q)

This casca de of opera tions is implement ed in a n efficient ma nner u singpolypha se filtering techniques, a nd it is a centr a l concept of multira te filtering(see refer ence [ 1] for deta ils on mu ltirat e f i lter t heory). Note tha t the q ua li ty ofth e resa mpling result relies on th e qua lity of th e FIR filter h .

Px(n) y(n)FIRH Q

O ther Functions for Filtering

Page 49: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 49/798

1-21

Filter ban ks ma y be implemented using upfirdn by a llowing the fi l ter h to be

a ma tr ix, with one FIR filter per column. A signa l vector is pa ssedindependently t hrough each FIR fi l ter, result ing in a ma trix of output signals.

Oth er functions th a t perform multira te filtering (w ith fixed filter) includeresample , interp , and decimate .

Anti-Causal, Zero-Phase Filter ImplementationIn t he ca se of FIR filters, it is possible to design linea r pha se filters th a t, w hen

a pplied t o dat a (using filter or conv ), simply delay t he output by a fixednum ber of sam ples. For IIR filters, however, the pha se distortion is usua llyhighly n onlinea r. The filtfilt function uses the information in th e signa l a tpoints before a nd a fter t he current point, in essence “looking int o the futur e,”to eliminate phase distortion.

To see h ow filtfilt does this, reca ll tha t if th e z -tr a nsform of a rea l sequencex (n ) is X (z ), th e z -tr a nsform of the t ime reversed sequence x (n ) is X (1/ z ).Consider t he processing scheme

When | z | = 1, t ha t is z = e j ω, the output reduces to X (e j ω)| H (e j ω)| 2. Given allth e sam ples of the sequence x (n ), a doubly filter ed version of x t h a t h a szero-phase distortion is possible.

For example, a 1-second dura tion signa l sam pled a t 100 Hz, composed of tw osinusoidal components a t 3 Hz a nd 40 Hz, i s

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

H ( z) X ( z)

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

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

TimeReverse

1 Signal Processing Basics

Page 50: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 50/798

1-22

Now creat e a 10-point a verag ing FIR filter, a nd filter x using both filter a nd

filtfilt for comparison.b = ones(1,10)/10; % 10 point averaging filtery = filtfilt(b,1,x); % Noncausal filteringyy = filter(b,1,x); % Normal filteringplot(t,x,t,y,'--',t,yy,':')

B oth fi ltered versions elimina te t he 40 Hz sinusoid evident in the origina l ,

solid line. The plot a lso shows how filter a nd filtfilt differ; the da shed(filtfilt ) l ine is in phase with the original 3 Hz sinusoid, while the dott ed(filter ) line is delayed by a bout five samples. Also, th e a mplitude of theda shed l ine is smaller due to the ma gnitude squa red effects of filtfilt .

filtfilt reduces fi lter st a rtup tra nsients by carefully choosing init ialcondit ions, a nd by prepending onto th e input sequ ence a short, r eflected pieceof th e input sequence. For best results, ma ke sure the sequence you ar efi ltering ha s length a t least thr ee t imes the fi lter order a nd t a pers 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

O ther Functions for Filtering

Page 51: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 51/798

1-23

Frequency Domain Filter ImplementationDua lity between the t ime doma in a nd t he frequency doma in ma kes i t possibleto perform a ny opera tion in either domain. U sua lly one domain or th e oth er ismore convenient for a pa rt icula r opera tion, but you ca n a lwa ys a ccomplish agiven operat ion in either domain .

To implement genera l IIR filtering in t he frequency doma in, multiply th ediscrete Fourier t ra nsform (DF T) of th e input sequence with th e quotient of theDFT of the filter.

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

This computes results th at a re identical to filter , but wi th di fferent s ta r tuptr a nsients (edge effects). For long sequ ences, t his comput a tion is veryinefficient because of t he la rge zero-pad ded FF T opera tions on t he filtercoefficients, a nd becaus e the F FT a lgorithm becomes less efficient a s t henum ber of points n increases.

For FI R filters, how ever, it is possible to break longer sequences int o shorter,computa tiona lly efficient FF T lengths. The fun ction

y = fftfilt(b,x)

uses t he overla p a dd m ethod (see reference [ 1] a t the end of this chapter) tofilter a long sequence wit h mult iple medium-length FFTs. It s output isequivalent t o filter(b,1,x) .

1 Signal Processing Basics

Page 52: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 52/798

1-24

Impulse ResponseThe impulse response of a digita l filter is t he output a rising from th e unitimpulse input sequence defined as

In MATLAB, you ca n genera te a n impulse sequence a nu mber of w a ys; one

st ra ightforwa rd wa y isimp = [1; zeros(49,1)];

The impuls e response of the s imple filter b = 1 a nd a = [1 -0.9] is

h = filter(b,a,imp);

The impz function in t he t oolbox simplifies th is opera tion, choosing t he nu mberof points t o generat e and then ma king a st em plot (using the stem function).

impz(b,a)

The plot shows th e exponentia 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

Frequency Response

Page 53: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 53/798

1-25

Frequency ResponseThe Signal Processing Toolbox enables you to perform frequency domaina na lysis of both an alog and digita l f il ters.

Digital Domainfreqz uses an FFT-based algorithm to calculate the z -tr a nsform frequencyresponse of a d igita l filter. Specifica lly, the sta tement

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

re turns the p -point complex frequ ency response, , of th e digit a l filter.

In it s simplest form, freqz a ccepts t he filter coefficient vectors b a nd a , and aninteger p specifying the num ber of points a t w hich to ca lcula te th e frequencyresponse. freqz retur ns th e complex frequency response in vector h , and thea ctua l frequency point s in vector w in ra d/s.

freqz ca n a ccept other pa ra meters, such a s a sam pling frequency or a vector ofa rbitr a ry frequency point s. The exam ple below finds t he 256-point frequencyresponse for a 12th -order Ch ebyshev Type I filt er. The ca ll to freqz specifies asampling frequency fs of 1000 H z .

[b,a] = cheby1(12,0.5,200/500);

[h,f] = freqz(b,a,256,1000);

B eca use the para meter l ist includes a sam pling frequency, freqz returns avector f tha t conta ins th e 256 frequency points between 0 and fs/2 used in th efrequency response ca lcula tion.

H e j ω( )

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

1 Signal Processing Basics

Page 54: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 54/798

1-26

Frequency Normalization This t oolbox uses t he convent ion t ha t unitfrequency is the Nyqu ist frequency, defined a s ha lf the sa mpling frequency.The cutoff frequency pa ra meter for a ll basic filter design functions isnormalized by th e Nyquist frequency. For a system wit h a 1000 Hz sa mplingfrequ ency, for exa mple, 300 H z is 300/500 = 0.6. To convert norma lizedfrequency to angu lar fr equency around t he unit circle, mult iply by π. Toconvert n ormalized frequency back to hertz, mult iply by ha lf the sa mplefrequency.

If you call freqz with no output a rguments, i t a utomat ica lly plots bothma gnit ude versus frequency a nd pha se versus frequency. For exa mple, anint h-order But terw orth lowpa ss filter wit h a cutoff frequency of 400 Hz, ba sedon a 2000 Hz sa mpling frequency, is

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

Now ca lcula t e the 256-point complex frequency response for this filt er, a nd plotthe magni tude and phase wi th a ca l l to freqz .

freqz(b,a,256,2000)

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

-800

-600

-400

-200

0

Frequency (Hertz)

P h a s e ( d e g r e e s )

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

-300

-200

-100

0

100

Frequency (Hertz)

M a g n i t u d e R e s p o n s e ( d B )

Frequency Response

Page 55: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 55/798

1-27

freqz can a lso a ccept a vector of arbit ra ry frequency points for use in th e

frequency response ca lcula tion. For exa mple,w = linspace(0,pi);h = freqz(b,a,w);

calculat es the complex frequency response a t t he frequency points in w for t hefilter defined by vectors b a nd a . Th e f req u en cy poin t s ca n r a n g e f rom 0 t o .To specify a frequency vector t ha t ra nges from zero to your sa mpling frequency,include both t he frequency vector and t he sam pling frequency value in th e

parameter l ist .

Analog Domainfreqs evalua tes frequency response for a n a na log filter defined by tw o inputcoefficient vectors, b a nd a . I ts opera tion is similar t o tha t of freqz ; you ca nspecify a num ber of frequency points t o use, supply a vector of a rbitra ryfrequency points , an d plot t he ma gnit ude an d pha se response of th e filter.

Magnitude and PhaseMATLAB provides functions t o extra ct ma gnit ude an d pha se from a frequencyresponse vector h . The function abs returns the ma gnitude of the response;angle returns t he phase an gle in ra dians. To extra ct an d plot t he magnit udea nd phase of a But terw orth fi l ter.

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

2 π

0 100 200 300 400 50010

−15

10−10

10−5

100

Magnitude

0 100 200 300 400 500−200

−150

−100

−50

0

50

100

150

200Phase

1 Signal Processing Basics

Page 56: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 56/798

1-28

The unwrap function is a lso useful in frequency an a lysis. unwrap unwraps the

pha se to ma ke it cont inuous a cross 360 ° phase discontinuit ies by a ddingmult iples of ±360° , a s n eeded. To see how unwrap is useful, design a 25th -orderlowpa ss FI R fi l ter.

h = fir1(25,0.4);

Obta in th e filter ’s frequency response wit h freqz , an d plot t he phase indegrees.

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

I t is difficult t o dist inguish th e 360° jumps (a n a rt ifact of the a rctan gentfunction inside angle ) from the 180° jumps th a t sign ify zeros in t he frequencyresponse.

U se unwrap to elimina te t he 360° jumps.

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

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

-150

-100

-50

0

50

100

150

200

Frequency Response

Page 57: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 57/798

1-29

DelayThe group delay of a f i lter is a measure of the a vera ge delay of the fi lter a s afunction of frequency. It is defined a s th e negat ive first deriva tive of a filter ’spha se response. If th e complex frequency response of a filter is , th enth e group dela y is

where θ is th e pha se a ngle of . Compute group delay w ith

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

wh ich returns the n-point group dela y, , of th e digit a l filter specified by b a nd a , eva lua ted a t t he frequencies in vector w.

The ph ase dela y of a filter is th e negat ive of pha se 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

H e j ω( )

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

H e j ω( )

τg ω( )

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

1 Signal Processing Basics

Page 58: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 58/798

1-30

To plot both the group and phase delays of a system on the sa me gra ph, type

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

0 200 400 600 800 1000−30

−20

−10

0

10

20

30Group DelayPhase Delay

Zero-Pole A nalysis

l l

Page 59: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 59/798

1-31

Zero-Pole AnalysisThe zplane function plots poles a nd zeros of a linear s yst em. For exa mple, asimple filter w ith a zero a t -1/2 a nd a complex pole pa ir a t a nd

is

zer = -0.5;pol = 0.9*exp(j*2*pi*[-0.3 0.3]');

The zero-pole plot for the filter is

zplane(zer,pol)

For a syst em in zero-pole form, su pply column vector a rgument s z a nd p t ozplane .

zplane(z,p)

For a sy stem in tr a nsfer function form, supply row vectors b a nd a a sarguments to zplane .

zplane(b,a)

0.9 e j 2 π 0.3( )0.9 e j – 2 π 0.3( )

-1 -0.5 0 0.5 1

-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

Real part

I m a g

i n a r y p a r t

1 Signal Processing Basics

I thi l fi d t h t f b d i g th t f ti d l t

Page 60: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 60/798

1-32

In this case zplane finds t he roots of b a nd a using the roots function and plots

th e resulting zeros and poles.S ee “Linea r S yst em Models” on pa ge 1-33 for det a ils on zero-pole an d t ra nsferfunction representa tion of systems.

Linear System M odels

Linear S stem Models

Page 61: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 61/798

1-33

Linear System ModelsThe Sig na l P rocessing Toolbox provides severa l models for represent ing linea rtime-inva ria nt syst ems. This flexibility lets you choose the representa tiona lscheme tha t best suit s your applicat ion a nd, w ithin t he bounds of numericsta bility , convert freely t o an d from most other models. This section provides abrief overview of supported linear syst em models a nd d escribes how to w orkw ith th ese models in MATLAB.

Discrete-Time System ModelsThe discrete-time syst em models a re representa tiona l schemes for digit a lfilters. MATLAB su pport s severa l discrete-time sys tem models, w hich a redescribed in th e following sections:

• “Tra nsfer Fun ction”• “Zero-Pole-Gain”• “State-Space”• “Pa rtia l Fra ction Expansion (Residue Form)”• “Second-Order Sections (SOS )”• “Lat t ice St ructure”• “Convolution Matrix”

Transfer Function

The tr ansfer fun cti on is a basic z -domain r epresenta tion of a digita l filter,expressing th e filter a s a ra tio of tw o polynomials. It is t he principaldiscrete-time model for this toolbox. The transfer function model descriptionfor the z -tr a nsform of a digita l filter ’s difference equa tion is

Here, the constan ts b (i ) a nd a (i ) a re th e filter coefficients, a nd t he order of thefilter is the ma ximum of n a nd m . In MATLAB , you st ore th ese coefficient s intw o vectors (row vectors by convent ion), one row vector for th e numera tor a ndone for the denomina tor. See “Filters a nd Tra nsfer Fun ctions” on pa ge 1-16 formore deta ils on th e tra nsfer function form.

Y z ( )b 1( ) b 2( ) z 1– L b n 1+( ) z n –+ + +

a 1( ) a 2( ) z 1– L a m 1+( ) z m –+ + +---------------------------------------------------------------------------------------- X z ( )=

1 Signal Processing Basics

Zero-Pole-Gain

Page 62: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 62/798

1-34

Zero-Pole-Gain

The fa ctored or zero-pole-gain form of a tr a nsfer function is

B y convention, MATLAB stores polynomia l coefficient s in row vectors a ndpolynomia l roots in column vectors. In zero-pole-ga in form, t herefore, th e zeroa nd pole locations for t he numerat or and denominat or of a tra nsfer functionreside in column vectors. The fa ctored t ra nsfer function ga in k is a MATLABscalar.

The poly a nd roots functions convert between polynomial and zero-pole-gainrepresent a tions. For exa mple, a simple IIR filter is

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

The zeros an d 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

Returning to the original polynomials,bb = k*poly(q)

bb =2.0000 3.0000 4.0000

H z ( ) q z ( )p z ( )---------- k

z q 1( )–( ) z q 2( )–( )L z q n ( )–( )z p 1( )–( ) z p 2( )–( )L z p n ( )–( )

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

Linear System M odels

aa = poly(p)

Page 63: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 63/798

1-35

p y(p)

aa =1.0000 3.0000 3.0000 1.0000

Note tha t b a nd a in th is case represent the t ra nsfer function

For b = [2 3 4] , the roots function misses the zero for z equa l to 0. In fa ct, itmisses poles an d zeros for z equal t o 0 wh enever t he input tra nsfer function hasmore poles than zeros, or vice versa. This is acceptable in most cases. Tocircumvent th e problem, however, simply append zeros to make t he vectors t hesa me length before using t he roots function; for exam ple, b = [b 0] .

State-SpaceIt is alw a ys possible to represent a digita l filter, or a syst em of differenceequa tions, as a set of first-order difference equa tions. In ma tr ix or state-space form, you can w rite the equat ions a s

where u is the input, x is the sta te vector, an d y is the output . Forsingle-chan nel syst ems, A i s an m-by-mmat r ix where m is th e order of the filter,B is a column vector, C is a row vector, and D is a scala r. St at e-space nota tion is

especia lly convenient for mult icha nnel syst ems wh ere input u and output y become vectors, and B, C, and D become ma tr ices.

St a te-spa ce represent a tion extends easily t o the MATLAB environment. InMATLAB , A , B, C, and D a re rectangula r ar ra ys; MATLAB t reat s them asindividua l va riables.

Ta king the z -tr a nsform of the sta te-space equa tions an d combining them showsth e equiva lence of sta te-spa ce a nd t ra nsfer function forms.

Don’t be concerned if you are not fa miliar w ith t he sta te-space representa tionof linear syst ems. Some of th e filter d esign a lgorith ms use sta te-space formint erna lly but do not require an y knowledge of sta te-space concepts t o use th em

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

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

x n 1+( ) A x n ( ) B u n ( )+=

y n ( ) C x n ( ) D u n ( )+=

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

1 Signal Processing Basics

successfully. If your a pplicat ions use st a te-spa ce ba sed signa l processing

Page 64: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 64/798

1-36

y y pp p g p g

extens ively, however, consu lt t he Cont r ol Sy st em Toolbox for a compreh ensivelibrar y of sta te-space tools.

Par tial Fraction Expa nsion (Residue Form )Ea ch tra nsfer function also has a corresponding par ti al fr acti on expansion orresidue form r epresent a tion, given by

provided H (z ) ha s no repeat ed poles. Here, n is th e degree of the denominat orpolynomial of th e ra tiona l tra nsfer function b (z )/a (z ). I f r is a pole of multiplicitys r , then H (z ) ha s term s of the form

The residuez function in t he Sign a l P rocessing Toolbox converts tr a nsferfunctions to and fr om the part ial fra ction expa nsion form. The “ z ” on th e end ofresiduez sta nds for z -domain , or discrete domain. residuez return s th e polesin a column vector p , th e residues corresponding to t he poles in a columnvector r , an d a ny improper par t of the original t ra nsfer function in a row vector k . residuez determines tha t t wo poles a re the sa me if the magnitude ofth eir difference is smaller t ha n 0.1 percent of either of the poles’ ma gnitud es.

P a rt ial fra ction expa nsion ar ises in signa l processing as one method of findingth e inverse z -tr a nsform of a t ra nsfer function. For exam ple, the part ia l fractionexpansion of

is

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

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

1 p 1( ) z 1–

---------------------------- L r n ( )

1 p n ( ) z 1–

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

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

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

r j s r 1–+( )

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

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

Linear System M odels

r =

Page 65: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 65/798

1-37

-128

p =-4-2

k =[]

w hich corresponds t o

To find th e inverse z -tr a nsform of H (z ), find t he sum of th e inverse z -transformsof the t wo a ddends of H (z ), giving th e ca usa l impulse response

To verify t his in MATLAB , t ype

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

resptf =

-4 32 -160 704 -2944

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

respres =

-4 32 -160 704 -2944

H z ( ) 12–

1 4 z 1–+--------------------- 8

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

h n ( ) 12– 4–( )

n 8 2–( )

n + n 0 1 2…, , ,

=,

=

1 Signal Processing Basics

Second- O rder Sections (SO S)

Page 66: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 66/798

1-38

Any transfer function H (z ) has a second-order sections represent a tion

where L is th e number of second-order sections t ha t describe the sys tem.MATLAB r epresent s th e second-order section form of a discret e-tim e syst em a sa n L -by-6 ar ra y sos . Ea ch row of sos cont a ins a single second-order section,wh ere the row elements a re the three numerat or a nd th ree denominat orcoefficients that describe the second-order section.

There a re a n un count a ble number of wa ys t o represent a filter in second-ordersection form. Through ca reful pairin g of the pole a nd zero pa irs, ordering of thesections in t he casca de, an d mult iplicat ive sca ling of the sections, it is possibleto reduce qua nt izat ion noise gain a nd a void overflow in some fixed-point filterimplement a tions. The fun ctions zp2sos a nd ss2sos , described in “LinearSyst em Tra nsforma tions” on pa ge 1-43 , perform pole-zero pa iring , sectionscaling, a nd section ordering.

Note In t he Sig na l P rocessin g Toolbox, a ll second -order sectiontra nsforma tions apply only t o digita l f i lters.

La ttice Structure

For a discrete N th order all-pole or all-zero filter described by the polynomialcoefficients a (n ), n = 1, 2, …, N + 1, there are N corresponding la tt ice structurecoefficients k (n ), n = 1, 2, …, N . The para meters k (n ) a re also ca lled t her efl ection coeffi cient s of the filter. Given these reflection coefficients, you canimplement a discrete filter a s shown below .

H z ( ) H k z ( )

k 1=

L

∏b 0 k b 1 k z 1– b 2 k z 2–+ +

a 0 k a 1 k z 1– a 2 k z 2–+ +----------------------------------------------------------

k 1=

L

∏= =

so s

b 01 b 11 b 21 a 01 a 11 a 21

b 02 b 12 b 22 a 02 a 12 a 22M M M M M M

b 0 L

b 1 L

b 2 L

a 0 L

a 1 L

a 2 L

=

Linear System M odels

Σ y(m)Σ. . . x(m) Minimum-phase output

Page 67: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 67/798

1-39

For a general pole-zero IIR filter described by polynomial coefficients a a nd b ,th ere ar e both lat tice coefficients k (n ) for t he denomina tor a and la ddercoefficients v (n ) for the numera tor b . The la t tice/la dder filt er ma y beimplemented as

The toolbox function tf2latc a ccepts a n FI R or IIR filter in polynomia l forma nd r eturn s t he corresponding reflection coefficients. An exam ple FIR filter inpolynomial form is

b = [1.0000 0.6149 0.9899 0.0000 0.0031 -0.0082];

Σ z -1

k(1)

k(1)

Σ

k(n)

k(n)

. . . z -1

F I R L a t t i c e F i lt e r

x(m)

Σ

Σ y(m)

k(1)

–k(1) Σ

k(n)

–k(n). . .

. . . z -1 Σ z -1

I I R L a t t i c e F i lt e r

p p

All-pole output

Maximum-phase output

Allpass output

z -1+

+x(m)

g(m)

+

k(N)

k(N)

z -1+

+

k(2)

k(2)

z -1+

+

k(1)

k(1)

++ +

v(N+1) v(N) v(3) v(2) v(1)

f(m)ARMA output

1 Signal Processing Basics

This filt er ’s lat t ice (reflection coefficient ) represent a tion is

Page 68: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 68/798

1-40

k = tf2latc(b)

k =0.30900.98010.00310.0081

-0.0082

For II R filters, th e ma gnitud e of th e reflection coefficients provides an easysta bility check. If a ll the r eflection coefficients corresponding to a polynomialha ve magnitude less th an 1, a l l of tha t polynomia l’s roots a re inside the unitcircle. For exam ple, consider an I IR filter w ith n umera tor polynomial b fromabove and denominator polynomial

a = [1 1/2 1/3];

The filter ’s la tt ice represent a tion is

[k,v] = tf2latc(b,a)

k =0.37500.3333

000

v =0.62520.12120.9879

-0.00090.0072

-0.0082

Because abs(k) < 1 for a ll reflection coefficient s in k , the filter is sta ble.

Linear System M odels

The function latc2tf calculat es the polynomial coefficients for a filter from itsla tt ice (reflection) coefficient s G iven t he reflection coefficient vector k( above)

Page 69: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 69/798

1-41

la tt ice (reflection) coefficient s. G iven t he reflection coefficient vector k( above),th e corresponding polynomia l form is

b = latc2tf(k)

b =1.0000 0.6149 0.9899 -0.0000 0.0031 -0.0082

The la tt ice or lat tice/la dder coefficients ca n be used to implement t he filterusing t he function latcfilt .

Convolution M a trixIn signa l processing, convolving t wo vectors or ma tr ices is equivalent tofiltering one of th e input opera nds by t he other. This relat ionship permits t herepresenta tion of a digita l f il ter as a convolut i on m atr i x .

G iven a ny vector, the t oolbox function convmtx genera tes a ma trix whose innerproduct w ith a nother vector is equiva lent t o the convolution of the t w o vectors.

The generat ed mat rix represents a digital f i l ter th a t you ca n a pply to an yvector of a ppropriat e length ; the inner dimension of th e operan ds must a greeto compute t he inner product.

The convolut ion ma t rix for a vector b , represent ing t he num era tor coefficientsfor a digita 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

Tw o equiva lent w a ys t o convolve b wi th x a re a s follows.

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

1 Signal Processing Basics

Continuous-Time System Models

Page 70: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 70/798

1-42

The cont inuous-time syst em models a re representa tiona l schemes for a na logfilters. Man y of the discrete-time syst em models described ea rlier ar e alsoa ppropria te for the representa tion of continuous-time syst ems:

• St a te-spa ce form• P a rtia l fra ction expansion• Tra nsfer function• Zero-pole-ga in form

It is possible to represent any system of linear time-invariant differentialequat ions a s a set of f irst-order differential equa tions. In ma trix or state-space form, you ca n express th e equa tions a s

where u is a vector of n u inputs, x i s an n x -element sta te vector, a nd y is a vectorof n y outputs . In MATLAB, st ore A , B, C, and D in separa te recta ngular a r rays .

An equivalent representation of the state-space system is the Laplacetransform transfer function description

where

For single-input, single-output syst ems, th is form is given by

Given the coefficients of a Laplace transform transfer function, residue determines th e pa rt ia l fraction expa nsion of the syst em. See th e description ofresidue in t he MATLAB document a tion for details.The factored zero-pole-gain form is

x · A x B u +=

y C x D u +=

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

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

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

a 1( ) s m a 2( ) s m 1– L a m 1+( )+ + +----------------------------------------------------------------------------------------- -= =

H s ( ) z s ( )p s ( )---------- k

s z 1( )–( ) s z 2( )–( )L s z n ( )–( )s p 1( )–( ) s p 2( )–( )L s p n ( )–( )--------------------------------------------------------------------------------= =

Linear System M odels

As in th e discrete-tim e case, MATLAB s tores polynomia l coefficient s in r ow vectors in descending pow ers of s . MATLAB st ores polynomia l roots, or zeros

Page 71: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 71/798

1-43

g p p y ,a nd poles, in column vectors.

Linear System TransformationsThe S igna l P rocessing Toolbox provides a num ber of functions th a t convertbetw een th e various linea r syst em models; see Ch a pter 7, Fun ction Reference for a complete description of each. You can use th e follow ing cha rt to find a na ppropriat e tra nsfer function: find t he row of th e model to convert from on th e

left side of th e cha rt a nd t he column of the model to convert t o on the t op of thechart a nd rea d t he function na me(s) a t t he intersection of the row a nd column.

Note Converting fr om one filter stru cture or model to an other ma y produce aresult wit h different char a cterist ics t ha n t he original . This is due to thecomputer ’s finite-precision a rith metic a nd t he va ria tions in th e conversion’sround-off computations.

Transferfunction

State-space

Zero-pole-gain

Partialfraction

Latticefilter

Second-ordersections

Convolutionmatrix

Transferfunction

tf2ss tf2zp roots

residuezresidue

tf2latc convmtx

State-space ss2tf ss2zp ss2sos

Zero-pole-gain

zp2tfpoly

zp2ss zp2sos

Partialfraction

residuezresidue

Lattice filter latc2tf

SOS sos2tf sos2ss sos2zp

Convolutionmatrix

1 Signal Processing Basics

Ma ny of the t oolbox filter design functions use these functions intern a lly. Forexample, the zp2ss function convert s th e poles and zeros of a n a na log

Page 72: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 72/798

1-44

prototype into the state-space form required for creation of a Butterworth,Chebyshev, or elliptic filter. Once in sta te-space form, th e filter design functionperforms a ny required frequency tra nsforma tion, that is , it t ra nsforms th einit ial lowpa ss design int o a ba ndpass, highpa ss, or ba ndstop fil ter, or alowpa ss filter wit h t he desired cut off frequency. See th e descriptions of theindividua l filter design functions in Cha pter 7, “Function Reference,” for moredetails .

Note In t he Sig na l P rocessin g Toolbox, a ll second -order sectiontra nsforma tions apply only t o digita l f i lters.

Discrete Fourier Transform

Discrete Fourier Transform

Page 73: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 73/798

1-45

The discrete Fourier t ra nsform, or D FT, is the prima ry t ool of digita l signa lprocessing. The founda tion of th e Signa l P rocessing Toolbox is t he fa st Fouriertr a nsform (FF T), a meth od for computing t he DF T wit h r educed execut iontime. Ma ny of the t oolbox functions (including z -domain frequency response,spectrum a nd cepstrum a na lysis, an d some fi l ter design a nd implementa tionfunctions) incorporate the FFT.

MATLAB pr ovides the fun ctions fft a nd ifft to comput e th e discrete Fourier

tr a nsform an d its inverse, respectively. For th e input seq uence x and i t stransformed version X (th e discrete-time Fourier tra nsform at equa lly spacedfrequencies a round t he unit circle), the t w o functions implement t herelationships

In t hese equa tions, th e series subscripts begin wit h 1 instea d of 0 beca use ofMATLAB ’s vector indexing scheme, a nd

Note MATLAB uses a nega tive j for t he fft function. This is a n engineeringconvention; physics an d pure mat hema tics typically use a positive j .

fft , with a single input argument x , comput es th e DF T of the input vector ormat r ix. I f x is a vector, fft comput es th e DF T of the vector; if x is a recta ngulara r r a y, fft computes t he DF T of ea ch ar ra y column.

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

n 0=

N 1–

∑=

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

k n –

k 0=

N 1–

∑=

W N e j –2 πN -------

=

1 Signal Processing Basics

For exa mple, crea te a t ime vector a nd signa l.

(0 1/100 10 1/100) % Ti

Page 74: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 74/798

1-46

t = (0:1/100:10-1/100); % Time vectorx = sin(2*pi*15*t) + sin(2*pi*40*t); % Signal

The DFT of the signa l, and the ma gnitude a nd pha se of the t ra nsformedsequence, ar e then

y = fft(x); % Compute DFT of xm = abs(y); p = unwrap(angle(y)); % Magnitude and phase

To plot t he ma gnitu de an d pha se, ty pe th e follow ing comma nds.f = (0:length(y)-1)*99/length(y); % Frequency vectorplot(f,m); title('Magnitude');set(gca,'XTick',[15 40 60 85]);figure; plot(f,p*180/pi); title('Phase');set(gca,'XTick',[15 40 60 85]);

A second ar gument to fft specifies a number of points n for t he tra nsform,represent ing DF T length.

y = fft(x,n);

In t his ca se, fft pads t he input sequence wit h zeros if i t is shorter t ha n n , or

trun ca tes th e sequence if i t is longer t ha n n . I f n is not specified, it defa ults t oth e lengt h of the input sequence. Execution time for fft depends on th elength, n , of the D FT it performs; see the fft reference pa ge in t he MATLABdocumenta tion for deta ils about the a lgorithm.

15 40 60 850

100

200

300

400

500

600Magnitude

15 40 60 85−0.5

0

0.5

1

1.5

2

2.5

3x 10

4 Phase

Discrete Fourier Transform

The inverse discrete Fourier t ra nsform function ifft a lso a ccepts a n inputsequence and , optiona lly, the num ber of desired points for t he tr a nsform. Tryth e exa mple below ; the origina l sequence a nd t he reconstructed sequence ar e

Page 75: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 75/798

1-47

th e exa mple below ; the origina l sequence x a nd t he reconstructed sequence ar eidentical (with in rounding error).

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

This t oolbox a lso includes functions for t he t wo-dimensional FFT and itsinverse, fft2 a nd ifft2 . These functions a re useful for tw o-dimensional s igna lor ima ge processing . The goertzel function, which is a nother a lgorithm tocomput e th e DF T, a lso is included in t he t oolbox. This fun ction is efficient forcomputin g t he DF T of a portion of a long signa l. See the descriptions in Chapter7, “Function Reference,” for details.

It is sometimes convenient t o rea rra nge the output of the fft or fft2 functionso th e zero frequency component is a t t he center of th e sequence. The MATLABfunction fftshift moves t he zero frequency component to t he center of a vector

or matr ix.

1 Signal Processing Basics

Selected BibliographyAlgorith m development for th e Signa l P rocessing Toolbox ha s dra w n hea vily

Page 76: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 76/798

1-48

Algorith m development for th e Signa l P rocessing Toolbox ha s dra w n hea vilyupon the r eferences listed below . All a re recommended t o the int erested rea derw ho needs t o know more about sign a l processing t ha n is covered in thismanua l .

[1] Crochiere, R.E., a nd L.R. Ra biner. M ul ti -Rate Signa l Pr ocessin g .En glewood Cliffs, NJ : P rentice Ha ll, 1983. P gs. 88-91.

[2] IE EE . Pr ogram s for Di gital Signa l Pr ocessin g . IEE E P ress. New York: J ohnWiley & Sons, 1979.

[3] J a ckson, L.B. Di gi ta l Fi l ters and Signal Processin g . Third E d. B oston:Kluw er Aca demic P ublishers, 1989.

[4] Ka y, S .M. M odern Spectr a l Est im at ion . Englewood Cliffs, NJ : P rentice Ha ll ,1988.

[5] Oppenheim, A.V., a nd R.W. S cha fer. Di scr ete-Ti m e Si gnal Pr ocessi ng .

En glewood Cliffs, NJ : P rentice Ha ll, 1989.[6] P a rks, T.W., an d C .S. B urru s. Di gi ta l F i l ter D esign . New York: J ohn Wiley& Sons, 1987.

[7] P ra tt ,W.K. Di gital I m age Processin g . New York: J ohn Wiley & Sons , 1991.

[8] P ercival, D .B ., a nd A.T. Wa lden. Spectr al An alysis for Physical Appl i cat ions: M ul t i t aper and Convent i onal U ni var i a te Techni ques . Ca mbridge:Cambridge University Press, 1993.

[9] P roakis, J .G., a nd D .G. Ma nola kis. Di gital Sign al Pr ocessin g: Pri ncipl es,Algor i th ms, and Appl i cat ions . Upper Sa ddle River, NJ : Pr entice Ha ll, 1996.

[10] Ra biner, L.R., and B . G old. Th eory and Appl i cat ion of Di gi ta l Si gnal Processing . Englew ood Cliffs, NJ : Pr entice Ha ll, 1975.

[11] Welch, P .D. “The U se of Fa st Fourier Tra nsform for t he E stima tion ofP ower Spectr a : A Method B a sed on Time Averag ing Over Short , Modified

Periodograms.” I EE E Tr ans . Audio E lect r oacoust . Vol. AU -15 (J un e 1967).P gs. 70-73.

2

Fil D i

Page 77: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 77/798

Filt er D esign

Overview . . . . . . . . . . . . . . . . . . . . . 2-2

Filter Requirements and Specification . . . . . . . . 2-3

IIR Filter Design . . . . . . . . . . . . . . . . . . 2-5Cla ssical IIR Fil ter Design U sing Ana log P rototyping . . . . 2-7Compar ison of Cla ssical IIR Filter Types . . . . . . . . . 2-9

FI R Filter Design . . . . . . . . . . . . . . . . . . 2-17Linear P ha se Fil ters . . . . . . . . . . . . . . . . . 2-18Windowing Method . . . . . . . . . . . . . . . . . . 2-19

Multiband FIR Fil ter Design with Tra nsit ion B an ds . . . . 2-23Constra ined Least Squa res FIR Fil ter Design . . . . . . . 2-28Arbitr a ry-Response Filter Design . . . . . . . . . . . . 2-32

Special Topics in IIR F ilter Design . . . . . . . . . . 2-38Ana log P rototype Design . . . . . . . . . . . . . . . 2-39Frequ ency Tra nsforma tion . . . . . . . . . . . . . . . 2-39Filter Discretiza tion . . . . . . . . . . . . . . . . . 2-42

Selected Bibliography . . . . . . . . . . . . . . . 2-46

2 Filter Design

OverviewThe Sign a l P rocessing Toolbox provides functions t ha t support a ra nge of filter

Page 78: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 78/798

2-2

The Sign a l P rocessing Toolbox provides functions t ha t support a ra nge of filterdesign methodologies. The following sections explain how to apply the filterdesign t ools to I nfi ni te I m pul se Response (IIR ) a nd Fi ni te Im pul se Response (FIR) filter design problems:

• “Filter Requirements and Specification”• “IIR F il ter D esign”• “FIR F il ter D esign”• “Special Topics in IIR Filter Design”• “Selected Bibliography”

Filter Requirements and Specification

Filter Requirements and SpecificationThe goal of filter design is to perform frequency dependent a ltera tion of a da ta

Page 79: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 79/798

2-3

g g p q y psequence. A possible requirement might be to remove noise above 30 Hz froma da ta sequence sampled a t 100 Hz. A more rigorous specifica tion might call fora specific a mount of pa ssband ripple, stopband a tt enuat ion, or tra nsit ionw idth . A very precise specificat ion could ask to a chieve th e performa nce goa lswit h t he minimum fil ter order, or i t could ca ll for a n a rbitra ry ma gnitudesha pe, or i t might require an FI R fi lter.

Filter d esign meth ods differ prima rily in how performa nce is specified. For“loosely specified” requirements , as in t he first case above, a B utt erwort h II Rfilter is often sufficient. To design a fifth-order 30 Hz low pass B utt erwort hfi lter a nd a pply i t to the dat a in vector x ,

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

The second input a rgument to butter specifies the cutoff frequency,

norma lized to ha lf the sa mpling frequency (th e Nyquist frequ ency).

Frequency Normalization in the Signal Processing Toolbox All of th efilter design functions operat e wit h norma lized frequencies, so th ey do notrequire the system sa mpling ra te a s a n extra input a rgument. This toolboxuses the convention th a t unit frequency is th e Nyquist frequency, defined asha lf the sa mpling frequency. The norma lized frequency, th erefore, is alw a ysin the interval 0

≤f ≤

1. For a system w ith a 1000 Hz sampling frequency,300 Hz is 300/500 = 0.6. To convert norma lized frequency to a ngula rfrequency a round th e unit circle, multiply by π. To convert norma lizedfrequency back to hertz, mult iply by ha lf the sa mple frequency.

More rigorous filter requ irements t ra ditiona lly include pa ssba nd ripple ( Rp, i ndecibels), stopband attenuation ( Rs , in decibels), an d tr a nsition widt h ( Ws-Wp ,in hert z).

2 Filter Design

1

Page 80: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 80/798

2-4

You can d esign Bu tt erwort h, Ch ebyshev Type I, Chebyshev Type II, a ndelliptic filters t ha t meet t his t ype of performa nce specifica tion. The t oolboxorder selection functions estima te th e minimum filter order th a t meets a givenset of requirement s.

To meet s pecifica tions w ith more rigid const ra ints like linear pha se ora rbitra ry fi l ter shape, use the FI R a nd direct I IR fi l ter design routines.

10-1

100

101

0

0.2

0.4

0.6

0.8

Frequency(rad/sec)

M a g n i t u d e

IIR Filter Design

IIR Filter DesignThe primary a dvan ta ge of IIR fi lters over FI R fi l ters is tha t they t ypically meet

Page 81: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 81/798

2-5

a given set of specificat ions w ith a much low er filter order th a n a correspondingFIR fi lter. Although IIR fi lters ha ve nonlinear phase, da ta processing w ithinMATLAB is commonly performed “off-line,” tha t is, th e entire da ta sequence isa va ilable prior t o filtering. This a llow s for a noncausa l, zero-pha se filteringa pproach (via t he filtfilt function), which eliminates the nonlinear phasedistort ion of a n I IR fi l ter.

The clas sica l IIR filters, B utt erwort h, Chebyshev Types I and I I, elliptic, a ndB essel, all a pproximat e the ideal “brick wa ll” filter in different w a ys. Thistoolbox provides functions t o crea te a ll these t ypes of classical I IR filters in boththe a na log a nd digita l doma ins (except B essel , for w hich only the a na log caseis supported), a nd in lowpass, highpass, ban dpass, a nd ba ndstopconfigura tions. For most filter t ypes, you can a lso find t he low est filter ordertha t f i ts a given fi l ter specificat ion in t erms of passban d a nd st opba nda tt enuat ion, and tra nsit ion width (s).

The direct filter design function yulewalk f inds a f i l ter with ma gnituderesponse a pproxima ting a desired function. This is one wa y t o crea te amultiband ba ndpass f i lter.

You can a lso use the par a metric modeling or syst em identifica tion functions todesign I IR filters. These functions a re discussed in “Parametric Modeling” onpage 4-12 .

The generalized But terw orth design function maxflat is discussed in th e

section “Generalized B utt erworth Fil ter Design” on page 2-15 .The followin g ta ble summa rizes the va rious filter met hods in th e toolbox an dlists the functions available to implement these methods.

2 Filter Design

Method Description Functions

Page 82: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 82/798

2-6

AnalogPrototyping

U sing t he poles and zeros ofa classica l lowpa ssprototype filter in th econt inuous (Lapla ce)doma in, obta in a digitalfilter thr ough frequency

tra nsforma tion a nd fil terdiscretization.

Complete d esign functions:

besself , butter , cheby1 , cheby2 , ellip

Order estimation functions:

buttord , cheb1ord , cheb2ord , ellipord

Lowpass analog prototype functions:

besselap , buttap , cheb1ap , cheb2ap ,ellipap

Frequency tra nsforma tion functions:

lp2bp , lp2bs , lp2hp , lp2lp

Filter discretization functions:

bilinear , impinvar

D ir ect D es ig n D es ig n d ig it a l filt er dir ect lyin t he discrete time-domainby a pproximating apiecewise linear magnitude

response.

yulewalk

GeneralizedBut terworthDesign

Design lowpa ssBut terworth f il ters w i thmore zeros t ha n poles.

maxflat

Paramet r i cModeling

Find a digital f il ter tha ta pproximat es a prescribedtime or frequency domainresponse. (See t he S yst emId ent ificat ion Toolbox fora n exten sive collection ofpar a metr ic modeling tools.)

Time-doma in modeling fu nctions :

lpc , prony , stmcb

Frequency-domain modeling functions:

invfreqs , invfreqz

IIR Filter Design

Classical IIR Filter Design Using Analog Prototyping

The principal II R digita l filter design t echniq ue th is toolbox provides is ba sedon the conversion of clas sica l low pass a na log filters to their digita l equiva lents.

Page 83: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 83/798

2-7

The followin g sections d escribe how t o design filters a nd su mma rize thechar a cteristics of the support ed filter t ypes. See “S pecia l Topics in II R F ilterDesign” on pa ge 2-38 for det a iled st eps on t he filter design process.

Com plete Cla ssica l IIR Filter D esignYou can easily crea te a f i lter of a ny order w ith a lowpa ss, highpass, ba ndpass,

or band stop configurat ion using t he filter design functions.

B y default , ea ch of these functions return s a lowpa ss filter; you need onlyspecify the desired cutoff frequency Wn in norma lized frequency (Nyquistfrequency = 1 Hz). For a h ighpass filter, a ppend th e string 'high' to thefunction’s para meter list. For a ba ndpa ss or ba ndst op filter, specify Wn a s atw o-element vector conta ining th e pa ssba nd edge frequencies, appending t hes t r ing 'stop' for th e bandst op configura tion.

Filter Type Design Function

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

Butterworth [b,a] = butter(n,Wn, options )[z,p,k] = butter(n,Wn, options )[A,B,C,D] = butter(n,Wn, options )

Ch ebysh ev 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 )

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

2 Filter Design

Here a re some exa mple digita l filters.

[b,a] = butter(5,0.4); % Lowpass Butterworth[b,a] = cheby1(4,1,[0.4 0.7]); % Bandpass Chebyshev Type I

Page 84: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 84/798

2-8

[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 a n a na log filter, perha ps for simula tion, use a tr a iling 's' a ndspecify cutoff frequ encies in r a d/s.

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

All filter design functions retu rn a filter in the tr a nsfer function,zero-pole-ga in, or sta te-space linea r syst em model representa tion, dependingon how ma ny output ar guments a re present.

Note All cla ssical I IR low pas s filters a re ill-condit ioned for extr emely low cut-off frequencies. Therefore, instea d of designing a lowpa ss II R filter w ith avery na rrow passba nd, i t ca n be bett er to design a w ider passba nd a nddecimat e the input signal.

Designing IIR Filters to Frequency Domain SpecificationsThis t oolbox provides order selection fun ctions t ha t calculat e th e minimumfilter order tha t meets a given set of requirements.

These a re useful in conjunction w ith th e filter design fun ctions. S uppose youwa nt a bandpa ss fi lter w ith a passba nd from 1000 to 2000 Hz, stopband ssta rt ing 500 Hz aw a y on either side, a 10 kHz sa mpling frequency, a t most 1 dB

Filter Type Order Estimation Function

Butterworth [n,Wn] = buttord(Wp,Ws,Rp,Rs)

Ch ebyshev Type I [n,Wn] = cheb1ord(Wp , Ws , Rp, Rs)

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

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

IIR Filter Design

of passba nd ripple, and a t least 60 dB of stopband at tenua tion. You can m eetth ese specifica tions by using t he butter function a s follows .

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

Page 85: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 85/798

2-9

n =12

Wn =0.1951 0.4080

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

An elliptic filter th a t meets t he sam e 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 functions a lso work with the other sta nda rd ba nd configurat ions, a s w ella s for an alog fi lters; see Cha pter 7, “Function Reference,” for details.

Comparison of Classical IIR Filter TypesThe t oolbox provides five different ty pes of classical IIR filters, ea ch optima l insome wa y. This section shows t he basic an a log prototy pe form for each a ndsumma rizes ma jor chara cterist ics.

Butterw orth FilterThe B utt erwort h filter provides the best Ta ylor Series approxima tion to theideal lowpa ss f i lter response a t a na log frequencies a nd ; for a nyorder N , the ma gnitude squar ed response has 2 N -1 zero derivat ives at th eselocat ions ( m a x i m a l l y f l a t a t a nd ). Response is monotonic

overa ll, decrea sing smooth ly from to . a t.

Ω 0= Ω ∞=

Ω 0= Ω ∞=

Ω 0= Ω ∞= H j Ω( ) 1 2 ⁄ =Ω 1=

2 Filter Design

1

Page 86: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 86/798

2-10

Chebyshev Type I FilterThe Ch ebyshev Type I filter minimizes th e a bsolut e difference betw een t heidea l a nd a ctual frequency response over th e entire passband by incorpora tinga n equal r ipple of Rp dB in the passban d. Stopba nd response is ma xima lly flat .The tra nsit ion from passband to stopband is more rapid th an for t heBut terworth f il ter. a t .

10-1

100

101

0

0.2

0.4

0.6

0.8

Frequency(rad/sec)

M a g n

i t u d e

H j Ω( ) 10 R p 20 ⁄ –= Ω 1=

10-1

100

1010

0.2

0.4

0.6

0.8

1

Frequency(rad/sec)

a g n

i u e

IIR Filter Design

Cheb yshev Typ e II FilterThe Chebyshev Type II filter min imizes the a bsolute difference betw een theideal a nd a ctua l frequency response over the ent ire stopban d by incorporat inga n equal r ipple of Rs dB in t he stopband. Pa ssband response is maximally fla t .

Page 87: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 87/798

2-11

q pp p p y

The stopband d oes not a pproa ch zero as qu ickly as t he type I filter (a nd doesnot a pproa ch zero a t a ll for even-va lued filter order n ). The a bsen ce of rippl e inthe passban d, however, is often an importa nt a dvan ta ge.a t .

Elliptic FilterE lliptic filters a re equiripple in both th e pa ssba nd a nd st opba nd. Theygenera lly meet filter requirement s wit h th e low est order of an y support ed filterty pe. G iven a filter order n , passba nd r ipple Rp in decibels, a nd st opba nd rippleRs in decibels, elliptic filters minimize tr a nsition widt h. a t

.

H j Ω( ) 10 R s 20 ⁄ –=

Ω 1=

10-1

100

1010

0.2

0.4

0.6

0.8

1

Frequency(rad/sec)

M

a g n

i t u d e

H j Ω( ) 10 R p 20 ⁄ –=

Ω 1=

2 Filter Design

1

Page 88: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 88/798

2-12

Bessel FilterAna log B essel lowpa ss fi lters ha ve maximally flat group delay a t zerofrequency and r etain n early consta nt group delay a cross the entire passba nd.Fil tered signals therefore mainta in their wa vesha pes in the pa ssbandfrequency ra nge. Frequency ma pped a nd digita l Bessel filters, however, do notha ve this ma ximally flat property; t his toolbox supports only t he a na log casefor t he complete B essel filter d esign function.

B essel filters generally require a h igher filter order th a n other filters forsa t is factory s topband a t tenuat ion. a t and decreases asfilter order n increases.

10-1

100

1010

0.2

0.4

0.6

0.8

Frequency(rad/sec)

M a g n

i t u d e

H j Ω( ) 1 2 ⁄ < Ω 1=

IIR Filter Design

1

Page 89: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 89/798

2-13

Note The lowpa ss fi l ters shown a bove were crea ted w ith t he a na logprototype functions besselap , buttap , cheb1ap , cheb2ap , and ellipap . Thesefunctions find t he zeros, poles, an d ga in of an order n a na log fi lter of thea ppropria t e type w ith cutoff frequ ency of 1 ra d/s. The complete filt er designfunctions (besself , butter , cheby1 , cheby2 , and ellip ) call t he prototypingfunctions as a first st ep in th e design process. See “ Specia l Topics in II R Filt erDesign ” on pa ge 2-37 for det a ils.

To crea te simila r plots, use n = 5 a nd, as n eeded, Rp = 0.5 a nd Rs = 20 . Forexample, to create the elliptic 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

10-1

100

1010

0.2

0.4

0.6

0.8

Frequency(rad/sec)

M a g n

i t u d e

2 Filter Design

Direct IIR Filter DesignThis t oolbox uses t he t erm di r ect m ethods to describe techniques for II R designtha t f ind a f i lter ba sed on specifications in th e discrete domain. U nlike thea na log prototyping method, direct design methods a re not constra ined to the

d d l h h b d b d f h

Page 90: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 90/798

2-14

sta nda rd lowpa ss, highpass, ban dpass, or ba ndstop configurat ions. Rat her,these functions design fi lters w ith a n a rbitra ry, perhaps multiban d, frequencyresponse. This section discusses the yulewalk function, which is intendedspecifically for filter design; “Pa ra metric Modeling” on page 4-12 discussesother methods th a t ma y a lso be considered direct, such as P rony’s method,Linea r P rediction, th e Steiglitz-McBride meth od, a nd inverse frequencydesign.

The yulewalk function designs recursive IIR digit a l filters by fit ting a specifiedfrequency response. yulewalk ’s na me reflects its m ethod for finding t he filter ’sdenominat or coefficients: it finds t he inverse FF T of the idea l desired pow erspectr um a nd solves the “modified Yule-Wa lker equa tions” using th e resultinga utocorrela tion function sam ples. The sta tement

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

returns row vectors b a nd a conta ining the n+1 numerat or and denomina torcoefficient s of th e order n II R filter wh ose frequency-ma gnitud e char a cteristicsa pproxima te t hose given in vectors f a nd m. f is a vector of frequency pointsra nging from 0 to 1, wh ere 1 represent s th e Nyquist frequency. m is a vectorconta ining the desired ma gnitude response a t the points in f . f a nd mca ndescribe an y piecew ise linea r sha pe magn itude response, including amultiba nd response. The FI R count erpart of this function is fir2 , which alsodesigns a f i lter ba sed on a n a rbitra ry piecewise l inear ma gnitude response. See“FIR Fil ter Design ” on pa ge 2-16 for det a ils.

Note tha t yulewalk does not a ccept pha se informa tion, and no sta tements a rema de a bout the optimali ty of the result ing fi l ter.

Design a multiband fi l ter with yulewalk , and plot t he desired an d a ctualfrequency response.

m = [0 0 1 1 0 0 1 1 0 0];

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

IIR Filter Design

1

1.2

Page 91: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 91/798

2-15

Generalized Butterworth Filter DesignThe toolbox function maxflat enables you t o design generalized B utt erworthfilters, th at is , But terworth fi lters w ith d iffering numbers of zeros a nd poles.This is d esirable in some implementa tions w here poles a re more expensivecomputa tionally tha n zeros. maxflat is just like th e butter fun ction, excepttha t i t you ca n specify tw o orders (one for the numera tor a nd one for t hedenomina tor) inst ead of just one. These filters a re m a x i m a l l y f l a t . This mea nstha t t he result ing fi l ter is optimal for any num erat or and denomina tor orders,wit h the maximum number of derivat ives at 0 a nd the Nyquist frequency ω = π both se t to 0.

For exa mple, when t he tw o orders ar e the same, maxflat i s the same as butter .

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

b =0.0317 0.0951 0.0951 0.0317

a =1.0000 -1.4590 0.9104 -0.1978

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

0.2

0.4

0.6

0.8

1

2 Filter Design

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

b = 0.0317 0.0951 0.0951 0.0317

a =

Page 92: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 92/798

2-16

a =1.0000 -1.4590 0.9104 -0.1978

However, maxflat is more versat ile beca use it a llow s you to design a filter wit hmore zeros th a n poles.

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

b =0.0950 0.2849 0.2849 0.0950

a =1.0000 -0.2402

The third input t o maxfla t is t he hal f-power fr equency , a frequency betw een0 and 1 wi th a desi red magni tude response of .

You can a lso design l inea r pha se fil ters tha t h a ve the maxima lly flat propertyusing the 'sym' option.

maxflat(4,'sym',0.3)

ans =0.0331 0.2500 0.4337 0.2500 0.0331

For complete deta ils of th e maxflat a lgorithm, see Selesnick a nd B urrus [2].

1 2 ⁄

FIR Filter Design

FIR Filter Design

Digit a l filters w ith finite-dura tion impulse response (a ll-zero, or F IR filters)ha ve both a dvant a ges a nd disadva nta ges compared to infinite-dura tionimpulse response (IIR) filters.

Page 93: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 93/798

2-17

impulse response (IIR) filters.

FIR fi l ters have the following primar y a dvan ta ges:

• They can ha ve exactly linea r pha se.• They are alw a ys sta ble.•

The design methods a re generally linear .• They can be rea lized efficiently in h a rdw a re.• The fil ter sta rtup t ra nsients ha ve finite durat ion.

The primary disa dvant a ge of FIR fi l ters is tha t t hey often require a muchhigher filter order th a n I IR filters t o achieve a given level of performa nce.Correspondingly, t he delay of th ese filters is often much grea ter t ha n for anequal performance IIR filter.

Method Description Functions

Window ing Apply w indow to t runca tedinverse Fourier tr a nsform ofdesired “brick wa ll” filter

fir1 , fir2 ,kaiserord

Mult iband w i th

TransitionB a n d s

Equiripple or least squares

a pproach over sub-ba nds of th efrequency ra nge

firls , remez ,

remezord

ConstrainedLeast Squares

Minimize squared int egralerror over entire frequ encyra nge subject t o ma ximumerror constra ints

fircls , fircls1

Arbitrary

Response

Arbitra ry responses, including

nonlinear pha se and complexfilters

cremez

Ra ised C osin e L ow pa ss respon se w it hsmooth, sinusoida l t ra nsit ion

firrcos

2 Filter Design

Linear Phase FiltersExcept for cremez , all of the FI R filter design functions design linea r pha sefilters only . The filter coefficient s, or “ta ps,” of such filters obey either a n evenor odd symmetry relat ion. Depending on this symmetry, a nd on wh ether theorder n of th e filter is even or odd a linear pha se filter (stored in lengt h n + 1

Page 94: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 94/798

2-18

order n of th e filter is even or odd, a linear pha se filter (stored in lengt h n + 1vector b) ha s cert a in inherent restrictions on its frequency response.

The phase delay a nd group delay of linear pha se FIR fi l ters ar e equal a ndconsta nt over the frequency ba nd. For a n order n l inea r pha se FIR fi l ter, thegroup dela y is n /2, an d t he filtered signa l is simply dela yed by n /2 ti me s t eps(a nd t he ma gnitude of its F ourier t ra nsform is scaled by th e f i lter ’s ma gnituderesponse). This property preserves the w a ve sha pe of signa ls in th e passba nd;tha t is , there is no phase distort ion.

The funct ions fir1 , fir2 , firls , remez , fircls , fircls1 , and firrcos a lldesign type I a nd II l inea r phase FIR fi lters by defa ult . Both firls a nd remez

design t ype III a nd IV l inea r pha se FIR fi l ters given a 'hilbert' or'differentiator' f lag. cremez ca n design a ny t ype of l inea r pha se fil ter, andnonlinear pha se fil ters a s w ell .

Note B eca use the frequency response of a t ype II filter is zero at th e Nyquistfrequency (“high” frequency), fir1 does not design type II highpa ss a ndba ndst op filters. For odd-va lued n in th ese ca ses, fir1 a dds 1 to the order an dreturn s a t ype I filter.

Linear PhaseFilter Type

FilterOrder Symmetry of Coefficients

Response H(f),f = 0

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

Type I E ven even: No rest r ict ion No rest r ict ion

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

Type I I I E ven 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+, , ,=

FIR Filter Design

Windowing MethodConsider th e ideal, or “brick w a ll,” digita l low pass filter w ith a cutoff frequencyof ω0 ra d/s. This f i lter ha s ma gnitude 1 at al l frequencies w ith ma gnitude lesst h a n ω0, and m a gnitude 0 a t frequencies with ma gnitude betw een ω0 a nd π. I t simpulse response sequence h (n ) is

Page 95: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 95/798

2-19

impulse response sequence h (n ) is

This filter is not implementa ble since its impulse response is infinite a nd

noncausa l. To crea te a finite-dura tion impulse response, tru ncat e it bya pplying a w indow. B y reta ining th e centr a l section of impulse response in thistrunca tion, you obta in a l inea r phase FI R fi lter. For exa mple, a length 51 fi lterwith a lowpass cutoff frequency ω0 of ra d/s is

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

The window a pplied here is a simple rectan gular w indow. B y P a rseval’stheorem, this is t he length 51 fi lter t ha t best approximates t he idea l lowpa ss

filter, in the integra ted least squa res sense. The follow ing comma nds displayth e filter ’s frequ ency response.

[H,w] = freqz(b,1,512,2);s.xunits = 'rad/sample';s.yunits = 'squared';s.plot = 'mag'; % Plot magnitude only.freqzplot(H,w,s)title('Truncated Sinc Lowpass FIR Filter');

h n ( ) 12 π------ H ω( ) e j ωn ωd

π–

π∫ 1

2 π------ e j ωn ωd ω0–

ω0

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

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

0.4 π

2 Filter Design

1

1.2

1.4Truncated Sinc Lowpass FIR Filter

Page 96: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 96/798

2-20

Note the ringing a nd ripples in t he response, especially nea r t he ban d edge.This “G ibbs effect” does not van ish a s th e filter length in creases, but anonrectangula r w indow reduces i ts ma gnitude. Multiplication by a window inth e time doma in causes a convolution or smooth ing in th e frequency doma in.Apply a length 51 Ha mming w indow to the f i l ter.

b = 0.4*sinc(0.4*(-25:25));b = b.*hamming(51)';[H,w] = freqz(b,1,512,2);s.xunits = 'rad/sample';s.yunits = 'squared';s.plot = 'mag';freqzplot(H,w,s)title('Hamming-Windowed Truncated Sinc LP FIR Filter');

0 0.05 0.1 0.15 0.2 0.25 0.30

0.2

0.4

0.6

0.8

1

Normalized Frequency ( ×πrad/sample)

M a g n

i t u d e s q u a r e

d

FIR Filter Design

1

1.2

1.4Hamming−Windowed Truncated Sinc LP FIR Filter

Page 97: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 97/798

2-21

As you ca n see, this grea tly reduces the ringing. This improvement is a t t heexpense of tra nsition widt h (th e windowed version ta kes longer to ra mp frompa ssba nd t o stopban d) a nd optima lity (th e windowed version does notminimize th e integrat ed squa red error).

The fu nct ions fir1 a nd fir2 a re based on th is windowing process. Given afilter order and description of a n ideal desired filter, these functions return awindowed inverse Fourier tr a nsform of tha t ideal f i l ter. Both use a Ha mmingwindow by default , but t hey accept a ny w indow function. See “Overview” onpage 4-2 for an overview of wind ows a nd t heir properties.

Standard Band FIR Filter Design: fir1fir1 implements the classica l method of windowed l inear phase FI R digita lfilter design. It r esembles the IIR filter design functions in th a t it is formula tedto design fi l ters in sta nda rd ba nd configurat ions: lowpa ss, bandpa ss, highpass,an d bandstop.

The st a tements

n = 50; Wn = 0.4;

b = fir1(n,Wn);

0 0.05 0.1 0.15 0.2 0.25 0.30

0.2

0.4

0.6

0.8

Normalized Frequency ( ×πrad/sample)

M a g n

i t u d e s q u a r e

d

2 Filter Design

creat e row vector b cont a ining t he coefficient s of th e order n Ha mming-w indowed filter. This is a lowpa ss, linea r pha se FIR filter with cut off

frequency Wn . Wn is a n umber betw een 0 a nd 1, where 1 corresponds t o theNyqu ist frequency, ha lf the sa mpling frequency. (U nlike other meth ods, here

Wn corresponds to the 6 dB point.) For a highpa ss filter, simply a ppend t hestring 'high' to the function’s para meter l ist For a band pass or bandst op

Page 98: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 98/798

2-22

string high to the function s para meter l ist . For a band pass or bandst opfilter, specify Wn a s a tw o-element vector conta ining the pa ssband edgefrequencies; append the str ing 'stop' for th e bandst op configura tion.

b = fir1(n,Wn,window) uses t he w indow specified in column vector window forth e design. The vector window must be n+1 element s long. If you do not specifya w indow, fir1 a pplies a H am ming window.

Kaiser W indow O rder Estima tion.The kaiserord function estimates the filterorder, cutoff frequency, a nd K a iser w indow beta para meter needed t o meet agiven set of specifica tions. G iven a vector of frequency ban d edges an d acorresponding vector of ma gnit udes, as w ell a s ma ximum a llowa ble ripple,kaiserord returns a ppropriat e input pa ra meters for t he fir1 function.

M ultiba nd FIR Filter Design: fir2The fir2 function also designs windowed FIR fi l ters, but w ith a n a rbitra ri lysha ped piecewise linear frequency response. This is in cont ra st to fir1 , whichonly designs f i lters in sta nda rd lowpa ss, highpass, ba ndpass, a nd ban dstopconfigurations.

The commands

n = 50;

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

return row vector b conta ining the n+1 coefficient s of th e order n FIR fi lterw hose frequency-ma gnit ude cha ra cteristics mat ch those given by vectors f a nd m. f is a vector of frequency point s ra nging from 0 to 1, w here 1 represent sthe Nyquist frequency. mis a vector cont a ining th e desired ma gnitu de response

a t t he point s specified in f . (The II R counterpar t of this fun ction is yulewalk ,wh ich a lso designs f i l ters based on a rbitra ry piecewise l inea r ma gnituderesponses. See “IIR F il ter Design” on page 2-5 for deta ils.)

FIR Filter Design

Multiband FIR Filter Design with Transition BandsThe firls a nd remez functions provide a more general mea ns of specifying th eideal desired fi l ter tha n th e fir1 a nd fir2 functions. These functions designHilbert tra nsformers, differentiat ors, and other f i l ters with odd symmetriccoefficients (ty pe III a nd t ype IV linear pha se). They a lso let you include

i i “d ’ ” i i hi h h i i i i d d

Page 99: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 99/798

2-23

tr a nsition or “don’t car e” regions in w hich the error is not minimized, an dperform band dependent weighting of the minimization.

The firls function is an extension of the fir1 a nd fir2 functions in th at i tminimizes the int egra l of the squa re of the error betw een the desired frequency

response an d th e actua l frequency response.The remez function implements the Parks-McClellan algorithm, which usesth e Remez excha nge algorith m an d Chebyshev approxima tion theory to designfilters w ith optimal f i ts betw een t he desired a nd a ctual frequency responses.The filters a re optima l in the sense th a t t hey minimize the ma ximum errorbetw een t he desired frequency response a nd t he act ua l frequency response;th ey ar e sometimes called m i n i m a x filters. Filters designed in th is wa y exhibita n equiripple behavior in th eir frequency response, an d hence are a lso known

a s equir ipple filters. The P a rks-McClella n FI R filter design algorith m isperha ps the most popular a nd w idely used FIR filter design meth odology.

The syn ta x for firls a nd remez is th e sam e; the only difference is th eirminimiza tion schemes. The next exam ple shows h ow filters designed w ithfirls a nd remez reflect t hese different schemes.

Ba sic Configura tions

The defa ult mode of opera t ion of firls a nd remez is to design type I or ty pe IIlinear pha se filters, depending on w heth er th e order you desire is even or odd,respectively. A low pass exam ple w ith a pproximat e amplitude 1 from 0 to0.4 Hz, an d approximate am plitude 0 from 0.5 to 1.0 Hz is

n = 20; % Filter orderf = [0 0.4 0.5 1]; % Frequency band edgesa = [1 1 0 0]; % Desired amplitudesb = remez(n,f,a);

Fr om 0.4 to 0.5 Hz, remez performs no error minimiza tion; this is a t ra nsit ionba nd or “don’t ca re” region. A tr a nsition ba nd minimizes th e error more in t heband s tha t you do care about, at the expense of a slower tra nsit ion ra te. In th is

2 Filter Design

wa y, these types of f i lters ha ve an inherent tra de-off similar to FIR design bywindowing.

To compare leas t squa res to equiripple filter design, use firls to crea te asimilar filter. Type

bb = firls(n,f,a);

Page 100: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 100/798

2-24

( , , );

a nd compa re 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 fi l ter designed with remez exhibits equiripple beha vior.Also note tha t t he firls filter ha s a bett er response over most of the passba nda nd stopband, but a t th e ba nd edges ( f = 0.4 a nd f = 0.5 ), th e response isfur ther a wa y f rom the ideal tha n the remez fi lter. This shows th a t the remez filter ’s m a x i m u m error over the passban d a nd stopba nd is sma ller an d, in fact ,it is the sma llest possible for this ban d edge configura tion a nd filter length.

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

1.4

FIR Filter Design

Think of frequency band s a s lines over short frequ ency interva ls. remez a ndfirls use this scheme to represent a ny piecewise linear d esired function w ith

an y t ra nsi t ion bands . firls a nd remez design lowpa ss, highpa ss, bandpa ss,a nd ba ndstop fi l ters; a bandpa ss exa mple 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

Page 101: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 101/798

2-25

a = [0 0 1 1 0 0]; % Bandpass filter amplitude

Technically, these f a nd a vectors define five ban ds:

• Tw o stopba nd s, from 0.0 to 0.3 a nd from 0.8 to 1.0•

A passband from 0.4 to 0.7• Tw o tra nsit ion ba nds, from 0.3 to 0.4 an d from 0.7 to 0.8

Exa mple highpass a nd ban dstop fi lters ar e

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 pairs

a = [1 1 0 0 1 1]; % Bandstop filter amplitudeAn example multiband bandpa ss fi l ter 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 possibil ity is a f i lter t ha t ha s a s a tra nsit ion region t he l ine connectingthe passban d with the stopband; t his ca n help contr ol “runaw a y” magnit uderesponse in wide tra nsit 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

2 Filter Design

The W eight VectorBoth firls a nd remez a llow you to place more or less empha sis on minimizing

th e error in certa in frequency ba nds r elat ive to oth ers. To do th is, specify aw eight vector follow ing th e frequency and a mplitude vectors. An exam plelowpa ss equiripple filter wit h 10 times less ripple in the st opban d th a n th epassband is

Page 102: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 102/798

2-26

p

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 legal w eight vector is a lwa ys ha lf the length of the f a nd a vectors; t here mustbe exactly one w eight per band .

Anti-Symm etric Filters / Hilber t Tra nsform ersWhen called w ith a tra il ing 'h' or 'Hilbert' option, remez a nd firls designFIR filters w ith odd symmetr y, th a t is, type III (for even order) or type IV (forodd order) linear pha se filters. An ideal H ilbert t ra nsformer ha s thisa nti-symmetry property a nd a n a mplitude of 1 across th e entire frequencyrange. Try the following approximate Hilbert transformers.

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

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

FIR Filter Design

You can find t he dela yed Hilbert t ra nsform of a signa l x by passing i t t hroughth ese 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

Page 103: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 103/798

2-27

xh filter(bb,1,x); % Hilbert transform of x

The a na lytic signa l corresponding t o x is the complex signa l tha t ha s x as i t sreal part a nd the Hilbert t ra nsform of x as i t s imaginary par t . For th is FIRmethod (a n a lternat ive to the hilbert function), you must d elay x by hal f the

fi lter order to creat e the a na lytic signa l.xd = [zeros(10,1); x(1:length(x)-10)]; % Delay 10 samplesxa = xd + j*xh; % Analytic signal

This met hod does not w ork directly for filters of odd order, w hich require anoninteger delay. In this case, the hilbert function, described in “SpecializedTra nsforms” on pa ge 4-36, estimat es the a na lytic signal . Alternat ively, use theresample function to delay t he signa l by a nonint eger number of sam ples.

DifferentiatorsDifferentia tion of a signa l in th e time doma in is equiva lent to multiplica tion ofthe signa l’s Fourier tra nsform by a n ima ginary ra mp function. Tha t is , todifferentia te a signa l , pass i t thr ough a f i l ter tha t ha s a response H (ω) = j ω.Approxima te th e ideal differentia tor (w ith a delay) using remez or firls wi tha 'd' or 'differentiator' option.

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

To obta in t he correct deriva tive, scale by pi*fs ra d/s, w here fs is the sa mplingfrequency in hertz. For a type III filter, the differentiation band should stopshort of the Nyquist frequency, a nd t he am plitude vector must reflect tha tchan ge to ensure t he correct slope.

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

In the 'd' mode, remez weight s th e error by 1/ ω in nonzero amplitude bands t ominimize th e ma ximum re la t ive error. firls weight s th e error by (1/ ω)2 innonzero amplitude bands in t he 'd' mode.

2 Filter Design

The follow ing plots show t he ma gnitu de response for the differentia tors a bove.

3000

3500

Differentiator, odd order

3000

3500

Differentiator, even order

Page 104: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 104/798

2-28

Constrained Least Squares FIR Filter DesignThe Constra ined Least Sq ua res (CLS ) FIR filter design functions implement atechnique th a t ena bles you to design FIR filters w ithout explicitly defining thetransition bands for the magnitude response. The ability to omit thespecifica tion of tr a nsit ion ba nds is useful in severa l situa tions. For exa mple, itma y not be clear w here a r igidly defined t ra nsit ion ba nd should appear if noisea nd signal informa tion appea r together in the same frequency ban d. Simila rly,i t ma y ma ke sense to omit t he specifica tion of tra nsit ion ba nds if th ey appear

only to cont rol th e results of Gibbs phenomena t ha t a ppea r in th e filter ’sresponse. See Selesnick, Lan g, an d B urrus [2] for d iscussion of this m ethod.

Inst ead of defining passba nds, stopband s, and tra nsit ion regions, the CLSmethod a ccepts a cutoff frequency (for t he highpa ss, lowpa ss, ban dpas s, orba ndst op cases), or pass ban d a nd st opban d edges (for multiban d cases), for t hedesired response. In t his w a y, th e CLS method defines tra nsit ion regionsimplicitly, rather than explicitly.

The key feat ure of the CL S met hod is tha t it ena bles you to define upper a ndlower t hresholds tha t conta in the ma ximum allowa ble r ipple in the ma gnituderesponse. Given this constraint, the technique applies the least square errorminimiza tion t echniq ue over th e frequency ra nge of the filter ’s response,instea d of over specific ban ds. The error minimiza tion includes any a rea s of

0 100 200 300 400 5000

500

1000

1500

2000

2500

Frequency (Normalized)0 100 200 300 400 500

0

500

1000

1500

2000

2500

Frequency (Normalized)

FIR Filter Design

discont inuity in t he ideal, “brick wa ll” response. An a dditiona l benefit is tha tth e techniq ue ena bles you to specify a rbitra rily sma ll peaks resulting from

G ibbs’ phenomena .There ar e tw o toolbox functions t ha t implement t his design technique.

D i i F i

Page 105: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 105/798

2-29

For deta ils on t he ca lling synt a x for th ese functions, see their referencedescriptions in Ch a pter 7, “Function Reference.”

Basic Low pa ss and H ighp a ss CLS Filter DesignThe most ba sic of th e CLS design functions, fircls1 , uses th is techniq ue to

design low pass a nd highpa ss FIR filters. As an example, consider designing afilter w ith order 61 impulse response an d cutoff frequency of 0.3 (norma lized).Furt her, define the upper an d low er bounds t ha t const ra in th e design processa s:

• Ma ximum pa ssba nd d eviat ion from 1 (pas sba nd r ipple) of 0.02.• Maximum stopband deviation from 0 (stopband ripple) of 0.008.

To approach th is design problem us ing fircls1 , use the following comma nds.

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

Description Function

Constra ined least sq ua re multiban d FIR fi l ter design fircls

Constra ined least squa re fil ter design for lowpa ss a nd

highpass l inear pha se fil ters

fircls1

0 ds = 0.0081dp = 0.02

2 Filter Design

0.8

1

Page 106: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 106/798

2-30

M ultiba nd CLS Filter Design

fircls uses the sa me technique to design FI R filters wit h a desired piecewiseconst a nt m a gnit ude response. In th is ca se, you ca n specify a vector of ba ndedges and a corresponding vector of ba nd a mplitudes. In a ddition, you ca nspecify the ma ximum a mount of ripple for ea ch band .

For example, assu me th e specifica tions for a filter ca ll for:

• Fr om 0 to 0.3 (norma lized): a mplit ude 0, upper bound 0.005, lowerbound -0.005

• Fr om 0.3 to 0.5: amplit ude 0.5, upper bound 0.51, lower boun d 0.49• Fr om 0.5 to 0.7: a mplit ude 0, upper boun d 0.03, lower bound -0.03• Fr om 0.7 to 0.9: amplit ude 1, upper bound 1.02, low er bound 0.98• Fr om 0.9 to 1: a mplit ude 0, upper bound 0.05, low er bound -0.05

Design a CLS filter wit h impulse response order 129 th a t meets t hesespecifications.

n = 129;f = [0 0.3 0.5 0.7 0.9 1];a = [0 0.5 0 1 0];up = [0.005 0.51 0.03 1.02 0.05];

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10.2

0

0.2

0.4

0.6

FIR Filter Design

lo = [-0.005 0.49 -0.03 0.98 -0.05];h = fircls(n,f,a,up,lo,'plot');

1

1.2

Page 107: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 107/798

2-31

W eigh ted CLS Filter D esignWeighted CLS filter design lets you design lowpa ss or highpa ss FIR filters w ithrelat ive weight ing of th e error minimiza tion in each ban d. The fircls1 function enables you to specify the pa ssba nd a nd st opba nd edges for th e leastsqua res weighting function, as w ell as a consta nt k th a t specifies th e rat io ofthe stopband t o passban d weighting.

For exa mple, consider specifica tions th a t call for an FI R filter wit h impulseresponse order of 55 a nd cut off frequency of 0.3 (norma lized). Also ass umema ximum a llowa ble pa ssband ripple of 0.02 an d ma ximum a llowa ble stopba ndripple of 0.004. In a ddition, a dd w eighting requ irements:

• P a ssba nd edge for the w eight fun ction of 0.28 (norma lized)• St opba nd edge for t he w eight function of 0.32• Weight error minimizat ion 10 times a s much in the stopban d a s in the

passband

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10.2

0

0.2

0.4

0.6

0.8

2 Filter Design

To approach t his using fircls1 , type

n = 55;wo = 0.3;dp = 0.02;ds = 0.004;wp = 0.28;ws = 0 32;

Page 108: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 108/798

2-32

ws = 0.32;k = 10;h = fircls1(n,wo,dp,ds,wp,ws,k,'plot');

Arbitrary-Response Filter DesignThe cremez filter design function provides a tool for designing F IR filters wit ha rbitra ry complex responses. It differs from t he other filter design functions inhow t he frequency response of the filter is specified: it a ccepts t he na me of afunction wh ich return s th e filter response ca lcula ted over a grid of frequencies.This capa bility m a kes cremez a highly versatile and powerful technique forfilter design.

This design t echniq ue ma y be used t o produce nonlinea r-pha se FIR filters,asymmetric frequency-response filters (with complex coefficients), or moresymmet ric filters w ith cust om frequency responses.

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10.2

0

0.2

0.4

0.6

0.8

1

FIR Filter Design

The design a lgorithm optimizes th e Chebyshev (or minima x) error using a nextended Remez-exchange algorithm for an initial estimate. If this exchange

method fails to obta in th e optimal f i l ter, the a lgorithm switches to ana scent -descent a lgorith m th a t t a kes over to finish th e convergence to theoptima l solut ion.

M ultiba nd Filter Design

Page 109: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 109/798

2-33

gConsider a m ultiba nd filter wit h th e followin g special frequency-doma incharacterist ics.

A linear-pha se multiba nd filter ma y be designed using t he predefinedfrequency-response function multiband , a s 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 iban d filter, we ca n use a short ha nd filter designnotat ion simila r to the synta x 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 w ith remez , a vector of ban d edges is pa ssed to cremez . This vector definesthe frequency ba nds over w hich optimizat ion is performed; note t ha t there a retw o tra nsit ion bands, from -0.5 to -0.4 an d from 0.3 to 0.4.

Band Amplitude OptimizationWeighting

[-1 -0.5] [5 1] 1

[-0.4 + 0.3] [2 2] 10

[+ 0.4 + 0.8] [2 1] 5

2 Filter Design

In eith er ca se, th e frequency response is obta ined an d plott ed using linearscale.

[h,w] = freqz(b,1,512,'whole');plot(w/pi-1,fftshift(abs(h))); grid;xlabel('Normalized Frequency');ylabel('Magnitude Response');

Page 110: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 110/798

2-34

Note tha t t he frequency response ha s been calculat ed over the entirenorma lized frequency ran ge [-1 + 1] by passing t he option 'whole' t o freqz. Inorder to plot the negat ive frequency informa tion in a n a tura l wa y, the response

ha s been “w ra pped,” just a s FFT da ta is , using fftshift .

The filter response for this multiband filter is complex, which is expectedbecause of th e a symmetry in the frequency domain.

-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

M a g n

i t u d e

R e s p o n s e

FIR Filter Design

1

1.5

2

2.5

a l P a r t

Page 111: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 111/798

2-35

Filter De sign w ith Reduced Dela yConsider th e design of a 62-ta p low pas s filter w ith a ha lf-Nyqu ist cutoff. If wespecify a n egat ive offset va lue to the lowpass filter design function, the groupdelay offset for the design is significant ly less tha n th a t obtained for a sta nda rdlinear -pha se design. This filter design m a y be comput ed a s follows.

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

The resultin g ma gnitu de response is

[h,w] = freqz(b,1,512,'whole');plot(w/pi-1,fftshift(abs(h))); grid;xlabel('Normalized Frequency');ylabel('Magnitude Response');

0 5 10 15 20 25 30 35 40-0.5

0

0.5 R e a

0 5 10 15 20 25 30 35 40-0.2

0

0.2

I m a g

P a r t

2 Filter Design

0 8

1

1.2

1.4

s p o n s e

Page 112: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 112/798

2-36

The group dela y of the filter reveals t ha t t he offset ha s been reduced from N/2 t o N/2-16 (i.e., fr om 30.5 t o 14.5 ). Now, h owever, the gr oup dela y is n o longerflat in th e pa ssba nd region (plott ed over the norma lized frequency ran ge 0 to0.5 for clar 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

Normalized Frequency

M a g n

i t u d e

R e s

0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5

12

13

14

15

16

17

Normalized frequency (Nyquist == 1)

G r o u p

d e

l a y

( i n s a m p

l e s )

FIR Filter Design

If w e compare t his nonlinear-phase fi l ter to a l inea r-phase fi l ter tha t ha sexa ctly 14.5 sa mples of group dela y, t he result ing filt er is of order 2*14.5, or 29.Using b = cremez(29,[0 0.5 0.55 1],'lowpass') , the passband a ndstopban d ripple is much grea ter for t he order 29 filter. These compa risons cana ssist y ou in deciding w hich filter is more a ppropriat e for a specific a pplicat ion.

Page 113: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 113/798

2-37

2 Filter Design

Special Topics in IIR Filter Design

The class ic IIR filter design t echniq ue finds an a na log lowpa ss filter wit h cutofffrequency of 1, tra nsla tes th is “prototype” filter to the desired bandconfigura tion, then t ra nsforms th e filter to th e digita l domain. The toolboxprovides functions for each step of this process.

Page 114: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 114/798

2-38

The butter , cheby1 , cheby2 , and ellip functions ar e sufficient for ma nydesign problems, and th e low er level functions a re generally n ot needed. But ifyou do ha ve an a pplica tion where you need to tra nsform t he band edges of ana na log filter, or discretize a ra tiona l tra nsfer function, th is section describesth e tools wit h w hich to do so.

Classical IIR Filter Design

Analog Lowpass Prototype Creation Frequency Transformation Discretization

buttapellipap

cheb1apcheb2ap

besselap lp2lplp2bp

lp2hplp2bs

bilinearimpinvar

butter cheby1 cheby2 ellip besself

Minimum Order Computation for Classical IIR Filter Design

buttord cheb1ord cheb2ord ellipord

Complete Design

Special Topics in IIR Filter Design

Analog Prototype DesignThis t oolbox provides a number of functions t o crea te lowpa ss a na log prototype

filters wit h cutoff frequency of 1, the first s tep in th e clas sica l approa ch to IIRfilter design. The ta ble below summa rizes the a na log prototype designfunctions for ea ch supported filter ty pe; plots for each t ype are sh own in “IIRFilter Design” on pa ge 2-5.

Page 115: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 115/798

2-39

Frequency TransformationThe second st ep in t he a na log prototyping design t echniq ue is th e frequencytr a nsforma tion of a lowpa ss prototype. The t oolbox provides a set of functionsto t ra nsform a na log lowpas s prototypes (wit h cutoff frequency of 1 ra d/s) intobandpass, highpass, bandstop, and lowpass filters of the desired cutofffrequency.

Filter Type Analog Prototype Function

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

Butterworth [z,p,k] = buttap(n)

Ch ebysh ev Type I [z,p,k] = cheb1ap(n,Rp)

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

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

2 Filter Design

Freq. Transformation Transformation Function

Lowpass t o lowpa ss[numt,dent] = lp2lp(num,den,Wo)[At,Bt,Ct,Dt] = lp2lp(A,B,C,D,Wo)

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

s ’ s ω0 ⁄ =

s ’ω0s

-------=

Page 116: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 116/798

2-40

As shown, all of the frequency transformation functions can accept two linearsystem models: tra nsfer function an d st at e-space form. For th e bandpa ss a ndbandst op cases

a nd

where ω1 is the lower ba nd edge and ω2 is the upper ban d edge.

The frequency tra nsforma tion functions perform frequency va ria blesubsti tution. In t he case of lp2bp a nd lp2bs , th is is a second-ord ersubstit ut ion, so the output filter is tw ice th e order of the input. For lp2lp a ndlp2hp , the output f i lter is the sa me order as the input.

To begin designing a n order 10 ba ndpa ss Chebyshev Type I filter wit h a va lue

of 3 dB for passba nd ripple, enter[z,p,k] = cheb1ap(5,3);

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

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

s

s ’ ω0B ω------- s ω0 ⁄ ( )

21+

s ω0 ⁄ -------------------------------=

s ’B ωω0-------

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

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

ω0 ω1ω2=

B ω ω2 ω1–=

Special Topics in IIR Filter Design

Outputs z , p , and k cont a in th e zeros, poles, a nd ga in of a lowpa ss a na log filterw ith cut off frequency Ωc equa l to 1 ra d/s. U se th e lp2bp function t o tra nsformthis lowpa ss prototype to a bandpa ss an a log fi lter w ith ba nd edgesa nd . First , convert th e filter to sta te-spa ce form so th e lp2bp functioncan accept it.

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

Now, find t he bandw idth a nd center frequency, and call lp2bp .

Ω1

π 5 ⁄ =Ω2 π=

Page 117: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 117/798

2-41

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);

Fina lly, ca lculat e the frequency response a nd plot i ts ma gnitude.

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

xlabel('Frequency (Hz)');.

0 0.2 0.4 0.6 0.8 110

−7

10−6

10−5

10−4

10−3

10−2

10−1

100

Frequency (Hz)

2 Filter Design

Filter DiscretizationThe third step in th e an a log prototyping t echnique is th e tra nsforma tion of th e

filter t o the discrete-time d omain. The t oolbox provides t wo m ethods for t his:the impulse inva riant a nd bil inea r t ra nsforma tions. The fi lter design functionsbutter , cheby1 , cheby2 , and ellip use the bilinear t ra nsforma tion fordiscretizat ion in this step.

Page 118: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 118/798

2-42

Impulse InvarianceThe toolbox function impinvar creat es a digita l filter w hose impulse response

is th e sa mples of th e cont inuous impulse response of an a na log filter. Thisfunction works only on filters in t ra nsfer function form. For best results, t hea na log filter should ha ve negligible frequency content a bove half th e samplingfrequency, because such high frequency cont ent is a liased int o lower ba ndsupon sa mpling. Impulse invarian ce works for some lowpa ss a nd ba ndpassfi lters, but is n ot a ppropriat e for h ighpass a nd ba ndstop fi lters.

Design a Chebyshev Type I filter a nd plot its frequ ency response.

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

Analog to DigitalTransformation

Transformation Function

Impulse inva riance [numd,dend] = impinvar(num,den,fs)

Bilinear transform [zd,pd,kd] = bilinear(z,p,k,fs,Fp)[numd,dend] = bilinear(num,den,fs,Fp)[Ad,Bd,Cd,Dd] = bilinear(At,Bt,Ct,Dt,fs,Fp)

Special Topics in IIR Filter Design

200

0 0.2 0.4 0.6 0.8 1−150

−100

−50

0

Normalized Frequency ( ×πrad/sample)

M a g n

i t u d e ( d B )

Page 119: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 119/798

2-43

Impulse inva riance retains t he cutoff frequencies of 0.1 Hz a nd 0.5 Hz.

Bilinea r Tra nsform a tionThe bilinear t ra nsforma tion is a n onlinea r ma pping of the continuous domainto the discrete doma in; i t ma ps the s -plan e into the z -pla ne by

B ilinear tra nsforma tion ma ps the -axis of the continuous doma in to the unitcircle of th e discrete doma in a ccording t o

The t oolbox fun ction bilinear implement s this opera tion, where th e frequencywa rping consta nt k is equal t o tw ice the sa mpling frequency ( 2*fs ) by defau lt,a nd equal to if you give bilinear a t ra i ling argument thatrepresents a “mat ch” frequency Fp . If a ma tch frequency Fp (in h ert z) ispresent, bilinear ma ps th e frequency (in ra d/s) to th e sa mefrequency in the discrete domain, normalized to the sampling rate:

(in ra d/sa mple).

0 0.2 0.4 0.6 0.8 1−800

−600

−400

−200

0

200

Normalized Frequency ( ×πrad/sample)

P h a s e

( d e g r e e s )

H z ( ) H s ( )s k

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

=

j Ω

ω 2 t a n 1– Ωk ---- =

2 πf p πf p f s ⁄ ( )t a n ⁄

Ω 2 πf p

=

ω 2 πf p f s ⁄ =

2 Filter Design

The bilinear function can perform this transformation on three differentlinear sy stem representa tions: zero-pole-ga in, tra nsfer function, andstate-space form. Try calling bilinear with t he stat e-space ma trices tha tdescribe th e Ch ebyshev Type I filter from t he previous s ection, using asa mpling frequency of 2 Hz, a nd ret a ining th e low er ban d edge of 0.1 Hz.

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

The frequency response of th e resulting digita l filter is

Page 120: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 120/798

2-44

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

The lower ba nd edge is a t 0.1 Hz a s expected. Notice, however, tha t t he upperband edge is slightly less tha n 0.5 Hz, al though in the a na log doma in i t wa sexactly 0.5 Hz. This illustra tes th e nonlinear n a tur e of the bilinea rtra nsforma tion. To countera ct t his nonlinearity, i t is n ecessary t o creat e a na logdomain filters w ith “prewa rped” ba nd edges, wh ich ma p to th e correct loca tionsupon bilinear transformation. Here the prewarped frequencies u1 a nd u2 generate Bwa nd Wo for t he lp2bp function.

fs = 2; % Sampling frequency (hertz)

u1 = 2*fs*tan(0.1*(2*pi/fs)/2); % Lower band edge (rad/s)u2 = 2*fs*tan(0.5*(2*pi/fs)/2); % Upper band edge (rad/s)Bw = u2 - u1; % Bandwidth

Wo = sqrt(u1*u2); % Center frequency[At,Bt,Ct,Dt] = lp2bp(A,B,C,D,Wo,Bw);

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

-500

0

500

Normalized frequency (Nyquist == 1)

P h a s e

( d e g r e e s

)

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

-200

-100

0

Normalized frequency (Nyquist == 1)

M a g n

i t u d e

R e s p o n s e

( d B )

Special Topics in IIR Filter Design

A digita l band pass filter w ith correct ba nd edges 0.1 a nd 0.5 times t he Nyquistfrequency is

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

The example ban dpa ss filters from th e last tw o sections could a lso be crea tedin one sta tement using t he complete IIR design function cheby1 . For insta nce,a n a na log version of the exa mple Chebyshev filter is

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

Page 121: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 121/798

2-45

Note tha t t he band edges a re in ra d/s for a na log fi l ters, wh ereas for t he digital

case, frequency is norma lized.[bz,az] = cheby1(5,3,[0.1 0.5]);

All of th e complete design fun ctions ca ll bilinear interna lly. They prewa rp th eba nd edges as needed to obta in th e correct digita l filter. See Cha pter 7,“Function Reference,” for more on th ese functions.

2 Filter Design

Selected Bibliography[1] Ka ra m, L.J ., and J .H. McClella n. “Complex Chebyshev Approxima tion forFIR Fil ter Design.” I EE E T ran s. on Cir cui ts and Systems I I . Ma rch 1995.

[2] Selesnick, I.W., and C.S. Burrus. “Generalized Digital Butterworth FilterDesign.” Pr oceedi ngs of t he IE EE I nt . Conf. Acoust., Speech, Si gnal Pr ocessing .Vol. 3 (Ma y 1996).

[3] Selesnick I W M Lang and C S Burrus “Constrained Least Square

Page 122: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 122/798

2-46

[3] Selesnick, I.W., M. Lang, and C.S. Burrus. Constrained Least SquareDesign of FIR Filters without Specified Transition Bands.” Pr oceedi ngs of th e I EE E I nt . Conf . Acoust., Speech, Signal Pr ocessi ng . Vol. 2 (Ma y 1995).P gs. 1260-1263.

3St a t ist ica l Signa l

ProcessingOverview . . . . . . . . . . . . . . . . . . . . . 3-2

Page 123: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 123/798

Correlation and Covariance . . . . . . . . . . . . . 3-3B ias a nd Norma liza tion . . . . . . . . . . . . . . . . 3-4Multiple Cha nnels . . . . . . . . . . . . . . . . . . 3-5

Spectral Analysis . . . . . . . . . . . . . . . . . . 3-6Spectra l Est imat ion Method Overview . . . . . . . . . . 3-8Nonpara metric Methods . . . . . . . . . . . . . . . . 3-10P a ra metric Methods . . . . . . . . . . . . . . . . . 3-30

Selected Bibliography . . . . . . . . . . . . . . . 3-39

3 Statistical Signal Processing

OverviewThe S igna l P rocessing Toolbox provides tools for est ima ting import a ntfunctions of ra ndom signals. In pa rticula r, there a re tools to estimatecorrela tion a nd cova ria nce sequences a nd spectr a l density functions of discretesigna ls. The follow ing sections explain th e correla tion a nd covaria nce functionsa nd discuss th e mat hemat ica lly relat ed functions for estimat ing the powerspectrum:

• “Correlat ion a nd Covaria nce”

Page 124: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 124/798

3-2

“Correlat ion a nd Covaria nce”• “Spectral Analysis”• “Selected Bibliography”

C orrelation and C ovaria nce

Correlation and CovarianceThe fu nct ions xcorr a nd xcov estima te th e cross-correla tion an dcross-covariance sequences of random processes. They also handlea utocorrelation a nd a utocovaria nce as specia l cases.

The tru e cross-correla tion sequence is a st a tist ica l qua nt ity defined as

R x y m ( ) E x n m + y *n E x n y *n m – ==

Page 125: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 125/798

3-3

where x n a nd y n ar e sta tionary ra ndom processes, , a nd E ⋅ is th e

expected value operator. The covariance sequence is the mean-removedcross-correlation sequence

or, in terms of the cross-correlation,

In pra ctice, you must estima te t hese sequences, beca use it is possible to accessonly a finite segment of th e infinite-length ra ndom process. A common estima teba sed on N sa mples of x n a nd y n is t he d eterminist ic cross-correla tion s equence(a lso ca lled the t ime-a mbiguity function)

wh ere we assume for t his discussion t ha t x n a nd y n a re indexed from 0 to N -1,a nd from -( N -1) to N -1. The xcorr function evalua tes this sum with a nefficient FFT-ba sed a lgorith m, given input s x n a nd y n stored in lengt h N vectors x a nd y . Its operat ion is equiva lent t o convolution with one of th e tw osubsequences reversed in time.

For exam ple,

x = [1 1 1 1 1]';y = x;

∞– n ∞< <

C x y m ( ) E x n m + µx –( ) y n µy –( )*=

C x y m ( ) R x y m ( ) µx µ*y –=

R ˆ

x y m ( )x n m + y n

*

n 0=

N m – 1–

∑ m 0≥

R ˆ

y x *

m –( ) m 0<

=

R ˆ

x y m ( )

3 Statistical Signal Processing

xyc = xcorr(x,y)

xyc =

1.00002.00003.00004.00005.00004.0000

Page 126: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 126/798

3-4

3.00002.00001.0000

Notice th a t t he resulting sequence length is one less tha n tw ice the lengt h ofth e input sequence. Thus, t he N th element is th e correlation at lag 0. Alsonotice the t r iangula r pulse of the output t ha t results w hen convolving t wosqua re pulses.

The xcov function estima tes a ut ocovaria nce a nd cross-cova ria nce sequences.This function has t he same options and eva luat es the same sum a s xcorr , butfirst removes the mean s of x a nd y .

Bias and NormalizationAn estimat e of a qua nti ty is biased if its expected va lue is not equa l to thequa nt ity it estima tes. The expected va lue of the output of xcorr is

xcorr provides the unbia sed estima te, dividing by N -| m | , when you specify an'unbiased' flag a fter th e input sequences.

xcorr(x,y,'unbiased')

Although t his estima te is unbia sed, the end points (near -( N -1) a nd N -1) suf ferfrom la rge varia nce because xcorr computes them using only a few da ta points.A possible tra de-off is to simply d ivide by N using the 'biased' flag.

xcorr(x,y,'biased')

E R

ˆ

x y m ( ) E x n m + y *

n n 0=

– –

∑ N m –( )R x y m ( )= =

C orrelation and C ovaria nce

With t his scheme, only the sa mple of the correla tion a t zero lag (the N th outputelement) is unbia sed. This estima te is often more desirable tha n t he unbia sedone because i t a voids ran dom la rge varia tions at the end points of thecorrela tion sequence.

xcorr provides one oth er norma lizat ion scheme. The synt a x

xcorr(x,y,'coeff')

divides the out put by norm(x)*norm(y) so tha t , for aut ocorrelations, thesample a t zero lag is 1.

Page 127: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 127/798

3-5

p g

Multiple ChannelsFor a mult icha nnel signa l, xcorr a nd xcov estimat e the autocorrelat ion a ndcross-correla tion a nd covaria nce sequences for a ll of th e chan nels a t once. If S i s an M -by-N signal ma trix representing N chan nels in its columns, xcorr(S) returns a (2 M -1)-by- N 2 ma tr ix w ith t he aut ocorrelat ions a nd cross-correla tionsof the chan nels of S in i ts N 2 columns. If S is a three-channel signal

S = [s1 s2 s3]

then t he result of xcorr(S) is orga nized a s

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

Tw o relat ed functions, cov a nd corrcoef , a re ava i lable in the s ta ndardMATLAB environment. They estima te cova ria nce and norma lized cova ria ncerespectively between the different chan nels at lag 0 a nd a rra nge them in asquare mat r ix.

3 Statistical Signal Processing

Spectral AnalysisThe g oa l of spectr al estim ati on is t o describe th e distr ibution (over fr equency)of the power conta ined in a signal, based on a finite set of da ta . Estima tion ofpow er spectr a is useful in a va riety of applica tions, including t he detection ofsigna ls buried in wide-ba nd n oise.

The power spectru m of a sta tionary r an dom process x n i s ma themat ical lyrelat ed to the correla tion sequence by th e discrete-time Fourier tra nsform. Interms of norma lized frequency, th is is given by

Page 128: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 128/798

3-6

This can be w ritt en a s a function of physical frequency f (e.g. , in hertz) by usingthe relat ion ω = 2πf /f s , where f s is the sampling frequency.

The correla tion sequence can be derived from t he power spectr um by use of th einverse discrete-time F ourier t ra nsform.

The a vera ge pow er of the sequ ence x n over the entire Nyquist interval isrepresent ed by

S x x ω( ) R x x m ( ) e j ωm –

m ∞–=

∑=

S x x

f ( ) R x x

m ( ) e 2 π j f m – f s ⁄

m ∞–=

∑=

R x x m ( )S x x ω( ) e j ωm

2 π------------------------------ ωd

π–

π

∫ S x x f ( ) e 2 π j f m f s ⁄

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

f s 2 ⁄ –

f s 2 ⁄

∫ = =

R x x 0( )S x x ω( )

2 π----------------- ωd

π–

π

∫ S x x f ( )

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

f s 2 ⁄ –

f s 2 ⁄

∫ = =

Spectral A nalysis

The quantities

from the a bove expression a re defined a s th e power spectr al d ensit y (P SD ) ofthe s ta t ionary ra ndom signal x n .

The a verage power of a signal over a part icular frequency band ,, ca n be found by integrat ing the PS D over tha t ba nd.

P x x ω( )S x x ω( )

2 π-----------------= P x x f ( )

S x x f ( )

f s ---------------=a nd

ω1 ω2[ , ]0 ω1 ω2 π≤<≤

Page 129: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 129/798

3-7

You can see from t he a bove expression t ha t P xx (ω) represent s t he power contentof a signa l in a n i n f in i t e s ima l frequency band, w hich is w hy w e ca ll it t he powerspectral density .

The unit s of th e PS D a re pow er (e.g., w a tt s) per unit of frequency. In t he case

of P xx (ω), th is is w a tt s/ra d/sa mple or simply wa tt s/ra d. I n t he case of P xx (f ), t heunits a re wa tt s/hertz. Int egrat ion of the P SD with respect to frequency yieldsunits of wa tt s, a s expected for the avera ge power .

For rea l signa ls, the P SD is symmetric a bout D C, an d thus P xx (ω) foris sufficient t o completely cha ra cterize th e PS D. H owever, in order to obta inthe a verage power over t he entire Nyquist int erval i t is n ecessary t o introduceth e concept of the one-sided P S D .

The one-sided P SD is given by

The a vera ge pow er of a signa l over th e frequency ba nd , ,can be comput ed using th e one-sided P SD a s

P ω1 ω2,[ ] P x x ω( ) ωd

ω1

ω2

∫ P x x ω( ) ωd

ω– 2

ω– 1

∫ +=

P ω1 ω2,[ ]

0 ω π<≤

P o n e s i d e d ω( )0 -π ω≤ 0<,2 P x x ω( ) 0 ω≤ π<,

=

ω1 ω2[ , ] 0 ω1 ω2 π≤<≤

P ω1 ω2,[ ] P o n e s i d e d ω( ) ωd

ω1

ω2

∫ =

Page 130: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 130/798

Spectral A nalysis

Method Description Functions

P er iodogra m P ow er spect ra l d en sit y est ima t e periodogram

Welch Avera ged per iodogra ms ofoverla pped, w indowed signa l sections

pwelch , csd ,tfe , cohere

Mult it a per ) S pect ra l est im at e fr om combin a tionof multiple ort hogona l w indows (or“tapers”)

pmtm

Page 131: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 131/798

3-9

tapers )

Yule-Wa lkerAR

Aut oregressive (AR) spect ra lestima te of a t ime-series from itsestimated autocorrelation function

pyulear

B urg Aut oregressive (AR) spect ra lestima tion of a time-series byminimiza tion of linea r predictionerrors

pburg

C ova ria nce Aut oregressive (AR) spect ra lestima tion of a time-series byminimiza tion of the forwa rdprediction errors

pcov

ModifiedCovariance

Aut oregressive (AR) spect ra lestima tion of a time-series byminimiza tion of the forwa rd a nd

backward prediction errors

pmcov

MU S IC Mult iple signa l cla ssifica t ion pmusic

E igenvect or P seudospect rum est ima te peig

3 Statistical Signal Processing

Nonparametric MethodsThe follow ing sections dis cuss t he periodogram , modified periodogram , Welch,

a nd multi taper methods of nonpar a metric estima tion, along w ith t he rela tedCSD function, tra nsfer function estima te , and coheren ce function.

The PeriodogramOne wa y of estima ting t he pow er spectrum of a process is to simply find t hediscrete-time F ourier tra nsform of the sa mples of th e process (usua lly done ona grid with a n FF T) an d ta ke the magnitu de squar ed of the result . Thisestimat e is ca lled th e periodogram

Page 132: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 132/798

3-10

estimat e is ca lled th e periodogram .

The periodogra m estima te of th e PS D of a length-L signa l x L [n ] is

where

The a ctua l computa tion of X L (f ) can be performed only a t a finite number offrequency point s, N , an d usua lly employs the FF T. In pra ctice, mostimplement a tions of th e periodogra m meth od compute the N -point P SDest imate

where

It is w ise to choose N > L so tha t N is the next power of two larger t ha n L . Toevaluate X L [f k ], w e simply pad x L [n ] w ith zeros to length N . I f L > N , we mustw r a p x L [n ] modulo- N prior t o computing X L [f k ].

P ˆ

x x f ( )X L f ( )2

f s L--------------------=

X L f ( ) x L n [ ]e 2 π j f n – f s ⁄

n 0=

∑=

P ˆ x x f k [ ]X

Lf

k [ ]2

f s L----------------------- ,= f k

k f s

N -------- ,= k 0 1 … N 1–, , ,=

X L f k [ ] x L n [ ]e 2 π j k n – N ⁄

n 0=

N 1–

∑=

Spectral A nalysis

As an example, consider the following 1001-element signal xn , wh ich consist sof tw o sinusoids plus n oise.

randn('state',0);fs = 1000; % Sampling frequencyt = (0:fs)/fs; % One second worth of samples

A = [1 2]; % Sinusoid amplitudes (row vector)f = [150;140]; % Sinusoid frequencies (column vector)xn = A*sin(2*pi*f*t) + 0.1*randn(size(t));

Page 133: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 133/798

3-11

Note The th ree la st l ines i l lustra te a convenient a nd general w ay to expressth e sum of sinusoids. Togeth er th ey a re equiva lent t o

xn = sin(2*pi*150*t) + 2*sin(2*pi*140*t) + 0.1*randn(size(t));

The periodogra m estima te of the P SD can be computed by

Pxx = periodogram(xn,[],'twosided',1024,fs);

a nd a plot of the estima te can be displa yed by simply omitt ing the outputa rgument, as below.

periodogram(xn,[],'twosided',1024,fs);

0 100 200 300 400 500 600 700 800 900−90

−80

−70

−60

−50

−40

−30

−20

−10

0

Frequency (Hz)

P o w e r

S p e c t r a

l D e n s i t y

( d B / H z )

Periodogram PSD Estimate

Page 134: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 134/798

Spectral A nalysis

The effect of the convolution is best u nderst ood for sinusoida l da ta . Supposet h a t x [n ] is composed of a sum of M complex sinus oids.

It s spectrum is

x n [ ] A k e j ωk n

k 1=

M

∑=

X f ( ) f s A k δ f f k–( )M

∑=

Page 135: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 135/798

3-13

w hich for a finite-length sequence becomes

So in the spectr um of th e finite-length signa l, the Dira c delta s ha ve beenreplaced by terms of th e form , w hich corresponds to th e frequencyresponse of a recta ngula r w indow centered on th e frequency f k .

The frequency response of a recta ngula r win dow ha s the sha pe of a sin c signa l,a s shown below.

( ) s k k ( )k 1=

X L f ( ) A k δ ρ f k –( )k 1=

M

W R f ρ–( ) ρd

f s 2 ⁄ –

f s 2 ⁄

∫ A k W R f f k –( )k 1=

M

∑= =

W R f f k –( )

−0.5 0 0.5−90

−80

−70

−60

−50

−40

−30

−20

−10

0

3 Statistical Signal Processing

The plot d isplays a ma in lobe an d several side lobes, the la rgest of wh ich isa pproxima tely 13.5 dB below th e ma inlobe pea k. These lobes account for t heeffect known a s spectra l l eaka ge . While the infinite-length s igna l ha s its powerconcentrated exactly at the discrete frequency points f k , th e wind owed (ort runcat ed) signal ha s a continuum of power “leaked” ar ound t he discretefrequency point s f k .

B eca use the frequency response of a s hort recta ngula r w indow is a m uch poorera pproximat ion to the Dira c delta function tha n th a t of a longer w indow,spectral leaka ge is especially evident w hen da ta records are sh ort . C onsider thefollow ing s equence of 100 sa mples.

Page 136: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 136/798

3-14

randn('state',0)fs = 1000; % Sampling frequencyt = (0:fs/10)/fs; % One-tenth of a second worth of samples

A = [1 2]; % Sinusoid amplitudesf = [150;140]; % Sinusoid frequenciesxn = A*sin(2*pi*f*t) + 0.1*randn(size(t));periodogram(xn,[],1024,fs);

It is importa nt t o note tha t t he effect of spectr a l lea ka ge is cont ingent solely onthe length of the dat a record. I t is n ot a consequence of the fact t ha t t heperiodogra m is computed a t a finite number of frequency sa mples.

0 100 200 300 400 500−80

−70

−60

−50

−40

−30

−20

−10

0

Frequency (Hz)

P o w e r

S p e c t r a

l D e n s i t y

( d B / H z )

Periodogram PSD Estimate

Page 137: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 137/798

3 Statistical Signal Processing

−50

−40

−30

−20

−10

0

o w e r

S p e c t r a

l D e n s i t y

( d B / H z )

Periodogram PSD Estimate

Page 138: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 138/798

3-16

The a bove discussion a bout resolut ion did not consider t he effect s of noise sinceth e signal-to-noise ra tio (SNR) ha s been rela tively high t hus fa r. When t heSNR is low, t rue spectra l fea tures a re much ha rder to dist inguish, a nd noisea rtifacts a ppea r in spectral estimat es based on t he periodogra m. The examplebelow il lustra tes t his.

randn('state',0)fs = 1000; % Sampling frequencyt = (0:fs/10)./fs; % One-tenth of a second worth of samples

A = [1 2]; % Sinusoid amplitudesf = [150;140]; % Sinusoid frequenciesxn = A*sin(2*pi*f*t) + 2*randn(size(t));periodogram(xn,[],1024,fs);

0 100 200 300 400 500−70

−60

Frequency (Hz)

P

Spectral A nalysis

−40

−35

−30

−25

−20

−15

−10

−5

o w e r

S p e c t r a

l D e n s i t y

( d B / H z )

Periodogram PSD Estimate

Page 139: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 139/798

3-17

Bias of the Periodogram . The periodogra m is a biased estimator of the P SD. I tsexpected va lue ca n be shown to be

w hich is similar t o the first expression for X L (f ) in “Spectral Leaka ge” onpage 3-12 , except th a t t he expression here is in terms of a verag e power ra th ertha n ma gnitude. This suggests t ha t t he est ima tes produced by theperiodogram correspond to a leaky PSD ra the r than the t rue PSD.

Note tha t essentia l ly yields a tr ia ngular B a rtlet t window (wh ichis apparent from t he fact t ha t the convolution of tw o recta ngular pulses is atr ian gula r pulse). This results in a height for t he lar gest sidelobes of th e lea kypower spectra tha t is a bout 27 dB below the ma inlobe peak; i .e ., about tw ice thefrequency sepa ra tion relat ive to the n on-squa red recta ngular window.

The periodogra m is a symptotica lly unbiased, w hich is evident from th e ea rlierobserva tion tha t a s th e dat a record length t ends to infinity, the frequencyresponse of the recta ngula r w indow more closely approxima tes th e Dira c deltafunction (a lso tr ue for a B a rt lett w indow). However, in some ca ses theperiodogra m is a poor est ima tor of the P SD even w hen th e dat a record is long.This is due t o the va ria nce of th e periodogra m, a s expla ined below .

0 100 200 300 400 500−55

−50

−45

Frequency (Hz)

P

E X L f ( )2

f s L-------------------- 1

f s L-------- P x x ρ( )W R f ρ–( )2 ρd

f s 2 ⁄ –

f s 2 ⁄

∫ =

W R f ρ–( )2

3 Statistical Signal Processing

Variance of the Periodogra m. The va ria nce of th e periodogra m can be shown t o beapproximately

wh ich indica tes tha t t he varian ce does not t end to zero a s the da ta length L tends t o infinity. In st a tist ical terms, t he periodogra m is not a consistentestima tor of th e PS D. Nevertheless, the periodogra m can be a useful tool forspectral estima tion in si tua tions where the S NR is high, a nd especially if thedata record is long.

v a r X L f ( )

2

f s L-------------------- P x x

2f ( ) 1 2 πL f f s ⁄ ( )sin

L 2πf f s ⁄ ( )sin------------------------------------ 2

+≈

Page 140: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 140/798

3-18

The M odified Periodogra mThe m odi fi ed per iodogr am w indows t he time-domain sign a l prior to comput ingth e FFT in order to smooth t he edges of the signa l. This ha s t he effect ofreducing th e height of the sidelobes or spectra l leaka ge. This phenomenongives rise to the int erpreta tion of sidelobes as spurious frequencies intr oducedinto the signal by the abrupt truncat ion tha t occurs wh en a recta ngularwindow is used. For nonrecta ngular windows, th e end points of the tr uncat edsignal a re a tt enuat ed smoothly, a nd hence the spurious frequencies int roduceda re much less severe. On the other ha nd, nonrecta ngular windows a lso broad enth e mainlobe, w hich results in a net reduction of resolut ion.

The periodogram function a llow s you t o compute a modified periodogra m byspecifying the w indow t o be used on t he da ta . For exa mple, compa re arecta ngular w indow a nd a H amming window.

randn('state',0)

fs = 1000; % Sampling frequencyt = (0:fs/10)./fs; % One-tenth of a second worth of samples

A = [1 2]; % Sinusoid amplitudesf = [150;140]; % Sinusoid frequenciesxn = A*sin(2*pi*f*t) + 0.1*randn(size(t));periodogram(xn,rectwin(length(xn)),1024,fs);

Spectral A nalysis

−60

−50

−40

−30

−20

−10

0

P o w e r

S p e c t r a

l D e n s i t y

( d B / H z )

Periodogram PSD Estimate

Page 141: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 141/798

3-19

periodogram(xn,hamming(length(xn)),1024,fs);

You can verify tha t a lthough t he sidelobes are much less evident in th eHa mming-windowed periodogra m, the tw o main peaks a re wider. In fa ct , t he3 dB width of the mainlobe corresponding to a Ha mming window isa pproximately tw ice tha t of a recta ngular w indow. H ence, for a f ixed dat alength , the P SD resolut ion a t ta inable wi th a Ha mming window is

0 100 200 300 400 500−80

−70

Frequency (Hz)

0 100 200 300 400 500−80

−70

−60

−50

−40

−30

−20

−10

0

Frequency (Hz)

P o w e r

S p

e c t r a

l D e n s i t y

( d B / H z )

Periodogram PSD Estimate

3 Statistical Signal Processing

a pproximat ely ha lf tha t a t t a inable with a rectan gular w indow. The competinginterest s of mainlobe width a nd sidelobe height ca n be resolved to some extentby using variable windows such a s the Ka iser w indow.

Nonrecta ngular windowing a ffects the a verage power of a signal beca use someof the t ime samples a re a tt enuat ed when mu ltiplied by t he window. Tocompensa te for th is, the periodogram function norma lizes the w indow to ha vea n a verag e pow er of unity . This w a y th e choice of wind ow does not a ffect t hea vera ge power of the signa l.

The modified periodogra m estima te of the P SD is

2

Page 142: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 142/798

3-20

where U is the window normalizat ion consta nt

w hich is independent of the choice of window. The a ddition of U a s anormalizat ion consta nt ensures t ha t the m odified periodogra m isa symptotically un biased.

W elch’s M ethodAn improved estima tor of th e P SD is t he one proposed by Welch [8] . Themethod consists of dividing th e time series da ta into (possibly overlapping)

segments, computin g a modified periodogra m of ea ch segment , an d th ena vera ging the P SD estimat es. The result is Welch’s P SD estimat e.

Welch’s meth od is implement ed in th e Signa l P rocessing Toolbox by th e pwelch function. By default , th e da ta is divided into eight segments wit h 50%overla pbetw een them. A H a mming w indow is used to compute t he modifiedperiodogra m of each segment .

The a vera ging of modified periodogra ms t ends t o decrease th e varia nce of th e

estimat e rela t ive to a single periodogra m estima te of the entire dat a record.Although overla p betw een segments t ends to int roduce redunda nt informa tion,th is effect is diminished by th e use of a n onrecta ngula r w indow, wh ich reduces

P ˆ x x f ( ) X L f ( )f s L U

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

U 1L---- w n ( )2

n 0=

L 1–

∑=

Spectral A nalysis

th e import a nce or weight given to the end sa mples of segments (the sa mplestha t overla p).

H owever, a s mentioned above, th e combined use of short da ta records a ndnonrecta ngular windows r esults in reduced resolution of the estima tor. Insumma ry, th ere is a tra deoff betw een va riance reduction an d resolution. Onecan ma nipulat e the para meters in Welch’s method to obta in improvedestima tes rela tive to the periodogram , especially w hen t he SNR is low. This isillustra ted in th e followin g example.

Consider a n origina l signa l consist ing of 301 sa mples.

randn('state',1)

Page 143: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 143/798

3-21

fs = 1000; % Sampling frequencyt = (0:0.3*fs)./fs; % 301 samples

A = [2 8]; % Sinusoid amplitudes (row vector)f = [150;140]; % Sinusoid frequencies (column vector)xn = A*sin(2*pi*f*t) + 5*randn(size(t));periodogram(xn,rectwin(length(xn)),1024,fs);

0 100 200 300 400 500−60

−50

−40

−30

−20

−10

0

10

Frequency (Hz)

P o w e r S p e c t r a

l D e n s i t y

( d B / H z )

Periodogram PSD Estimate

3 Statistical Signal Processing

We can obta in Welch’s spectr a l estima te for 3 segments w ith 50%overlap w ith

pwelch(xn,rectwin(150),75,512,fs);

10

−5

0

5

10

t a

l D e n s i t y

( d B / H z )

Welch PSD Estimate

Page 144: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 144/798

3-22

In t he periodogra m a bove, noise and t he leaka ge make one of the sinusoidsessentia l ly indist inguisha ble from the a rt if icial peaks. In contr a st , a l thoughth e PS D produced by Welch’s meth od ha s w ider pea ks, you can st ill distin guishth e tw o sinusoids, which sta nd out from th e “noise floor.”

How ever, if we tr y to reduce th e varia nce furt her, th e loss of resolution causesone of th e sinusoids to be lost a ltogether.

pwelch(xn,hamming(100),75,512,fs);

0 100 200 300 400 500−25

−20

−15

−10

Frequency (Hz)

P o w e r

S p e c t r

Spectral A nalysis

−15

−10

−5

0

5

P o w e r

S p e c t r a

l D e n s i t y

( d B / H z )

Welch PSD Estimate

Page 145: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 145/798

3-23

For a more deta iled discussion of Welch’s method of PS D est ima tion, seeKa y [2] a nd Welch [8] .

Bias and N orma liza tion in W elch’s M ethodWelch’s method yields a biased est ima tor of the P SD . The expected va lue ca nbe found t o be

where L s is the length of the da ta segments a nd U is the sam e norma liza tionconst a nt present in th e definition of the modified periodogram . As is th e ca sefor all periodogra ms, Welch’s estima tor is a symptotically un biased. For a fixedlength da ta record, the bias of Welch’s est imat e is lar ger tha n t ha t of theperiodogram beca use L s < L .

The va ria nce of Welch’s estim a tor is difficult to comput e beca use it d epends onboth the w indow used and the a mount of overla p betw een segments. Ba sica lly,th e varia nce is inversely proport iona l to the number of segment s w hosemodified periodogram s a re being a vera ged.

0 100 200 300 400 500−20

−15

Frequency (Hz)

E P ˆ

w e l c h 1f s L s U ---------------- P x x ρ( )W f ρ–( )2 ρd

f s 2 ⁄ –

f s 2 ⁄

∫ =

3 Statistical Signal Processing

Multi taper MethodThe periodogra m can be int erpreted a s filtering a length L signal, x L [n ],th rough a filter ban k (a set of filters in par a llel) of L FI R ban dpa ss filters. The3 dB bandw idth of each of these band pass fi lters ca n be shown to bea pproximat ely equal t o f s / L . The ma gnit ude response of each one of th esebandpa ss fi lters resembles t ha t of the rectan gular window discussed in“Spectra l Leaka ge” on pa ge 3-12 . The periodogram can th us be view ed as acomputa tion of th e pow er of each filtered signa l (i.e., th e output of eachbandpa ss f i l ter) tha t uses just one sa mple of each fi l tered signa l a nd a ssumestha t the PSD of x L [n ] is consta nt over the ban dwidt h of ea ch bandpa ss f i lter.

As th e length of the signa l increases, the ban dwidt h of each bandpa ss f i lterd ki it l ti filt d i i t h i t i

Page 146: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 146/798

3-24

decrea ses, making it a more selective filter, an d improving t he a pproximat ionof const a nt P SD over th e bandw idth of the filter. This provides anoth erinterpreta tion of why the P SD estimat e of the periodogra m improves as t helength of the signal increases. However, there a re tw o factors a ppa rent fromthis st a ndpoint tha t compromise the a ccura cy of th e periodogra m estima te.First , t he recta ngular window y ields a poor ba ndpass f i l ter. Second, th ecomputa tion of th e power at th e output of each ban dpass filter relies on a singlesa mple of th e output signa l, producing a very crude approximat ion.

Welch’s meth od ca n be given a simila r int erpreta tion in terms of a filter ban k.In Welch’s implementa tion, several sa mples are used t o compute t he outputpower, result ing in reduced varia nce of the est ima te. On the other ha nd, th ebandw idth of ea ch bandpass f i l ter is larger th a n th a t corresponding to theperiodogra m met hod, wh ich result s in a loss of resolution. The filter ba nkmodel th us provides a new interpreta tion of th e compromise betw een varia nceand resolution.

Thompson’s mu lt i taper m ethod (MTM) builds on t hese result s t o provide a nimproved PSD estimat e. Inst ead of using ba ndpass f i l ters tha t a re essential lyrecta ngula r w indows (as in t he periodogra m meth od), the MTM meth od uses aba nk of optima l band pass filters t o compute t he estima te. These optima l FIRfilters a re derived from a set of sequences know n a s di screte pr olat e spher oida l sequ en ces (DP SS s, also known a s Sl epi an sequ ences ).

In a ddit ion, th e MTM method provides a t ime-bandw idth pa ra meter with

which to balance the variance and resolution. This parameter is given by thetime-bandwidth product, N W a nd i t is directly rela ted to th e number of ta persused to compute th e spectrum. There a re a lwa ys 2 *N W -1 ta pers used t o formthe est imat e. This mea ns tha t , a s N W increases, there a re more estima tes of

Spectral A nalysis

the power spectrum, a nd t he var iance of th e estimat e decreases. However, th eband widt h of ea ch ta per is a lso proportional t o N W , so a s N W increases, eachestima te exhibits more spectr a l lea ka ge (i.e., wider peaks) a nd t he overa ll

spectral estima te is more biased. For each dat a set , there is usually a value forN W tha t a l lows a n optima l tra de-off between bia s an d varia nce.

The S igna l P rocessing Toolbox function t ha t implement s t he MTM met hod iscalled pmtm. Use pmtm to compute the P SD of xn from th e previous exa mples.

randn('state',0)fs = 1000; % Sampling frequencyt = (0:fs)/fs; % One second worth of samples

A = [1 2]; % Sinusoid amplitudesf f

Page 147: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 147/798

3-25

A [1 2]; % Sinusoid amplitudesf = [150;140]; % Sinusoid frequenciesxn = A*sin(2*pi*f*t) + 0.1*randn(size(t));

[P,F] = pmtm(xn,4,1024,fs);plot(F,10*log10(P)) % Plot in dB/Hzxlabel('Frequency (Hz)');ylabel('Power Spectral Density (dB/Hz)');

0 100 200 300 400 500−55

−50

−45

−40

−35

−30

−25

−20

−15

−10

−5

Frequency (Hz)

P o w e r

S p e c t r a

l D e n s i t y

( d B / H z )

3 Statistical Signal Processing

B y lowering t he t ime-bandw idth product, you can increase th e resolution a t theexpense of lar ger va ria nce.

[P1,f] = pmtm(xn,3/2,1024,fs);plot(f,10*log10(P1)) % Plot in dB/Hzxlabel('Frequency (Hz)');ylabel('Power Spectral Density (dB/Hz)');

−20

−10

0

d B / H

z )

Page 148: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 148/798

3-26

Note tha t t he avera ge power is conserved in both ca ses.

Pow = (fs/1024) * sum(P)

Pow =

2.4926

Pow1 = (fs/1024) * sum(P1)

Pow1 =

2.4927

This met hod is more computa tiona lly expensive tha n Welch’s method due t o

th e cost of computing t he discrete prolat e spheroida l sequences. For long da taseries (10,000 points or more), it is useful t o compute t he DP SS s once a nd sa vet hem in a MAT-file. The M-files dpsssave , dpssload , dpssdir , and dpssclear a re provided to keep a da ta ba se of saved D P SS s in th e MAT-file dpss.mat .

0 100 200 300 400 500−80

−70

−60

−50

−40

−30

Frequency (Hz)

P o w e r

S p e c t r a

l D e n s i t y

( d

Spectral A nalysis

Cross-Spectra l D ensity FunctionThe P SD is a special case of the cross spectr al densit y (CSD) function, definedbetween two signals x n a nd y n a s

As is t he case for th e correlat ion a nd covaria nce sequences, the t oolboxestimates the P SD a nd CSD because signal lengths a re finite.

To estima te th e cross-spectr a l density of tw o equa l lengt h signa ls x a nd y usingWelch’s meth od, th e csd function forms t he periodogra m a s th e product of the

S x y ω( ) R x y m ( ) e j ωm –

m ∞–=

∑=

Page 149: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 149/798

3-27

, p g pFF T of x a nd t he conjugat e of th e FFT of y . Un like the real-valued P SD, t heCS D is a complex function. csd ha ndles the sectioning a nd w indowing of x a ndy in the same wa y as the pwelch function.

Sxy = csd(x,y,nfft,fs,window,numoverlap)

Confidence Intervals

You can compute confidence int erva ls using t he csd function by including a na ddit iona l input argument p th a t specifies t he percenta ge of the confidenceinterval , a nd se t t ing the numoverlap a rgument to 0.

[Sxy,Sxyc,f] = csd(x,y,nfft,fs,window,0,p)

p must be a scala r betw een 0 a nd 1. This function assum es chi-squa reddistr ibuted periodogra ms of the nonoverlapping sections of w indowed da ta incomputing t he confidence interva ls. This a ssumption is valid w hen th e signal

is a G aussia n distr ibuted ra ndom process. P rovided th ese a ssumptions a recorrect, t he confidence interva l

[Sxy-Sxyc(:,1) Sxy+Sxyc(:,2)]

covers t he true CS D with probabil ity p . If y ou set numoverlap to any valueother tha n 0 , you genera te a w a rning indica ting th a t t he sections overlap andth e confidence int erval is n ot reliable.

3 Statistical Signal Processing

Transfer Function EstimateOne a pplicat ion of Welch’s meth od is nonpara metric syst em identificat ion.Assume tha t H is a l inea r, t ime invaria nt system, and x (n ) a nd y (n ) a re the

input to a nd output of H , respectively. Then t he power spectr um of x (n ) isrela ted to the CSD of x (n ) a nd y (n ) by

An estimate of the transfer function between x (n ) a nd y (n ) is

S x y ω( ) H ω( ) S x x ω( )=

H ˆ ω( )

S ˆ

x y ω( )

S ˆ

x x ω( )

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

Page 150: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 150/798

3-28

This method estimates both magnitude and phase information. The tfe function uses Welch’s method to compute the CS D a nd power spectr um, a ndthen forms their quotient for t he tra nsfer function est ima te. Use tfe the samewa y tha t you use the csd function.

Fil ter the signa l xn wit h a n FIR fi l ter, then plot t he actua l magnitude responsea nd t he est imat ed 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)');

ω

Spectral A nalysis

0 100 200 300 400 5000

0.2

0.4

0.6

0.8

1Actual Transfer Function Magnitude

0.2

0.4

0.6

0.8

1Transfer Function Magnitude Estimate

Page 151: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 151/798

3-29

Coherence FunctionThe ma gnitu de-squa red coherence betw een tw o signa ls x (n ) a nd y (n ) is

This quotient is a real num ber betw een 0 a nd 1 th a t measures th e correlat ionbetween x (n ) a nd y (n ) a t t he frequency ω.

The cohere function ta kes sequences x a nd y , comput es th eir pow er spectr aan d CSD , and re turns the quot ient of the magni tude squared of the CSD andthe product of the power spectra. I ts options a nd opera tion ar e similar to the

csd a nd tfe functions.The coherence function of xn a nd t he fil ter output yn versus frequency is

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

0 100 200 300 400 5000

Frequency (Hz)

C x y ω( )S x y ω( ) 2

S x x ω( ) S y y ω( )-----------------------------------=

3 Statistical Signal Processing

If th e input sequ ence length nfft , window length window , an d th e number of

overla pping da ta points in a window numoverlap, are such tha t cohere opera tes on only a single record, the fun ction r eturn s a ll ones. This is because

0 50 100 150 200 250 300 350 400 450 5000

0.2

0.4

0.6

0.8

1

Frequency

C o h e r e n c e F u

n c t i o n E s t i m a t e

Coherence Function

Page 152: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 152/798

3-30

p y gth e coherence function for linea rly dependent da ta is one.

Parametric MethodsP ar a metric methods can yield higher resolutions t ha n nonpara metric methodsin cases w hen th e signal length is short. These methods use a differenta pproach to spectral estima tion; instea d of trying to estimat e the P SD directlyfrom the da ta , they model the da ta a s the output of a l inea r system driven bywh ite noise, and th en at tempt to estima te the para meters of tha t l inea rsystem.

The most commonly us ed linear syst em model is the al l-pol e m odel , a f i lterwith a ll of i ts zeroes at the origin in t he z -pla ne. The outpu t of such a filter forw hite n oise input is a n a ut oregressive (AR) process. For this rea son, thesemethods a re sometimes referred to a s AR m eth ods of spectral estimation.

The AR methods t end to a dequat ely describe spectra of data tha t is “pea ky,”tha t is , data whose P SD is large at certa in frequencies. The dat a in ma nypra ctica l applica tions (such a s speech) tend s to ha ve “peaky spectra ” so tha t ARmodels a re often useful. In a ddit ion, th e AR models lead t o a syst em of linearequa tions w hich is relat ively simple to solve.

The Signal Processing Toolbox offers the following AR methods for spectralest imation:

• Yule-Walker AR method (autocorrelation method)• B urg method

Spectral A nalysis

• Covarian ce method• Modified cova ria nce method

All AR methods yield a P SD estima te given by

The different AR methods estima te th e AR par a meters a p (k ) slightlydifferent ly, yielding different P SD estima tes. The followin g ta ble provides asumma ry of th e different AR methods.

P ˆ

A R f ( ) 1f s ----

εp

1 a p k ( )e 2 π j k f – f s ⁄

p

∑+

2-------------------------------------------------------------------=

Page 153: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 153/798

3-31

Burg Covariance Modified Covariance Yule-Walker

Characteristics Does not a pplywindow to dat a

Does not a pplywindow to dat a

Does not a pplywindow to dat a

Applies window tod a t a

Minimizes th eforward andbackwa rd predictionerrors in the leastsquares sense, withthe AR coefficientsconstr ained to sat isfythe L-D recursion

Minimizes th eforwa rd predictionerror in the leastsquares sense

Minimizes th eforward andbackwa rd predictionerrors in the leastsquares sense

Minimizes th eforwar d predictionerror in the leastsquares sense(also called“Autocorrelationmethod”)

Advantages High resolution forshort data records

Better resolut ion tha nY-W for short datarecords (moreaccurate estimates)

High resolution forshort data records

Performs a s well asother meth ods forlarge data records

Always produces asta ble model

Able to extra ctfrequencies from da taconsist ing of p or morepure sinusoids

Able to extra ctfrequencies from dat aconsist ing of p or morepure sinusoids

Always produces asta ble model

Does not sufferspectral line-splitting

3 Statistical Signal Processing

Disadvantages Pea k locat ions highlydependent on init ialphase

May produce unsta blemodels

May produce unsta blemodels

Performs relat ivelypoorly for short da tarecords

May suffer spectra lline-splitt ing forsinusoids in noise, orwhen order is verylarge

Frequency bias forestimat es of sinusoidsin noise

Pea k locationsslightly dependent onini t ial phase

Frequency bias forestimat es of sinusoidsin noise

Frequency bias forestimat es of sinusoidsin noise

Minor frequency bia sfor estimat es ofsinusoids in noise

Burg Covariance Modified Covariance Yule-Walker

Page 154: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 154/798

3-32

Yule-Walker AR MethodThe Yul e-Walker AR m eth od of spectr a l estima tion comput es the ARpara meters by forming a biased est imat e of th e signal’s a utocorrelat ionfunction, a nd solving th e least squa res minimizat ion of th e forwa rd predictionerror. This results in the Yule-Walker equations

The use of a bia sed estima te of th e aut ocorrelat ion function ensures th a t t hea utocorrela tion ma tr ix above is positive definite. H ence, the ma tr ix isinvertible and a solution is gua ra nt eed to exist. Moreover, the AR par a metersth us computed a lwa ys r esult in a sta ble all-pole model. The Yule-Wa lkerequa tions can be solved efficiently via L evinson’s algorithm, w hich ta kesadvantage of the Toeplitz structure of the autocorrelation matrix.

The toolbox function pyulear implements the Yule-Walker AR method.

Conditions forNonsingularity

Order must be lesstha n or equal to halfthe input frame size

Order must be lessth an or equa l to 2/3the input fra me size

B ecause of the biasedest imate, theautocorrelationmat rix is guaran teedto positive-definite,hence nonsingular

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

*

r 2( ) r 1( ) L r p 1–( )*M O O M

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

a 2( )

a 3( )M

a p 1+( )

r 2( )–

r 3( )–M

r p 1+( )–

=

Spectral A nalysis

For example, compare the spectrum of a speech signal using Welch’s methodand the Yule-Walker AR method.

load mtlb[P1,f] = pwelch(mtlb,hamming(256),128,1024,fs);[P2,f] = pyulear(mtlb,14,1024,fs);plot(f,10*log10(P1),':',f,10*log10(P2)); gridylabel('PSD Estimates (dB/Hz)');xlabel('Frequency (Hz)');legend('Welch','Yule-Walker AR')

20

−10

WelchYule−Walker AR

Page 155: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 155/798

3-33

The solid-line Yule-Wa lker AR spectru m is sm oot her t ha n t he periodogra m

becaus e of th e simple underly ing a ll-pole model.

Burg M ethodThe B urg met hod for AR spectr a l estima tion is based on minimizing th eforwa rd a nd backwa rd prediction errors w hile sat isfying the L evinson-Durbinrecursion (see Marple [3] , Chap ter 7, and P roak i s [6] , S ection 12.3.3). Incontra st t o other AR estima tion methods, the B urg method avoids ca lculat ingth e aut ocorrela tion function, a nd inst ead est ima tes th e reflection coefficients

directly.The primar y a dva nt a ges of the B urg meth od are resolving closely spa cedsinusoids in signals w ith low n oise levels, and estimat ing short da ta records, in

0 100 200 300 400 500 600−70

−60

−50

−40

−30

−20

P S D E s t i m a

t e s

( d B / H z )

Frequency (Hz)

3 Statistical Signal Processing

w hich ca se the AR pow er spectra l density estima tes a re very close to th e truevalues. In a ddit ion, the B urg method ensures a sta ble AR model an d iscomput a tiona lly efficient.

The a ccura cy of th e B urg m ethod is lower for high-order models, long da tarecords, a nd h igh signa l-to-noise rat ios (wh ich ca n ca use l i ne sp l i t t i ng , or th egenera tion of extra neous peaks in t he spectr um estima te). The spectr a l densityestima te comput ed by the B urg met hod is also susceptible to frequency shifts(relat ive to the tr ue frequency) resulting fr om the initia l pha se of noisysinusoidal signa ls. This effect is ma gnified wh en a na lyzing short da tasequences.

The toolbox function pburg implements t he Bur g method. Compare t hespectrum of the speech signa l genera ted by both th e Bur g method a nd t heYule Wa lker AR m ethod They a re very simila r for la rge signa l length s

Page 156: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 156/798

3-34

Yule-Wa lker AR m ethod. They a re very simila r for la rge signa l length s.

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 100 200 300 400 500 600−80

−70

−60

−50

−40

−30

−20

−10

M a g n

i t u d e

( d B )

Frequency (Hz)

BurgYule−Walker AR

Spectral A nalysis

Compare the spectrum of a noisy signal computed using the B urg method a ndthe Welch method.

randn('state',0)fs = 1000; % Sampling frequencyt = (0:fs)/fs; % One second worth of samples

A = [1 2]; % Sinusoid amplitudesf = [150;140]; % Sinusoid frequenciesxn = A*sin(2*pi*f*t) + 0.1*randn(size(t));

[P1,f] = pwelch(xn,hamming(256),128,1024,fs);[P2,f] = pburg(xn,14,1024,fs);

plot(f,10*log10(P1),':',f,10*log10(P2)); gridylabel('PSD Estimates (dB/Hz)');

Page 157: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 157/798

3-35

y ( ( ) );xlabel('Frequency (Hz)');legend('Welch','Burg')

Note tha t, a s the model order for the Bu rg meth od is reduced, a frequency shiftdue to the initia l phase of th e sinusoids will become appa rent .

0 100 200 300 400 500 600−60

−50

−40

−30

−20

−10

0

P S D E s t i m a

t e s

( d B / H z )

Frequency (Hz)

WelchBurg

Page 158: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 158/798

Spectral A nalysis

Both of these methods are frequency estimator techniques based oneigenanalysis of the autocorrelation matrix. This type of spectral analysiscategorizes the informa tion in a correlat ion or dat a ma trix, assigning

informa tion to either a signa l subspace or a noise subspa ce.

Eigenana lysis O verviewConsider a number of complex sinusoids embedded in w hite n oise. You ca nwr ite the aut ocorrelation mat rix R for th is system as t he sum of the signala utocorrelation ma trix ( S ) and the noise autocorrelation matrix ( W ).

There is a close relat ionship betw een the eigenvectors of th e signa la ut ocorrelat ion ma tr ix and t he signa l an d noise subspa ces. The eigenvectors v

f h i l b h i l If h i

R S W +=

Page 159: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 159/798

3-37

of S span t he same signa l subspa ce as the signa l vectors. If the system conta insM complex sinusoids an d th e order of the au tocorrela tion ma tr ix is p ,eigenvectors v M + 1 through v p + 1 spa n t he noise subspa ce of th e aut ocorrelat ionmatr ix .

Frequency Estimator Functions. To genera te th eir frequency estima tes,

eigena na lysis methods ca lcula te functions of the vectors in the signa l and n oisesubspaces. Both t he MUS IC a nd E V techniques choose a function t ha t goes toinfinity (denomina tor goes to zero) a t one of th e sinusoidal frequencies in th einput signal. U sing digita l technology, the result ing estimat e has sha rp pea ksa t t he frequencies of interest; t his means t ha t t here might n ot be infinityva lues in the vectors.

The MUS IC est ima te is given by th e formula

where N is th e size of th e eigenvectors a nd e (f ) is a vector of complex sinu soids.

v represent s th e eigenvectors of the input signa l’s correla tion ma tr ix; v k i s thek t h eigenvector. H is t he conjugat e tr a nspose operat or. The eigenvectors u sed

P music f ( ) 1

e H f ( ) v k v k H

k p 1+=

N

e f ( )

---------------------------------------------------------------- 1

v k H e f ( ) 2

k p 1+=

N

∑-------------------------------------------= =

e f ( ) 1 exp j 2 πf ( ) exp j 2 πf 2⋅( ) exp j 2 πf 4⋅( ) …exp j 2 πf n 1–( )⋅( )[ ]H =

3 Statistical Signal Processing

in th e sum correspond t o th e smallest eigenvalues a nd spa n t he noise subspace(p is th e size of th e signa l subspa ce).

The expression is equiva lent to a Fourier tr a nsform (th e vector e (f )consist s of complex exponentia ls). This form is u seful for num eric comput a tionbeca use th e FF T can be computed for each v k and then the squared magni tudescan be summed.

The EV method w eights t he summa tion by th e eigenvalues of the correlat ionmatr ix .

v k H e f ( )

P ev f ( ) 1

v k H e f ( ) 2

k 1+

N

∑ λk ⁄

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

Page 160: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 160/798

3-38

The pmusic a nd peig functions in t his t oolbox use th e svd (singular valuedecomposition) function in th e signa l case a nd t he eig function for a na lyzingthe correlation matrix and assigning eigenvectors to the signal or noisesubspa ces. When svd is used, pmusic a nd peig never comput e th e correla tionma trix explicit ly, but the singular values a re the eigenva lues.

k p 1+=

Selected Bibliography

Selected Bibliography[1] H a yes, M.H. Stat is t ica l Di gi ta l Signal Processin g and M odel i ng . New York:

J ohn Wiley & Son s, 1996.[2] Ka y, S .M. M odern Spectr a l Est im at ion . Englewood Cliffs, NJ : P rentice Ha ll,1988.

[3] Ma rple, S.L. Di gi ta l Spectr a l An alysis . Englewood Cliffs, NJ : P rentice Ha ll ,1987.

[4] Orfa nidis, S.J . I nt r odu cti on to Signal Pr ocessin g . Upper Saddle River, NJ :P rent ice Ha ll, 1996.

[5] P erciva l, D.B ., a nd A.T. Wa lden. Spectr al An alysis for Physical Appl i cat ions: M ul t i t aper and Convent i onal U ni var i a te Techni ques . Ca mbridge:

Page 161: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 161/798

3-39

pp p q gCambridge University Press, 1993.

[6] P roakis, J .G., an d D.G . Manolakis. Di gital Signal Processin g: Pr in cipl es,Al gor i thm s, and Appl icat ions . En glewood Cliffs, NJ : P rent ice Ha ll, 1996.

[7] St oica, P ., a nd R. Moses. I nt r oduct ion to Spectr a l Anal ysis . Upper Sa ddle

River, NJ : P rentice Ha ll, 1997.[8] Welch, P .D. “The U se of Fas t Fourier Tra nsform for th e Est ima tion of P owerSpectr a : A Method B a sed on Time Avera ging Over Sh ort, ModifiedPeriodograms.” I EE E Tr ans. Aud io El ect r oacoust . Vol. AU -15 (J un e 1967).P gs. 70-73.

3 Statistical Signal Processing

Page 162: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 162/798

3-40

4

S pecia l TopicsOverview . . . . . . . . . . . . . . . . . . . . . 4-2

Windows . . . . . . . . . . . . . . . . . . . . . . 4-3B a sic Sh a pes . . . . . . . . . . . . . . . . . . . . 4-3G eneralized Cosine Windows . . . . . . . . . . . . . . 4-5Ka iser Window . . . . . . . . . . . . . . . . . . . 4-6Chebyshev Window . . . . . . . . . . . . . . . . . . 4-10

Page 163: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 163/798

Parametric Modeling . . . . . . . . . . . . . . . . 4-12Time-Doma in B a sed Modeling . . . . . . . . . . . . . 4-14Frequ ency-Doma in B a sed Modeling . . . . . . . . . . . 4-19

Resampling . . . . . . . . . . . . . . . . . . . . 4-22

Cepstrum Analysis . . . . . . . . . . . . . . . . . 4-25Inverse Complex Cepstru m . . . . . . . . . . . . . . 4-27

FFT-Based Time-Frequency Analysis . . . . . . . . . 4-29

Median Filtering . . . . . . . . . . . . . . . . . . 4-30

Communications Applications . . . . . . . . . . . . 4-31

Deconvolution . . . . . . . . . . . . . . . . . . . 4-35

Specialized Transforms . . . . . . . . . . . . . . . 4-36Chir p z-Tra nsform . . . . . . . . . . . . . . . . . . 4-36Discrete Cosine Tra nsform . . . . . . . . . . . . . . . 4-38Hilbert Tra nsform . . . . . . . . . . . . . . . . . . 4-40

Selected Bibliography . . . . . . . . . . . . . . . 4-42

4 Special Topics

OverviewThe Sign a l P rocessing Toolbox provides functions t ha t a llow you to a pply a

va riety of signa l processing t echniqu es. The following sections describe how t ouse some of these functions:

• “Windows”• “P ar a metric Modeling”• “Resampling”• “Cepstrum Analysis”• “FFT-Based Time-Frequency Analysis”• “Median Fil tering”• “Communicat ions Applica tions”

Page 164: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 164/798

4-2

• “Deconvolution”• “Specialized Tra nsforms”• “Selected Bibliography”

W indows

WindowsIn both d igita l filter design a nd power spectr um estima tion, the choice of a

windowing function can play a n importa nt role in determining the qua li ty ofovera ll results. The ma in role of th e wind ow is to da mp out t he effects of theG ibbs phenomenon t ha t results from t runcat ion of a n infinite series.

The toolbox wind ow functions a re shown in th e ta ble below .

Window Function

Ba rt let t -Ha nn w indow barthannwin

Ba rt let t w indow bartlett

Bla ckman window blackman

Page 165: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 165/798

4-3

Basic ShapesThe ba sic w indow is t he rectangul ar w in dow , a vector of ones of the a ppropriat elength . A recta ngula r w indow of length 50 is

n = 50;

Bla ckman window blackman

B lackman-ha rris window blackmanharris

Bohman window bohmanwin

Chebyshev window chebwin

G aussian window gausswin

Ha mming window hamming

Ha nn window hann

Ka iser w indow kaiser

Nutt a ll’s B lackman-ha rris w indow nuttallwin

Recta ngular w indow rectwin

Ta pered cosine w indow tukeywin

Triangula r window triang

4 Special Topics

w = rectwin(n);

This t oolbox st ores w indows in column vectors by convent ion, so a n equ ivalentexpression is

w = ones(50,1);

The Bart le t t (or t r iangula r) window is the convolution of tw o recta ngula rw indows. The functions bartlett a nd triang compute simila r tr iangula rwindows, with three important differences. The bartlett function alwaysreturns a window w ith t wo zeros on the ends of the sequence, so tha t for n odd,the center section of bartlett(n+2) is equivalent t o triang(n) .

bartlett(7)ans =

Page 166: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 166/798

4-4

00.33330.66671.00000.6667

0.33330

triang(5)

ans =

0.33330.6667

1.00000.66670.3333

For n even, bartlett is still th e convolution of two recta ngula r sequences.There is no stand a rd definit ion for t he tr ia ngular window for n even; th e slopesof th e line segment s of the triang result a re sl ightly st eeper t ha n t hose ofbartlett in this case.

w = bartlett(8);[w(2:7) triang(6)]

ans =

W indows

0.2857 0.16670.5714 0.50000.8571 0.83330.8571 0.83330.5714 0.50000.2857 0.1667

The fina l difference betw een t he Ba rtlet t an d tr ia ngular windows is evident inth e Fourier tra nsforms of these functions. The Fourier tra nsform of a B a rt lettwindow is negative for n even. The Fourier tra nsform of a tr ia ngular window,however, is alw ay s nonnega tive.

This difference ca n be import a nt w hen choosing a w indow for some spectr a lestima tion techniques, such as t he B lackma n-Tukey method. Bla ckman-Tukeyforms t he spectral estima te by calcula ting t he Fourier t ra nsform of thea ut ocorrelat ion sequence. The resulting estima te might be nega tive at some

Page 167: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 167/798

4-5

q g g gfrequencies if the w indow’s Fourier tr a nsform is nega tive (see Kay [1] , pg. 80).

Generalized Cosine WindowsB lackman, Ha mming, Han n, and rectan gular w indows a re al l special ca ses of

t he general i zed cosin e wi nd ow . These wind ows a re combina tions of sinusoida lsequences wit h frequencies 0, , a nd , w here N i s thewindow length. One wa y to generat e them is

ind = (0:n-1)'*2*pi/(n-1);w = A - B*cos(ind) + C*cos(2*ind);

where A , B, and C a re const a nt s you define. The concept behind t hese wind owsis tha t by summing the individual terms t o form t he window, th e low frequency

peaks in th e frequency domain combine in such a w a y a s to decrea se sidelobeheight. This ha s th e side effect of increasing t he ma inlobe widt h.

The Ha mming a nd H a nn w indows a re tw o-term generalized cosine windows,given by A = 0.54 , B = 0.46 for Ha mming and A = 0.5 , B = 0.5 for Ha nn ( C = 0 in bot h ca ses). The hamming a nd hann functions, respectively, compute thesewindows.

Note tha t t he definition of th e genera lized cosine window sh own in th e ea rlier

MATLAB code yields zeros a t sa mples 1 a nd n for A = 0.5 a nd B = 0.5 .The Bla ckma n w indow is a popular th ree-term w indow, given by A = 0.42 ,B = 0.5 , C = 0.08 . The blackman function computes th is window .

2 π N 1–( ) ⁄ 4 π N 1–( ) ⁄

4 Special Topics

Kaiser WindowThe Kai ser w in dow is an a pproximat ion t o th e prolat e-spheroida l window , forw hich th e ra tio of th e ma inlobe energy t o the sidelobe energy is ma ximized. For

a K a iser window of a part icular length, the para meter β controls the sidelobeheight. For a given β, the sidelobe height is fixed wit h respect t o window lengt h.The sta tement kaiser(n,beta) comput es a length n Kaiser window withparameter beta .

Exa mples of Ka iser w indows with length 50 a nd va rious values for th e beta para meter are

n = 50;

w1 = kaiser(n,1);w2 = kaiser(n,4);w3 = kaiser(n,9);[W1,f] = freqz(w1/sum(w1),1,512,2);

Page 168: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 168/798

4-6

[W1,f] freqz(w1/sum(w1),1,512,2);[W2,f] = freqz(w2/sum(w2),1,512,2);[W3,f] = freqz(w3/sum(w3),1,512,2);plot(f,20*log10(abs([W1 W2 W3]))); grid;legend('beta = 1','beta = 4','beta = 9',3)title('Three Kaiser Window Responses')xlabel('Normalized Frequency (Nyquist = 1)')ylabel('Normalized Magnitude (dB)')

0 0.2 0.4 0.6 0.8 1−180

−160

−140

−120

−100

−80

−60

−40

−20

0Three Kaiser Window Responses

Normalized Frequency (Nyquist = 1)

N o r m a

l i z e d M a g n

i t u d e

( d B )

beta = 1beta = 4beta = 9

W indows

As β increases, the sidelobe height decreases a nd th e mainlobe w idth increa ses.To see how th e sidelobe height st a ys t he sa me for a fixed β parameter as thelength is varied, try

w1 = kaiser(50,4);w2 = kaiser(20,4);w3 = kaiser(101,4);[W1,f] = freqz(w1/sum(w1),1,512,2);[W2,f] = freqz(w2/sum(w2),1,512,2);[W3,f] = freqz(w3/sum(w3),1,512,2);plot(f,20*log10(abs([W1 W2 W3]))); grid;legend('length = 50','length = 20','length = 101')

title('Three Kaiser Window Responses, Beta Fixed')xlabel('Normalized Frequency (Nyquist = 1)')ylabel('Normalized Magnitude (dB)')

Page 169: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 169/798

4-7

0 0.2 0.4 0.6 0.8 1−120

−100

−80

−60

−40

−20

0

20Three Kaiser Window Responses, Beta Fixed

Normalized Frequency (Nyquist = 1)

N o r m a

l i z e d M a g n

i t u d e

( d B )

length = 50length = 20length = 101

4Special Topics

Ka iser W indow s in FIR DesignThere are t wo design formula s tha t can help you design FIR filters t o meet aset of filter specifica tions using a Ka iser w indow. To achieve a sidelobe height

of −αdB, the beta parameter is

For a tra nsit ion width of ∆ωra d/s, use th e length

Filters designed using th ese heuristics will meet t he specifica tions

β0.1102 α 8.7–( ), α 50>0.5842 α 21–( )0.4 0.07886 α 21–( )+ , 50 α 21≥ ≥0, α 21<

=

n α 8–2.285 ω∆----------------------- 1+=

Page 170: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 170/798

4-8

a pproxima tely, but you should verify this. To design a lowpa ss filter w ith cut offfrequency ra d/s, tra nsit ion widt h ra d/s, a nd 40 dB of at tenua tion inthe stopba nd, try

[n,wn,beta] = kaiserord([0.4 0.6]*pi,[1 0],[0.01 0.01],2*pi);

h = fir1(n,wn,kaiser(n+1,beta),'noscale');

The kaiserord function estima tes th e filter order, cutoff frequency, and K a iserwindow beta para meter needed to meet a given set of frequency doma inspecifications.

The ripple in th e pa ssba nd is roughly the sa me as t he ripple in th e stopba nd.As you can see from the frequency response, th is filter near ly meets t hespecifications.

[H,f] = freqz(h,1,512,2);plot(f,20*log10(abs(H))), grid

0.5 π 0.2 π

W indows

-80

-60

-40

-20

0

20

M a g n

i t u d e

( d B )

FIR Design using Kaiser Window

0.240 dB

Page 171: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 171/798

4-9

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

Normalized Frequency (Nyquist == 1)

4Special Topics

Chebyshev WindowThe Chebyshev window minimizes the mainlobe width, given a particularsidelobe height . It is char a cterized by a n equiripple beha vior, tha t is, its

sidelobes all ha ve the sa me height. The chebwin function, with length a ndsidelobe height parameters, computes a Chebyshev window.

n = 51;Rs = 40; % Sidelobe height in decibelsw = chebwin(n,Rs);stem(w); title('Length 51 Chebyshev Window');xlabel('Sample Number');

0 6

0.8

1Length 51 Chebyshev Window

Page 172: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 172/798

4-10

As shown in the plot , t he Chebyshev window ha s lar ge spikes a t i t s outersa mples. P lot t he frequency response to see the equiripples at -40 dB .

[W,f] = freqz(w,1,512,2);plot(f,20*log10(abs(W)/sum(w))), gridtitle('Chebyshev Window Magnitude Response');xlabel('Normalized Frequency (Nyquist = 1)');

ylabel('Normalized Magnitude (dB)');

0 5 10 15 20 25 30 35 40 45 500

0.2

0.4

0.6

Sample Number

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

-60

-40

-20

0

Normalized Frequency (Nyquist == 1)

N o r m

a i l z e d M a g n i t u d e ( d B )

Chebyshev Window Magnitude Response

W indows

For a deta iled discussion of th e cha ra cteristics and a pplicat ions of th e va riouswindow types, see Oppenheim and Schafer [2], pgs. 444-462, a nd P a rks a ndBur rus [3] , pgs. 71-73.

Page 173: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 173/798

4-11

4Special Topics

Parametric ModelingP ar a metric modeling techniques find th e pa ra meters for a ma thema tical modeldescribing a signa l, system, or process. These techniques us e knowninformat ion a bout th e system t o determine the model. Applicat ions forpar a metric modeling include speech a nd music synt hesis, dat a compression,high-resolution spectral estimation, communications, manufacturing, andsimulation.

The toolbox para metric modeling functions opera te w ith t he ra tiona l tra nsferfunction model. Given a ppropriate informat ion a bout a n un known system(impulse or frequency response dat a , or input a nd output sequences), these

functions find the coefficients of a linear sy stem t ha t models the system.One important application of the parametric modeling functions is in thedesign of filters t ha t ha ve a prescribed time or frequency response. Thesefunctions provide a da ta -oriented alterna tive to the IIR a nd F IR fil ter design

Page 174: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 174/798

4-12

functions provide a da ta oriented alterna tive to the IIR a nd F IR fi l ter designfunctions discussed in Cha pter 2, “Fil ter Design.”

Parametric M odeling

H ere is a s umma ry of the par a metric modeling functions in this t oolbox. Noteth a t th e Sy stem Ident ifica tion Toolbox provides a more extensive collection ofparametric modeling functions.

Domain Functions Description

Time arburg G enera te a ll-pole filter coefficients t ha t model an input da tasequence using t he Levinson-Durbin a lgorith m.

arcov G enera te a ll-pole filter coefficients t ha t model an input da tasequence by minimizing th e forw a rd prediction error.

armcov G enera te a ll-pole filter coefficients t ha t model an input da tasequence by minimizing the forward and backward predictionerrors.

aryule G enera te a ll-pole filter coefficients t ha t model an input da ta

Page 175: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 175/798

4-13

Because yulewalk is gear ed explicitly t owa rd ARMA filter design, it isdiscussed in Cha pter 2, “Fil ter Design.” pburg a nd pyulear a re discussed inCha pter 3, “Sta t i s t ica l Signal P rocess ing,” a long with the other(nonparametric) spectral estimation methods.

aryule G enera te a ll pole filter coefficients t ha t model an input da tasequence using a n estima te of th e aut ocorrelat ion function.

lpc ,levinson

Linea r P redictive Coding. Genera te a ll-pole recursive filter w hoseimpulse response ma tches a given sequence.

prony G enera te IIR filter w hose impulse response ma tches a givensequence.

stmcb Find I IR filter w hose output , given a specified input sequence,ma tches a given output s equence.

Frequency invfreqz ,invfreqs

G enera te digit a l or a na log filter coefficients given complexfrequency response data.

4 Special Topics

Time-Domain Based ModelingThe lpc , prony , and stmcb functions find the coefficients of a digita l rat iona ltransfer function that approximates a given time-domain impulse response.

The a lgorithms differ in complexity a nd a ccura cy of th e resulting model.

Linear PredictionLinear prediction modeling a ssumes tha t each output sa mple of a signa l, x(k) ,is a linear combina tion of the past n outputs ( that is , it can be “l inearlypredicted” from these outputs), an d th a t t he coefficients a re consta nt fromsa mple to sam ple.

An n t h-order a ll-pole model of a signa l x is

a = lpc(x,n)

x k ( ) a 2( ) x k 1–( )– a 3( ) x k 2–( )–…

– a n 1+( ) x k n –( )–=

Page 176: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 176/798

4-14

To illustr a te lpc , crea te a sa mple signal th a t is the impulse response of a na ll-pole filter w ith a dditive w hite noise.

randn('state',0);

x = impz(1,[1 0.1 0.1 0.1 0.1],10) + randn(10,1)/10;The coefficient s for a fourt h-order a ll-pole filter th a t models t he syst em a re

a = lpc(x,4)

a =1.0000 0.2574 0.1666 0.1203 0.2598

lpc first calls xcorr to find a biased estima te of the correlat ion function of x ,a nd t hen uses th e Levinson-Dur bin recursion, implement ed in the levinson function, to find the model coefficients a . The Levin son-Du rbin r ecursion is afa st a lgorith m for solving a sy stem of symmetric Toeplitz linea r equa tions.lpc ’s ent ire a lgorith m for n = 4 is

r = xcorr(x);r(1:length(x)-1) = []; % Remove corr. at negative lagsa = levinson(r,4)

a =1.0000 0.2574 0.1666 0.1203 0.2598

Parametric M odeling

You could form t he linear prediction coefficients w ith other a ssumpt ions bypassing a different correlation estimat e to levinson , such a s the biasedcorrelation estimate.

r = xcorr(x,'biased');r(1:length(x)-1) = []; % Remove corr. at negative lagsa = levinson(r,4)

a =1.0000 0.2574 0.1666 0.1203 0.2598

Prony’s M ethod (ARM A M odeling)

The prony function models a signa l using a specified nu mber of poles an d zeros.G iven a sequence x a nd numerat or an d denominat or orders n a nd m,respectively, the statement

[b,a] = prony(x,n,m)

Page 177: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 177/798

4-15

finds the n umerat or a nd d enominat or coefficients of an IIR fi lter w hoseimpulse response approxima tes t he sequence x .

The prony function implements th e method described in [3] Pa rks and Bur rus(pgs. 226-228). This met hod uses a va ria tion of th e covar ia nce meth od of ARmodeling t o find t he denomina tor coefficients a , and t hen finds the numerat orcoefficients b for which t he resulting filter ’s impulse response ma tches exactlythe first n + 1 sa mples of x . The filter is not necessa rily sta ble, but it canpotent ia lly recover t he coefficients exa ctly if the da ta sequence is truly a nautoregressive moving average (ARMA) process of the correct order.

Note The fu nct ions prony a nd stmcb (described next) a re more a ccura telydescribed a s ARX models in syst em ident ifica tion t erminology. ARMAmodeling a ssumes noise only a t t he inputs, while ARX assumes a n externa linput. prony a nd stmcb know th e input signa l: it is a n impulse for prony a ndis arbitra ry for stmcb .

4 Special Topics

A model for t he t est sequ ence x (from th e ear lier lpc example) using ath ird-order IIR filter is

[b,a] = prony(x,3,3)

b =0.9567 -0.3351 0.1866 -0.3782

a =1.0000 -0.0716 0.2560 -0.2752

The impz comma nd sh ows how w ell th is filter ’s impulse response ma tches th eorigina l sequence.

format long[x impz(b,a,10)]

ans =

Page 178: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 178/798

4-16

0.95674351884718 0.95674351884718-0.26655843782381 -0.26655843782381-0.07746676935252 -0.07746676935252-0.05223235796415 -0.05223235796415-0.18754713506815 -0.05726777015121

0.15348154656430 -0.012049699261500.13986742016521 -0.000576327972260.00609257234067 -0.012716815706870.03349954614087 -0.004079670538630.01086719328209 0.00280486049427

Notice th a t t he first four sa mples ma tch exactly. For an example of exa ct

recovery, recover th e coefficients of a B utt erwort h filter fr om its impulseresponse.

[b,a] = butter(4,.2);h = impz(b,a,26);[bb,aa] = prony(h,4,4);

Try t his exa mple; you’ll see tha t bb a nd aa ma tch t he original filter coefficientsto wit hin a toleran ce of 10 -13 .

Parametric M odeling

Steiglitz-M cBride M ethod (ARM A M odeling)The stmcb function determin es th e coefficient s for th e syst em b (z )/a (z ) given a na pproximat e impulse response x , as w ell a s th e desired number of zeros a ndpoles. This function identifies an un known sys tem ba sed on both input a ndoutput sequences tha t d escribe the syst em’s beha vior, or just th e impulseresponse of the syst em. In its defa ult mode, stmcb works like prony.

[b,a] = stmcb(x,3,3)

b =0.9567 -0.5181 0.5702 -0.5471

a =

1.0000 -0.2384 0.5234 -0.3065

stmcb a lso finds systems tha t ma tch given input a nd output sequences.

y = filter(1,[1 1],x); % Create an output signal.[b ] t b( 0 1)

Page 179: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 179/798

4-17

[b,a] = stmcb(y,x,0,1)

b =1.0000

a =1 1

In this example, stmcb correctly identifies the syst em used to crea te y from x .

The Steiglitz-McBride method is a fast iterative algorithm that solves for thenumerat or a nd denominator coefficients simultaneously in a n a tt empt tominimize the signa l error betw een the filter output a nd t he given outputsigna l. This a lgorith m usua lly converges ra pidly, but m ight not converge if themodel order is t oo la rge. As for prony , stmcb ’s resultin g filter is not necessa rilysta ble due to its exact m odeling approach.

stmcb provides control over severa l import a nt a lgorith mic pa ra meters; modifythese para meters if you a re ha ving trouble modeling the da ta . To cha nge thenumber of itera tions from the default of five and provide a n initia l estima te forth e denomina tor coefficients

n = 10; % Number of iterationsa = lpc(x,3); % Initial estimates for denominator[b,a] = stmcb(x,3,3,n,a);

4 Special Topics

The function uses a n a ll-pole model creat ed w ith prony as a n in it ia l est imat ew hen you do not provide one of your own .

To compa re t he fun ctions lpc , prony , and stmcb , comput e the signa l error in

each case.a1 = lpc(x,3);[b2,a2] = prony(x,3,3);[b3,a3] = stmcb(x,3,3);[x-impz(1,a1,10) x-impz(b2,a2,10) x-impz(b3,a3,10)]

ans =

-0.0433 0 -0.0000-0.0240 0 0.0234-0.0040 0 -0.0778-0.0448 -0.0000 0.0498-0.2130 -0.1303 -0.0742

0 1545 0 1655 0 1270

Page 180: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 180/798

4-18

0.1545 0.1655 0.12700.1426 0.1404 0.10550.0068 0.0188 0.04650.0329 0.0376 0.05300.0108 0.0081 -0.0162

sum(ans.^2)

ans =

0.0953 0.0659 0.0471

In comparing m odeling ca pabilities for a given order II R model, th e last result

shows tha t for this exa mple, stmcb performs best , followed by prony , then lpc .This rela tive performa nce is typical of t he modeling functions.

Parametric M odeling

Frequency-Domain Based ModelingThe invfreqs a nd invfreqz functions implement th e inverse operat ions offreqs a nd freqz ; they find a n a na log or digita l tra nsfer function of a specified

order th a t ma tches a given complex frequency response. Though t he follow ingexa mples demonstra te invfreqz , th e discussion a lso a pplies to invfreqs .

To recover th e origin a l filter coefficients fr om th e frequen cy response of asimple digita l filter

[b,a] = butter(4,0.4) % Design Butterworth lowpass

b =0.0466 0.1863 0.2795 0.1863 0.0466

a =1.0000 -0.7821 0.6800 -0.1827 0.0301

[h,w] = freqz(b,a,64); % Compute frequency response[bb aa] = invfreqz(h w 4 4) % Model: n = 4 m = 4

Page 181: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 181/798

4-19

[bb,aa] = invfreqz(h,w,4,4) % Model: n = 4, m = 4

bb =

0.0466 0.1863 0.2795 0.1863 0.0466aa =

1.0000 -0.7821 0.6800 -0.1827 0.0301

The v ector of freq uencies w ha s the unit s in ra d/sa mple, a nd t he frequenciesneed not be equa lly spaced. invfreqz finds a f i lter of any order to fi t th efrequency data; a third-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 a nd invfreqz design filters w ith rea l coefficients; for a da tapoint a t positive frequency f , the functions fit t he frequency response a t both f a nd -f .

4 Special Topics

By defaul t invfreqz uses an equ a tion error method to ident ify the best modelfrom t he da ta . This f inds b a nd a in

by crea ting a syst em of linea r equa tions a nd solving t hem wit h MATLAB ’s \ operator. Here A (w (k )) a nd B (w (k )) a re the Fourier tra nsforms of th epolynomials a a nd b respectively a t t he frequency w (k ), a nd n is th e number offrequency points (th e length of h a nd w). w t (k ) weight s th e error relat ive to theerror at different frequencies. The synt a x

invfreqz(h,w,n,m,wt)

includes a w eighting vector. In th is mode, the filter resulting from invfreqz isnot guara nteed to be stable.

invfreqz provides a superior (“output error”) a lgorith m t ha t solves th e direct

minb a , w t k ( ) h k ( ) A w k ( )( ) B w k ( )( )– 2

k 1=

n

Page 182: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 182/798

4-20

invfreqz provides a superior ( output -error ) a lgorith m t ha t solves th e directproblem of minimizing th e weighted sum of the squ a red error betw een thea ctua l frequency response points a nd t he desired response

To use this a lgorith m, specify a pa ra meter for the itera tion count a fter t heweight vector para meter

wt = ones(size(w)); % Create unity weighting vector[bbb,aaa] = invfreqz(h,w,3,3,wt,30) % 30 iterations

bbb =

0.0464 0.1829 0.2572 0.1549

aaa =

1.0000 -0.8664 0.6630 -0.1614

The resulting filter is always stable.

minb a ,

w t k ( ) h k ( ) B w k ( )( )A w k ( )( )--------------------–

2

k 1=

n

Parametric M odeling

G ra phica lly compare t he results of the first a nd second a lgorithms t o theoriginal B utt erworth fi lter.

[H1,w] = freqz(b,a);

[H2] = freqz(bb,aa);[H3] = freqz(bbb,aaa);s.plot = 'mag';s.xunits = 'rad/sample';s.yunits = 'linear';freqzplot([H1 H2 H3],w);legend('Original','First Estimate','Second Estimate',3);grid on

200

−100

0

100

a g n

i t u d e

( d B )

Original

Page 183: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 183/798

4-21

To verify t he superiority of the fit n umerically, t ypesum(abs(h-freqz(bb,aa,w)).^2) % Total error, algorithm 1

ans =

0.0200

sum(abs(h-freqz(bbb,aaa,w)).^2) % Total error, algorithm 2

ans =

0.0096

0 0.2 0.4 0.6 0.8 1−600

−400

−200

0

Normalized Frequency ( ×πrad/sample)

P h a s e

( d e g r e e s )

0 0.2 0.4 0.6 0.8 1−300

−200

Normalized Frequency ( ×πrad/sample)

M First EstimateSecond Estimate

4 Special Topics

ResamplingThe toolbox provides a nu mber of functions tha t r esam ple a signa l at a higheror lower ra te.

Operation Function

Apply FI R fi l ter w ith resampling upfirdn

Cubic spline interpolat ion spline

Decimation decimate

Interpolation interp

Oth er 1-D interpolat ion interp1

Resample a t new ra t e resample

Page 184: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 184/798

4-22

The resample function cha nges the sampling rat e for a sequence to any r a tetha t is a ra tio of tw o integers. The basic synta x for resample is

y = resample(x,p,q)

w here the function resamples the sequence x a t p/q t imes the origina lsa mpling ra te. The length of the result y is p/q times th e lengt h of x .

One resam pling applicat ion is t he conversion of digitized a udio signals fromone sam pling ra te to a nother, such a s from 48 kHz (the digita l a udio ta pesta nda rd) to 44.1 kH z (th e compact disc sta nda rd). In t he next exa mple, th esam pling rat es are different but the idea is the sa me.

The example file contains a length 4001 vector of speech sampled at 7418 Hz.

clearload mtlbwhos

Name Size Bytes Class

Fs 1x1 8 double arraymtlb 4001x1 32008 double array

Grand total is 4002 elements using 32016 bytes

Resampling

FsFs =

7418

To play t his speech signa l on a worksta tion tha t can only play sound at8192 Hz, use the rat function to find integers p a nd q th a t yield the correctresampling fa ctor.

[p,q] = rat(8192/Fs,0.0001)

p =127

q =115

Since p/q*Fs = 8192.05 Hz, th e toleran ce of 0.0001 is a ccepta ble; to resam pleth e signa l a t very close to 8192 Hz.

y = resample(mtlb,p,q);

Page 185: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 185/798

4-23

y esa p e( t b,p,q);

resample a pplies a lowpa ss filter to the input sequence to prevent a liasingduring resampling. I t designs this f i l ter using t he firls function with a Ka iserwindow. The synta x

resample(x,p,q,l,beta)

controls the f i lter ’s length a nd t he beta para meter of the Ka iser w indow.Alterna tively, use the function intfilt to design an in terpola tion filter b a nduse it w ith

resample(x,p,q,b)

The decimate a nd interp functions do the sa me thing a s resample wi th p = 1 a nd q = 1 , respectively. These functions provide different a nt i-a lias filteringoptions, a nd t hey incur a slight signa l delay due to filtering. The interp function is significa nt ly less efficient t ha n th e resample function with q = 1 .

The t oolbox a lso conta ins a function, upfirdn , tha t a pplies an FIR fi l ter to a ninput sequence a nd outputs th e f il tered sequence at a different sa mple rat etha n i ts original rat e. See “Multira te Fil ter Ba nk Implementa tion” on page

1-20 .The sta nda rd MATLAB environment cont a ins a function, spline , tha t worksw ith irregular ly spaced da ta . The MATLAB function interp1 performs

4 Special Topics

interpolat ion, or ta ble lookup, using va rious methods including linea r a ndcubic int erpola tion.

Page 186: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 186/798

4-24

C epstrum Analysis

Cepstrum AnalysisCepstrum a na lysis is a nonlinear signa l processing technique with a variety ofa pplicat ions in a rea s such as speech a nd ima ge processing. The Signa lP rocessing Toolbox provides t hree fun ctions for cepstru m a na lysis.

The complex cepst rum for a sequ ence x is calculat ed by finding t he complexna tura l logarit hm of the Fourier tra nsform of x , then t he inverse Fouriertransform of the resulting sequence.

Operation Function

Complex cepstrum cceps

Inverse complex cepstrum icceps

Real cepstrumrceps

Page 187: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 187/798

4-25

The toolbox function cceps performs t his opera tion, estima ting t he complexcepstrum for an input sequence. I t returns a real sequence the sa me size a s th einput sequence.

xhat = cceps(x)

The complex cepstru m tr a nsforma tion is centr a l to the th eory a nd a pplicat ionof hom omorp hi c system s , tha t is , systems th at obey certa in genera l rules of

superposition. See Oppenheim an d S chafer [2] for a discussion of th e complexcepstru m a nd homomorphic tra nsforma tions, wit h deta ils on speech processingapplications.

Try u sing cceps in a n echo detection applica tion. First , creat e a 45 Hz sinewa ve sa mpled a t 100 Hz.

t = 0:0.01:1.27;s1 = sin(2*pi*45*t);

x ˆ 12 π------ X e j ω( )[ ]log e j ωn ωd

π–

π∫ =

4 Special Topics

Add a n echo of the signa l, with h a lf the am plitude, 0.2 seconds aft er thebeginning of the signa l.

s2 = s1 + 0.5*[zeros(1,20) s1(1:108)];

The complex cepstrum of this n ew signa l is

c = cceps(s2);plot(t,c)

0

0.5

1

Page 188: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 188/798

4-26

Note tha t t he complex cepstru m shows a peak a t 0.2 seconds, indica ting t heecho.

The r eal cepstr um of a signa l x , sometimes ca lled simply t he cepstru m, iscalculat ed by determining the na tura l logar ithm of magnitud e of the Fouriertra nsform of x , then obta ining the inverse Fourier tra nsform of the r esult ingsequence.

0 0.2 0.4 0.6 0.8 1 1.2 1.4-1.5

-1

-0.5

c x 1

2 π------ X e j ω( )log e j ωn ωd

π–

π

∫ =

C epstrum Analysis

The toolbox function rceps performs t his operat ion, returning the r ealcepstru m for a sequence x . The retu rned sequ ence is a rea l-va lued vector t hesa me size a s th e input vector.

y = rceps(x)

B y definition, you ca nnot reconst ruct t he origina l sequence from its realcepstrum t ra nsforma tion, as th e rea l cepstrum is ba sed only on th e magnitudeof the Fourier tr a nsform for the sequence (see Oppenheim a nd S chafer [2]). Therceps function, however, ca n reconst ruct a minimum-pha se version of th eoriginal sequence by applying a w indowing fun ction in t he cepstra l domain. Toobta in both the rea l cepstrum a nd t he minimum phase reconstruction for asequence, use

[y,ym] = rceps(x)

where y is the real cepstrum a nd ym is the minimu m pha se reconstruct ion of x .

Inverse Complex Cepstrum

Page 189: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 189/798

4-27

To invert the complex cepstrum, use the icceps function. Inversion iscomplicated by the fact tha t t he cceps function performs a da ta dependent

phase modifica tion so that the unw ra pped pha se of i ts input is continuous atzero frequency. The pha se modificat ion is equ ivalent to a n int eger delay. Thisdelay term is return ed by cceps if you a sk for a second out put. For exam ple,

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.1386Columns 8 through 100.2327 0.4114 0.9249

nd =1

4 Special Topics

To invert t he complex cepst rum , use icceps wit h the original delay par a meter.

icceps(xh,nd)

ans =Columns 1 through 7

1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000Columns 8 through 10

8.0000 9.0000 10.0000

Note With a ny m odifica tion of the complex cepstrum, t he origina l delay t ermma y no longer be valid. Use th e icceps function with care.

Page 190: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 190/798

4-28

FFT-Based Ti me-Frequency A nalysis

FFT-Based Time-Frequency AnalysisThe Sig na l P rocessin g Toolbox provides a fu nction, specgram , tha t re turns thetime-dependent Fourier tra nsform for a sequence, or display s th is informa tion

as a spectrogram. The Toolbox also inclues a spectrogram demo. Thetime-dependent Fouri er t r ansform is th e discrete-time Fourier t ra nsform for asequence, computed using a sliding w indow. This form of the Fouriertr a nsform, also know n a s th e short-time Fourier tra nsform (STFT), ha snum erous a pplicat ions in speech, sonar , an d ra da r processing. Thespectrogram of a sequence is the ma gnitu de of th e time-dependent Fouriertra nsform versus t ime.

To display t he spectrogra m of a linea r 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)

Page 191: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 191/798

4-29

Note that the spectrogra m displa y is an image, not a plot .

Time

F r e q u e n c y

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.80

500

1000

1500

2000

2500

3000

3500

4000

4500

5000

4 Special Topics

Median FilteringThe function medfilt1 implement s one-dimensional m edian filtering, anonlinear technique that applies a sliding window to a sequence. The median

filter repla ces th e center value in the w indow with the median va lue of all th epoints w ithin t he window [4] . In computing t his median, medfilt1 assumeszeros beyond t he input points.

When t he nu mber of elements n in the w indow is even, medfilt1 sorts t henumbers, then t a kes the a verage of the (n-1)/2 a nd (n-1)/2 + 1 elements.

Two simple examples wit h fourth - a nd t hird-order median filters a re

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)

Page 192: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 192/798

4-30

ans =

3 4 3 5 8 8 1See the medfilt2 function in th e I m age Pr ocessi ng T ool box User ’s Gui de forinformat ion on tw o-dimensional media n filtering.

C ommunications A pplications

Communications ApplicationsThe toolbox provides three functions for communications simulation.

M odula t i on va ries the a mplitude, pha se, or frequency of a carr ier signal wi threference to a m essage sign al . The modulate function modulat es a messagesignal w ith a specified modulat ion method.

The basic synt a x for t he modulate function is

y = modulate(x,fc,fs,' method ',opt)

Operation Function

Modulation modulate

Demodulation demod

Volta ge cont rolled oscillat ion vco

Page 193: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 193/798

4-31

where :

• x is the message signal.• fc is the carrier frequency.• fs is the sampling frequency.• method is a fla g for th e desired modulat ion meth od.• opt is any a ddit iona l argument t ha t t he method requires. (Not a ll

modula tion methods require an option a rgument.)

The ta ble below summa rizes the modula tion meth ods provided; see thedocument a tion for modulate , demod , and vco for complete deta ils on each.

Method Description

amdsb-sc or am Amplitude modulat ion, double side-ba nd, suppressedcarrier

amdsb-tc Amplitude modulat ion, double side-ba nd, tr a nsmit tedcarrier

4 Special Topics

If th e input x i s an a rray ra ther than a vector, modulate modula tes ea chcolumn of the arra y.

To obta in th e time vector t ha t modulate uses to compute the modulat ed signal,specify a second output parameter.

[y,t] = modulate(x,fc,fs,' method ',opt)

amssb Amplitude m odulat ion, s ingle side-ba nd

fm Frequency modulationpm Phase modulation

ppm P ulse position modulat ion

pwm P ulse widt h modulat ion

qam Quadra ture am plitude modulat ion

Method Description

Page 194: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 194/798

4-32

The demod function performs demodulat ion , tha t is , it obtains th e original

message signal from the modulated signa l.The syn ta x for demod is

x = demod(y,fc,fs,' method ',opt)

demod uses an y of th e methods shown for modulate , but the synta x forqua dra ture a mplitude demodulat ion requires tw o output pa ra meters.

[X1,X2] = demod(y,fc,fs,'qam')

If th e input y i s an a r ray, demod demodulat es all columns .

Try modula ting a nd demodulat ing a signa l. A 50 Hz sine wa ve sa mpled a t1000 Hz is

t = (0:1/1000:2);x = sin(2*pi*50*t);

C ommunications A pplications

With a carrier frequency of 200 Hz, t he modula ted a nd d emodulat ed versionsof this signal a re

y = modulate(x,200,1000,'am');z = demod(y,200,1000,'am');

To plot portions of th e origina l, modula ted, a nd 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');

0 8

−0.6

−0.4

−0.2

0

0.2

0.4

0.6

0.8

1Original Signal

0 8

−0.6

−0.4

−0.2

0

0.2

0.4

0.6

0.8

1Modulated Signal

Page 195: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 195/798

4-33

Note The demodulated signal is attenuated because demodulation includestw o steps: multiplicat ion a nd lowpa ss filtering. The mult iplicat ion produces acomponent with frequency centered a t 0 Hz a nd a component w ith frequencya t tw ice th e ca rrier frequency. The filtering removes the high er frequencycomponent of th e signal, producing t he a tt enuat ed result .

0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16−1

−0.8

0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16−1

−0.8

0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16−0.8

−0.6

−0.4

−0.2

0

0.2

0.4

0.6Demodulated Signal

4 Special Topics

The volta ge contr olled oscilla tor fun ction vco crea tes a signa l tha t oscil la tes ata frequency determined by t he input vector. The ba sic synta x for vco is

y = vco(x,fc,fs)

where fc is the carrier frequency a nd fs is the sampling frequency.To sca le the frequency modulat ion ra nge, use

y = vco(x,[Fmin Fmax],fs)

In t his ca se, vco scales the frequency modulat ion ra nge so va lues of x on th einterval [-1 1] ma p to oscillat ions of frequency on [Fmin Fmax] .

If th e input x i s an a r ray, vco produces an array whose columns oscillatea ccording t o the columns of x .

S ee “FF T-B a sed Time-Fr equency Ana lysis” on pa ge 4-29 for a n exam ple usingt he vco function.

Page 196: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 196/798

4-34

Deconvolution

DeconvolutionDeconvolution , or polynomial division, is the inverse operation of convolution.Deconvolution is useful in recovering th e input t o a known filter, given t he

filtered output . This m ethod is very sensit ive to noise in t he coefficients,however, so use ca ut ion in a pplying it.

The syn ta x for deconv is

[q,r] = deconv(b,a)

where b is th e polynomial dividend, a is th e divisor, q is the quotient, a nd r isthe remainder.

To t ry deconv , first convolve t w o simple vectors a a nd b (see Chap ter 1, “S igna lProcessing Basics,” for a description of the convolution function).

a = [1 2 3];b = [4 5 6];c = conv(a,b)

c =

Page 197: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 197/798

4-35

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

4 Special Topics

Specialized TransformsIn a ddit ion t o the discrete Fourier tr a nsform (DF T) described in C h a p t er 1,“Signal P rocessing B a sics,” the Signal Processing Toolbox and the MATLAB

environment together provide the follow ing tr a nsform functions:• The chirp z -tr a nsform (CZT), useful in eva lua ting th e z -transform along

cont ours other t ha n t he unit circle. The chirp z -tr a nsform is a lso moreefficient t ha n t he DF T a lgorith m for the computa tion of prime-lengthtr a nsforms, a nd it is useful in computing a subset of the DFT for a sequence.

• The dis crete cosine tr a nsform (DC T), closely r elat ed t o th e DF T. The D CT’senergy compa ction properties a re useful for a pplica tions like signa l coding.

• The Hilbert tra nsform, w hich fa cil i tat es the forma tion of the a na lytic signa l.The an a lytic signal is useful in t he ar ea of communicat ions, par ticular ly inband pass signal processing.

Chirp z -TransformThe ch irp z -tr a nsform , or CZT, comput es the z -tr a nsform a long spira l contours

Page 198: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 198/798

4-36

in the z -plane for a n in put sequence. Unlike th e DF T, t he CZT is not

constra ined to opera te a long t he unit circle, but can eva luat e the z -transforma long cont ours described by

where A is the complex sta rt ing point, W is a complex sca lar describing th ecomplex ra tio between point s on the cont our, an d M is the length of thetransform.

One possible spiral 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.')

z l A W l – l 0 … M 1–, ,=,=

Specia lized Transforms

czt(x,M,W,A ) computes the z -tr a nsform of x on these points .

-1.5 -1 -0.5 0 0.5 1 1.5

-1

-0.5

0

0.5

1

Real part

I m a g

i n a r y p a r t

Page 199: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 199/798

4-37

An int eresting a nd useful spira l set is mevenly spa ced sa mples a round th e unit

circle, pa ra meterized by A = 1 a nd W = exp(-j*pi/M) . The z -tr a nsform on th iscont our is simply th e DFT, obta ined by

y = czt(x)

czt may be fas ter tha n the fft function for computing the DFT of sequencesw ith certa in odd length s, part icula rly long prime-length sequences.

4 Special Topics

Discrete Cosine TransformThe toolbox function dct computes t he unita ry discrete cosine tr a nsform, orDCT, for a n input vector or ma trix. Mat hemat ically, the unit a ry D CT of a ninput sequence x is

where

The DC T is closely rela ted t o the discrete Fourier tr a nsform; th e DFT isa ctua lly one step in th e comput a tion of the D CT for a sequence. The DC T,however ha s better energycom pacti on properties with just a few of the

y k ( ) w k ( ) x n ( ) π 2 n 1–( ) k 1–( )2 N

-------------------------------------------cos

n 1=∑ k 1 … N , ,=,=

w k ( )

1

N

--------- k 1=,

2N ---- 2 k N ≤ ≤,

=

Page 200: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 200/798

4-38

however, ha s better energy com pacti on properties, with just a few of thetr a nsform coefficients r epresent ing t he ma jority of th e energy in t he sequence.The energy compaction propert ies of t he DC T ma ke it us eful in a pplicat ionssuch a s dat a communications.

The function idct comput es the inverse D CT for a n input sequence,reconst ructing a signa l from a complete or pa rt ial set of DC T coefficients. Theinverse discrete cosine tr a nsform is

where

x n ( ) w n ( ) y k ( ) π 2 n 1–( ) k 1–( )2 N

------------------------------------------ -cos

k 1=∑n 1 … N , ,=,=

w n ( )

1N

--------- n 1=,

2

N ---- 2 n N ≤ ≤,

=

Specia lized Transforms

B eca use of the energy compa ction m entioned a bove, it is possible to reconst ructa signa l from only a fra ction of its DC T coefficients. F or exa mple, genera te a25 Hz sinusoidal sequence, sa mpled a t 1000 Hz.

t = (0:1/999:1);x = sin(2*pi*25*t);

Compute th e DCT of th is sequence a nd reconst ruct t he signa l using only th osecomponents w ith va lue great er th a n 0.1 (64 of th e origina l 1000 DC Tcoefficients).

y = dct(x) % Compute DCTy2 = find(abs(y) < 0.9); % Use 17 coefficientsy(y2) = zeros(size(y2)); % Zero out points < 0.9z = idct(y); % Reconstruct signal using inverse DCT

Plot the original and reconstructed sequences.

subplot(2,1,1); plot(t,x);title('Original Signal')subplot(2,1,2); plot(t,z), axis([0 1 -1 1])title('Reconstructed Signal')

Page 201: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 201/798

4-39

title( Reconstructed Signal )

0 0.2 0.4 0.6 0.8 1−1

−0.5

0

0.5

1Original Signal

0 0.2 0.4 0.6 0.8 1−1

−0.5

0

0.5

1 Reconstructed Signal

4 Special Topics

One measu re of th e accura cy of th e reconstru ction is

norm(x-z)/norm(x)

th a t is, the norm of th e difference betw een th e origina l an d reconstru cted

signals, divided by th e norm of th e original signa l. In t his case, the relat iveerror of reconstruction is 0.1443. The reconstructed signal retainsa pproxima tely 85%of th e energy in th e origina l signal.

Hilbert TransformThe toolbox function hilbert computes the H ilbert tra nsform for a real inputsequence x a nd return s a complex result of the sa me length

y = hilbert(x)

wh ere the real part of y i s the or ig inal rea l dat a and the imaginary par t i s thea ctua l Hilbert tra nsform. y is sometimes called t he analyt i c signal , in referenceto th e continuous-time a na lytic signa l. A key property of th e discrete-timeana lyt ic signal is tha t i t s z -tr a nsform is 0 on the low er ha lf of the unit circle.Man y a pplica tions of the a na lytic signa l ar e relat ed to this property; forexa mple the a na lytic signa l is useful in a voiding aliasing effects for ba ndpass

Page 202: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 202/798

4-40

exa mple, the a na lytic signa l is useful in a voiding aliasing effects for ba ndpasssa mpling operat ions. The ma gnit ude of the a na lytic signa l is the complexenvelope of t he original signa l.

The Hilbert tr an sform is rela ted to the actua l dat a by a 90° pha se shift ; s inesbecome cosines and vice versa. To plot a portion of data (solid line) and itsHilbert transform (dotted 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

Specia lized Transforms

The an a lytic signal is useful in calculat ing in stan tan eous attr ibu tes of a t imeseries, the at tr ibutes of the series at a ny point in t ime. The insta nta neousa mplitude of th e input sequ ence is the a mplitude of th e ana lytic signal. The

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 203: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 203/798

4-41

insta nta neous pha se angle of the input sequence is th e (unw ra pped) angle ofthe a na lytic signal; the insta nta neous frequency is the t ime ra te of cha nge ofthe insta nta neous phase a ngle. You can calcula te the insta nta neous frequencyusing th e MATLAB function, diff .

4 Special Topics

Selected Bibliography[1] Ka y, S .M. M odern Spectr a l Est im at ion . Englewood Cliffs, NJ : P rentice Ha ll ,1988.

[2] Oppenheim, A.V., a nd R.W. S cha fer. Di scr ete-Ti m e Si gnal Pr ocessi ng .En glewood Cliffs, NJ : P rentice Ha ll, 1989.

[3] P a rks, T.W., an d C .S. B urru s. Di gi ta l F i l ter D esign . New York: J ohn Wiley& Sons, 1987.

[4] P ra tt ,W.K. Di gital I m age Processin g . New York: J ohn Wiley & Sons , 1991.

Page 204: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 204/798

4-42

5Filt er D esign a nd Ana lysisTool

Overview . . . . . . . . . . . . . . . . . . . . . 5-2

Opening the Filter Design and Analysis Tool . . . . . 5-6

Choosing a Filter Type . . . . . . . . . . . . . . . 5-7

Choosing a Filter Design Method . . . . . . . . . . 5-8

Setting the Filter Design Specifications . . . . . . . 5-9

Computing the Filter Coefficients . . . . . . . . . . 5-12

Analyzing the Filter . . . . . . . . . . . . . . . . 5-13

Page 205: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 205/798

Converting the Filter Structure . . . . . . . . . . . 5-15

Importing a Filter Design . . . . . . . . . . . . . . 5-17

Exporting a Filter Design . . . . . . . . . . . . . . 5-21

Saving and Opening Filter Design Sessions . . . . . . 5-25

5 Filter Design and A nalysis Tool

Overview

Note The F ilter Design a nd Ana lysis Tool (FD ATool) requ ires r esolutiongrea t er t han 640 x 480.

The Filter Design and Analysis Tool (FDATool) is a pow erful user interfa ce fordesigning a nd a na lyzing filters. FDATool enables you to quickly design digita lFIR or IIR filters by s ett ing filter performa nce specifica tions, by import ingfilters from your MATLAB workspace, or by directly specifying filtercoefficients. FDATool also provides tools for analyzing filters, such as

ma gnit ude a nd pha se response plots a nd pole-zero plots. You ca n u se FD AToola s a convenient a lterna tive to the comma nd line filter design functions. Thischapt er conta ins the follow ing sections, which wa lk you through a t ypica l filterdesign s ession using th e FD ATool:

• “Opening t he Filter Design a nd Ana lysis Tool”• “Choosing a Filter Type”• “Choosing a Filter Type”

Page 206: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 206/798

5-2

Choosing a Filter Type• “Choosing a Filter Design Method”• “Setting the Filter Design Specifications”• “Computing t he Filter C oefficients”• “Ana lyzing t he Fil ter”• “Converting t he Fil ter St ructure”• “Importing a Fil ter Design”•

“Exporting a Fil ter Design”• “Sa ving a nd Opening F il ter D esign S essions”

B elow is a brief int roduction t o the FD ATool th a t w ill give you a betterundersta nding of how it can be used.

Note I f you ha ve ins ta l led external ha rdwa re or ta rgets tha t in teract w i thFD ATool, you ma y see a ddit iona l options in F DATool. Refer t o th e specificha rdwa re or t ar get ma nua l for informa tion on t hese options.

These t oolboxes/ta rget s a re int egra ted w ith FD ATool.Filt er D esign Toolbo x Developer's Kit for Texas In str ument s™ DS P

Filter Design MethodsThe t ool gives you a ccess to a ll of th e filter d esign methods in th e Signa lP rocessin g Toolbox:

• But terworth (butter )• Ch ebyshev Type I ( cheby1 )• Chebyshev Type II ( cheby2 )• Elliptic (ellip )

Page 207: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 207/798

5-3

• Eq uiripple ( remez )• Least squares (firls )• Windows

- Ba rt let t -Ha nning (barthannwin )- Ba r t l et t (bartlett )- Bla ckman (blackman )- Blackman-Harris ( blackmanharris )- Bohman (bohmanwin )- Chebyshev (chebwin )- Ga ussian (gausswin )- Ha mming (hamming )- H a n n (hann )- Ka iser (kaiser )- Nutt a ll’s Bla ckma n-Ha rris ( nuttallwin )- Rectangular ( rectwin )

5 Filter Design and A nalysis Tool

- Ta pered cosine ( tukeywin )- Trian gular ( triang )

You can implement a ny of these windows ma nua lly using fir1 or fir2 .

Additiona l filter design methods a re ava ilable to users of th e Filter DesignToolbox.

Using the Filter Design and Analysis ToolThere are different wa ys th at you ca n design fil ters using the Fil ter Design andAna lysis Tool. For exa mple:

• You can first choose a filter type, such as ba ndpa ss, an d th en choose from the

a vailable FIR or II R fi l ter design methods.• You can specify th e filter by it s ty pe alone, along wit h certa in frequency- or

time-domain specifications such as passband frequencies and stopbandfrequencies. The filter you design is t hen comput ed using t he defau lt filterdesign method a nd filter order.

Analyzing Filter Responses

Page 208: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 208/798

5-4

Once you ha ve designed your filter, you ca n a na lyze different filter responsesin F DATool or in a separa te F ilter Visualiza tion Tool ( fvtool ):

• Magnitude response ( freqz )• P ha se response ( freqz )• P ole-zero plots ( zplane )• Impulse r esponse ( impz )•

G roup dela y (grpdelay )• St ep response

You ca n a lso displa y t he filter coefficients, export th e coefficients to t heMATLAB w orkspace, a nd crea te a C hea der file cont a ining t he coefficients.

Filter Design and Analysis Tool ModesThe Filt er Design a nd Ana lysis Tool opera tes in tw o modes:

• Design mode . In t his mode, you ca n:

- Design filters from scra tch.- Modify existing filters designed by FDATool.- Ana lyze filters.

Im por t m ode . In t his mode, you ca n:- Import previously saved filters or filter coefficients t ha t y ou ha ve stored in

the MATLAB workspace.- Ana lyze import ed filters.

If you also ha ve the Filter D esign Toolbox insta lled th e add itiona l quant ize mode is ava ilable. Use t his mode to:

• Quantize double-precision filters that you design in FDATool.• Quantize double-precision filters that you import into FDATool.• Ana lyze qua ntized fi l ters.

Getting HelpAt a ny t ime, you can right -click or press t he What’s this? butt on, , to getinforma tion on th e different pa rts of the GU I.

Page 209: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 209/798

5-5

5 Filter Design and A nalysis Tool

Opening the Filter Design and Analysis ToolTo open the Filter Design and Analysis Tool, type

fdatool

The Filt er Design a nd Ana lysis Tool opens in th e defau lt design mode .

AnalysisZoomFull ViewAnalysis

“What’s Thishelp

DisplayRegion

Print andPrint Preview

(If Filter Design Toolbox is installed,a Quantization boxandQuantization

Page 210: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 210/798

5-6

Select filter

Select filterdesign method

Specify filter order or allowautomatic estimation

Compute filtercoefficients

Set filter specifications (depend onfilter type and design method)

Set specifications forFIR Windowmethod

Filter Parameters

and Quantizationtab appear here.)

C hoosing a Filter Type

Choosing a Filter TypeYou ca n choose from several filter ty pes:

• Lowpass• Highpass• Bandpass• Bands top• Differentiator• Hilbert tra nsformer• Multiband• Arbitrary magnitude• Arbitra ry group delay• Ra ised cosine

To design a ba ndpa ss filter, select t he ra dio butt on next t o Bandpass in theFilter Type region of the GU I.

Page 211: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 211/798

5-7

Note Not a ll filter design methods a re ava ilable for a ll filter ty pes. Once youchoose your filter t ype, th is may r estrict th e filter design methods ava ilable toyou. Fil ter design methods tha t a re not ava ilable for a selected fi l ter type aredimmed in th e Method menu, a nd removed from the Design Method regionof the GU I.

You can a lso use the Type menu t o select a filter type.

5 Filter Design and A nalysis Tool

Choosing a Filter Design MethodYou can use t he default filt er design method for t he filter type tha t you’veselected, or you ca n select a filter design method from the ava ilable FIR a nd II R

methods listed in the G UI .To select th e Remez a lgorith m t o compute F IR filter coefficients, select t he FIR radio button and choose Equiripple from the list of methods.

You can a lso use the Method menu t o select a filter design meth od.

Page 212: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 212/798

5-8

Setting the Filter Design Specifications

Setting the Filter Design SpecificationsThe filter design specifica tions th a t you can set va ry a ccording to filter ty pe anddesign method. For exam ple, to design a ba ndpa ss filter, you can ent er:

• B a ndpass Fil ter Frequency Specifications• B a ndpass F il ter Ma gnitude Specifications• Filter Order

The displa y region illustra tes filter specifica tions w hen you select FilterSpecifications from th e Analysis menu.

Page 213: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 213/798

5-9

Bandpass Filter Frequency SpecificationsFor a bandpa ss fi lter, you can set:

Units of frequency:- H z- kH z- MH z- Norma lized (0 to 1)

• Sa mpling frequency• P a ssband frequencies• Stopband frequencies

5 Filter Design and A nalysis Tool

You specify the pa ssba nd w ith t w o frequencies. The first frequency determ inesth e lower edge of th e pa ssba nd, a nd t he second frequency determin es the upperedge of the passband .

Simila rly, you specify th e stopband w ith tw o frequencies. The first frequ ency

determines t he upper edge of the first st opba nd, a nd t he second frequencydetermines t he lower edge of the second stopban d.

For this exam ple:

• Keep th e units in Hz (default).• Set t he sam pling frequency ( Fs ) t o 2000 H z.• Set t he end of the first stopba nd ( Fstop1 ) t o 200 H z.

• Set t he beginning of the passba nd ( Fpass1 ) t o 300 H z.• Set t he end of the pa ssband ( Fpass2 ) t o 700 H z.• Set t he beginning of the second st opban d ( Fstop2 ) t o 800 H z.

Page 214: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 214/798

5-10

Bandpass Filter Magnitude SpecificationsFor a ba ndpa ss filter, you can specify the follow ing ma gnitu de responsecharacterist ics:

• U nits for the ma gnitude response (dB or l inear)• P assband r ipple• Stopband a t tenuat ion

Setting the Filter Design Specifications

For this exam ple:

• Keep th e units in dB (default).• Set t he passban d ripple ( Apass ) t o 0.1 dB .•

Set th e stopband a tt enuat ion for both st opbands ( Astop1 , Astop2 ) t o 75 dB .

Filter OrderYou ha ve tw o mutua lly exclusive options for determ ining t he filter order w hen

d i i i l filt

Page 215: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 215/798

5-11

you design a n equiripple filter• Minimum order : The filter design met hod determines t he minimum order

filter.• Specify order : You ent er th e filter order in a text box.

Select th e Minimum order radio button for this example.

Note tha t filter order specifica tion options depend on the filter design meth odyou choose. Some filter met hods ma y not ha ve both options a va ilable.

5 Filter Design and A nalysis Tool

Computing the Filter CoefficientsNow t ha t you’ve specified the filter design, select th e Design Filter but ton t ocompute the filter coefficients.

Notice tha t th e Design Filter butt on is dimm ed once you’ve computed t hecoefficients for your filter design. This but ton is ena bled ag a in once you ma kea ny cha nges to the filter specifica tions.

Page 216: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 216/798

5-12

A nalyzing the Filter

Analyzing the FilterOnce you’ve designed th e filter, you can view t he following filter responsechara cterist ics in t he display r egion or in a sepa ra te window:

• Magnitude response• P ha se response• Overlaid ma gnitude a nd pha se responses• G roup dela y• Impulse r esponse• St ep response•

P ole-zero plotYou can a lso displa y t he filter coefficients in t his region.

You can a ccess the an a lysis methods as i tems in t he Analysis menu, or byusing the t oolbar but tons.

For exam ple to look at th e filter ’s ma gnitud e response select t he Magnitude

Page 217: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 217/798

5-13

For exam ple, to look at th e filter s ma gnitud e response, select t he MagnitudeResponse butt on on th e toolba r.

5 Filter Design and A nalysis Tool

To display t he filter response char a cteristics in a separ a te w indow, selectFull View Analysis from t he Analysis menu. The Filter Visualization Tool(fvtool ) opens. You can use th is tool to ann ota te your design, view oth er filtera na lyses, a nd print your fi l ter response.

Page 218: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 218/798

5-14

You can click on t he response to add a da ta ma rker tha t d isplays informat iona bout t he par ticular point on t he response. Right-clicking displays a menuwh ere you can a djust t he appeara nce of the da ta ma rkers or delete them.

C onverting the Filter Structure

Converting the Filter StructureYou can u se the Convert structure butt on to convert t he current filter to a new str ucture. All filters ca n be converted t o the follow ing representa tions:

• Direct form I• Direct form II• Direct form I transposed• Direct form II transposed• State-space• Lattice ARMA

Note If you ha ve insta lled t he Filter D esign Toolbox you will see a dditiona lstructures in the Convert structure dialog box.

In a ddition, the follow ing conversions are a va ilable for pa rt icula r cla sses offilters:

Minimum pha se FIR filters can be convert ed to Lattice MA (min. phase)

Page 219: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 219/798

5-15

p ( p )• Maximum pha se FIR fi l ters ca n be converted to Lattice MA (max. phase)• Allpass filters ca n be convert ed to Lattice allpass• II R filters can be convert ed to Lattice ARMA

Note Converting from one filter struct ure to an other ma y produce a result

w ith d ifferent cha ra cteristics tha n t he origina l. This is due to the computer ’sfinite-precision a rith metic a nd th e va ria tions in th e conversion’s round-offcomputations.

When selected, t he Use second-order sections check box inst ructs t he t ool tostore t he convert ed filter st ructure a s a collection of second-order sectionsra ther tha n a s a monoli thic higher-order st ructure. The subordina te Scale menu let s you select from th e follow ing options.

• None (default)

5 Filter Design and A nalysis Tool

• L-2 (L 2 norm)• L-infinity (L ∞ norm)

The orderin g of the second-order sections is optim ized for th e select ed sca lingoption. (The tf2sos function tha t performs th e conversion is called wit h option'down' for L 2 norm sca ling, and w ith option 'up' for L ∞ norm scaling.)

For exam ple:

• P ress the Convert structure butt on to open the Convert structure dialogbox.

• Select Direct form I in th e list of filter stru ctures.• Select t he Use second-order sections check box.• Select L-infinity from th e Scale menu for L ∞ norm scaling.

Page 220: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 220/798

5-16

Importing a Filter Design

Importing a Filter DesignThe Import Filter region a llows you to import a filter by specifying th e filtercoefficients, eith er by ent ering t hem explicitly or by r eferring to va ria bles inth e MATLAB w orkspa ce. You can a ccess t his r egion by selecting Import Filter from t he Filter menu, or by pressing Ctrl+I .

The import ed filter ca n be in an y of th e representa tions listed in th e FilterStructure menu, a nd described in “Fil ter St ructures” .

Select t he frequency units from a mong th e follow ing options in th e Units menu,a nd specify the va lue of th e sampling frequency in the Fs field.

To import th e filter, press th e Import Filter button. The Display Region is

a utomat ica lly upda ted w hen the new fi lter ha s been imported.

Page 221: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 221/798

5-17

5 Filter Design and A nalysis Tool

Filter Structures• Direct Form filters

- Direct form I- Direct form II- Direct form I transposed- Direct form II transposed- Direct form II (Second-order sections)

• State-space• Lat t ice filters

- Lattica allpass- Lattice MA min. phase- Lattice MA max. phase- Lattice ARMA

• Quantized filter (Qfilt object) — available only when Filter DesignToolbox is in st a lled

The str ucture th a t y ou choose determines t he ty pe of coefficients th a t y ou needto specify in th e text fields to the right .

Dire ct Form

Page 222: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 222/798

5-18

For Direct Form I , Direct Form II , Direct Form I transposed , and Direct Form II transposed , specify th e filter by its tra nsfer function representa tion:

• The Numerator field specifies a va ria ble na me or va lue for t he numera torcoefficient vector b , wh ich conta ins m+1 coefficient s in descendin g powers of z.

• The Denominator field specifies a va ria ble na me or va lue for th edenominator coefficient vector a , wh ich conta ins n+1 coefficient s indescending powers of z. For FIR fi l ters, the Denominator is 1 .

Filters in t ra nsfer function form can be produced by all of the Signa l Pr ocessingToolbox filt er design funct ions (such a s fir1 , fir2 , remez , butter , yulewalk ).S ee “Tra nsfer Fun ction” on pa ge 1-33 for more informa tion.

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 –+ + +---------------------------------------------------------------------------------------= =

Page 223: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 223/798

5 Filter Design and A nalysis Tool

• For Lattice allpass , the Lattice coeff field specifies th e lat tice (reflection)coefficients, k(1) t o k(N) , were N is th e filter order.

• For Lattice MA(minimum or ma ximum pha se), the Lattice coeff fieldspecifies t he la t tice (reflection) coefficient s, k(1) t o k(N) , were N is the filter

order.• For Lattice ARMA, the Lattice coeff field specifies the lattice (reflection)

coefficients, k(1) t o k(N) , and the Ladder coeff field specifies the laddercoefficients, v(1) t o v(N+1) , were N is th e filter order.

Filters in la tt ice form ca n be produced by tf2latc . See “Lat t ice Structure” onpa ge 1-38 for more informa tion.

Quantized Filter (Qfilt Object)For Quantized filter , specify th e filter a s a Qfilt object. S ee qfilt in th e FilterDesign Toolbox for more in forma tion.

Page 224: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 224/798

5-20

Exporting a Filter Design

Exporting a Filter DesignYou can sa ve your filter design by:

• Exporting Filter C oefficients t o the Workspace• Exporting Filter C oefficients t o a Text File • E xportin g t he filt er coefficient s t o a MAT-file (see Sa ving and Opening Filter

Design S essions )• Creating a C header file containing the coefficients

Exporting Filter Coefficients to the Workspace

To sa ve filter coefficients a s va ria bles in t he MATLAB w orkspa ce1 Select Export from t he File menu . The Export dia log box appear s.

2 Select Workspace from t he Export To menu.

3 Assign varia ble names using t he text boxes in th e Variable Names region.If you ha ve varia bles with t he same na mes in your workspace a nd you wa ntto overwr ite th em, check the Overwrite existing variables box.

4 P ress the OK button.

Page 225: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 225/798

5-21

5 Filter Design and A nalysis Tool

Exporting Filter Coefficients to a Text FileTo save filt er coefficient s t o a t ext file

1 Select Export from th e File menu . The Export dia log box appear s.

2 Select Text-file from th e Export To menu.

3 P ress the OK button. The Export Filter Coefficients to a Text-file dialogbox appears.

4 Choose a filename and press Save .

The coefficients a re sa ved in t he t ext file tha t you specified, a nd th e MATLAB

Ed itor opens to display th e file.

Exporting to a C Header FileYou ma y w a nt to include fil ter informa tion in an externa l C program. To creat ea C header f i le with va riables tha t conta in fil ter pa ra meter dat a , follow t hisprocedure:

1 Select Export to C Header File from t he File menu . The Export to CHeader File dia log box appear s.

Page 226: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 226/798

5-22

Exporting a Filter Design

2 En ter t he varia ble na mes to be used in the C hea der file. The part icula r filterstructure determines th e varia bles th a t a re creat ed in the fi le.

Filter Structure Variable Parameter

Direct Form I

Direct Form II

Direct Form I transposed

Direct Form I I tra nsposed

Numerat or, Numera tor length*,Denomina tor, D enominat or length*, an dNumber of sections (ina ctive if filter ha s onlyone section)

La tt ice ARMA La tt ice coeffs, La tt ice coeffs lengt h*, La ddercoeffs, Ladder coeffs length*, Number ofsections (ina ctive if filter ha s only onesection)

La t t ice MA La t t ice coeffs, La t t ice coeffs lengt h*, a ndNumber of sections (ina ctive if filter ha s onlyone section)

Direct Form FI R

Direct Form FI R

Numerat or, Numerat or length*, a nd Numberof sections (inactive if filter h a s only onesection)

Page 227: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 227/798

5-23

*length va ria bles cont a in th e tota l number of coefficients of th a t t ype.

Note Variable na mes ca nnot be C la ngua ge reserved w ords, such a s “for.”

3 Select t he Export Suggested butt on to use th e suggested dat a type or selectExport As a nd select the desired da ta type from t he pulldown a nd select thedesired Fractional length .

t ransposedsection)

5 Filter Design and A nalysis Tool

Note If you do not h a ve the Filt er Design Toolbox insta lled, selecting a nydata type other than double-precision floating point results in a filter thatdoes not exact ly ma t ch th e one you designed in th e FDATool. This is du e to

rounding a nd trun cating differences.

4 Click OK to sa ve th e file and close the dia log box or click Apply to save thefile, but lea ve the dia log box open for add itiona l C hea der file definitions.

Page 228: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 228/798

5-24

Saving and O pening Filter Design Sessions

Saving and Opening Filter Design SessionsYou can sa ve your filter design session a s a MAT-file a nd r eturn to th e sam esession another time.

Select t he Save session but ton t o sa ve your session a s a MAT-file. The firsttime you sa ve a session, a Save Filter Design File browser opens, promptingyou for a session na me.

For example save th is design session as TestFilter fda in your current

Page 229: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 229/798

5-25

For example, save th is design session as TestFilter.fda in your currentw orking directory by typing TestFilter in the File name field.

The .fda extension is ad ded a utoma tica lly to a ll filter design sessions you save.

Note You ca n a lso use th e Save session a nd Save session as menu items in

t he File menu t o save a session. This dia log opens every t ime you select th eSave As menu item.

You can loa d existing sessions into t he Filter Design a nd Ana lysis Tool byselecting th e Open session butt on, . A Load Filter Design File browseropens th a t a llows you to select from your previously saved filter designsessions.

5 Filter Design and A nalysis Tool

Page 230: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 230/798

5-26

6S P Tool: A S igna lP rocessing G U I S uit e

Overview . . . . . . . . . . . . . . . . . . . . . 6-2

SPTool: An Interactive Signal Processing Environment 6-3

Opening SPTool . . . . . . . . . . . . . . . . . . 6-5

Getting Help . . . . . . . . . . . . . . . . . . . . 6-7

Overview of the Signal Browser: Signal Analysis . . . 6-8

Overview of the Filter Designer: Filter Design . . . . 6-11

Overview of the Filter Viewer: Filter Analysis . . . . 6-14

Overview of the Spectrum Viewer: Spectral Analysis . 6-17

Using SPTool: Filtering and Analysis of Noise 6-20

Page 231: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 231/798

Using SPTool: Filtering and Analysis of Noise . . . . . 6 20

Exporting Signals, Filters, and Spectra . . . . . . . . 6-32

Accessing Filter Parameters . . . . . . . . . . . . . 6-34

Importing Filters and Spectra into SPTool . . . . . . 6-39

Loading Variables from the Disk . . . . . . . . . . . 6-43

Selecting Signals, Filters, and Spectra in SPTool . . . 6-44

Editing Signals, Filters, or Spectra in SPTool . . . . . 6-45

Designing a Filter with the Pole/Zero E ditor . . . . . 6-46

Redesigning a Filter Using the Magnitude Plot . . . . 6-49

6 SPTool: A Signal Processing G UI Suite

OverviewSP Tool is a gra phica l user interfa ce (G UI ) for a na lyzing a nd ma nipula tingdigita l signa ls, filters, a nd spectr a . The first few sections of this cha pter givea n overview of SPTool a nd i ts a ssocia ted G U Is

• “SPTool: An Interactive Signal Processing Environment”• “Opening SP Tool”• “Overview of th e Signa l B rowser: Signal Analysis”• “Overview of the Filt er Designer: Filter Design”• “Overview of the Filter Viewer: F ilter Ana lysis”• “Overview of the Spectr um View er: Spectr a l Ana lysis”• “U sing S P Tool: Filtering a nd Ana lysis of Noise”

The rest of this cha pter i l lustra tes in deta il how to use the G U I-basedintera ctive tools by wa lking through some exam ples

• “U sing S P Tool: Filtering a nd Ana lysis of Noise”• “Importing a Signa l into SP Tool”• “Designing a Fil ter”• “Applying a Fil ter to a Signa l”• “Ana lyzing S ignals: Opening the Signa l B rowser”

Page 232: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 232/798

6-2

y g g p g g• “Spectr a l Ana lysis in the Spectr um Viewer”• “Exporting S ignals, Fil ters, and S pectra”• “Accessing Fil ter P a ra meters”• “Redesigning a Fil ter Using t he Magnitude P lot”• “Accessing P a ra meters in a Sa ved S pectrum”• “Importing Filters and Spectra into SPTool”• “Loa ding Varia bles from th e Disk”• “Selecting Signals, Filters, and Spectra in SPTool”• “Ed iting S igna ls, Filters, or Spectr a in S P Tool”• “Designing a Filter w ith th e P ole/Zero Edit or”•

“Making Signa l Mea surements: U sing Markers”

SPTool: A n Interactive Signal Processing Environment

SPTool: An Interactive Signal Processing EnvironmentSP Tool is an interactive GU I for digita l signal processing t ha t ca n be used to

• Analyze signals.• Design filters.• Analyze (view) filters.• Filter signals.• Ana lyze signa l spectra .

You can accomplish t hese tasks using four G UI s th a t y ou a ccess from w ithinS P Tool

• The Signal Br owser is for a na lyzing signa ls. You can a lso play portions ofsignals using y our computer ’s a udio hardw a re.

• The Fi lt er Design er is for designing or edit ing FIR a nd I IR digita l f i lters.Most of th e Signa l Pr ocessing Toolbox filter design met hods ava ilable at th ecomma nd line are a lso a va ilable in the Filter Designer. Additiona lly, you candesign a fi lter by using th e P ole/Zero E dit or to gra phica lly place poles andzeros on th e z -plane.

The Fi lt er Vi ewer is for a na lyzing fi l ter chara cterist ics. See Overview of theFilter Viewer: Filt er Ana lysis .

• The Spectru m Vi ewer is for spectra l a na lysis You can use the Signa l

Page 233: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 233/798

6-3

The Spectru m Vi ewer is for spectra l a na lysis. You can use the Signa lP rocessing Toolbox spectr a l estima tion meth ods to estima te t he powerspectral density of a signa l. See Overview of th e Spectr um View er: Spectr a lAnalysis .

SPTool Data StructuresYou can use SP Tool to an a lyze signa ls, f il ters, or spectra tha t you crea te a t t heMATLAB comma nd lin e.

You can bring signa ls, filters, or spectr a from the MATLAB w orkspace int o theSP Tool workspa ce using t he Import i tem under the File menu. Signa ls, f il ters,or spectra th a t y ou crea te in (or import int o) th e SP Tool workspa ce exist a sMATLAB str uctures. S ee the MATLAB d ocument a tion for more informa tion onMATLAB str uctures.

Page 234: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 234/798

O pening SPTool

Opening SPToolTo open SP Tool, ty pe

sptool

Page 235: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 235/798

6-5

When you first open S P Tool, it conta ins a collection of defa ult signa ls, filters,a nd spectr a . You can specify your ow n preferences for w ha t signa ls, filters, an dspectr a you wa nt to see w hen SP Tool opens. See “Designing a Fil ter with th eP ole/Zero E dit or” on pa ge 6-46 for more deta ils.

You can a ccess these th ree GU Is from S P Tool by selecting a signa l, filter, orspectrum a nd pressing t he a ppropriat e View button.

• Signal Browser• Filter Viewer• Spectrum Viewer

6 SPTool: A Signal Processing G UI Suite

You can a ccess the Filter Designer G U I by pressing t he New button to creat ea new fi lter or the Edit butt on to edit a selected filter. The Apply butt on a ppliesa selected filter t o a selected signa l.

The Create butt on opens the Spectr um View er an d crea tes th e power spectra ldensity of the selected sign a l. The Update butt on opens the Spectrum Viewerfor t he selected s pectr um.

Page 236: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 236/798

6-6

G etting Help

Getting HelpUse the What’s this? button to find out more informa tion about a part icularregion of the G U I.

Context-Sensitive Help: The What’s This? ButtonTo find informa tion on a pa rt icula r region of the Signal B rowser, FilterDesigner , Filter Viewer , or Spectrum Viewer

1 P ress the What’s this? but t on, .

2 Click on t he region of the G UI you w a nt informa tion on.

You can a lso use the What’s this? menu item in the Help menu to laun chcontext-sensitive help.

Page 237: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 237/798

6-7

6 SPTool: A Signal Processing G UI Suite

Overview of the Signal Browser: Signal AnalysisYou can use the Signa l Browser to display a nd a na lyze signals l isted in th eSignals list box in S P Tool.

U sing the Signal B rowser you ca n• Analyze and compare vector or array (matrix) signals.• Zoom in on portions of signa l da ta .• Measure a va riety of cha ra cterist ics of signa l dat a .• Compare multiple signals.• P lay portions of signa l data on a udio ha rdw ar e.•

P rint signa l plots.

Opening the Signal BrowserTo open th e Signa l B rowser from S P Tool

1 Selecting one or more signa ls in th e Signals list in SPTool

2 P ress ing the View button under the Signals list

Page 238: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 238/798

6-8

O verview of the Signal Browser: Signal A nalysis

The Signa l Br owser ha s th e follow ing component s• A toolba r w ith but tons for convenient a ccess to frequently u sed functions

Page 239: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 239/798

6-9

P rint a nd print preview

P lay an a udio s ignal

Displa y a rra y a nd complex signa ls

Zoom the signa l in an d out

Select one of severa l loa ded signa ls

Set t he display color a nd l ine style of a signal

6 SPTool: A Signal Processing G UI Suite

• A display region for analyzing signals, including markers for measuring,comparing, or playing signals

• A “panner” th a t displays t he entire signa l length , highlighting t he portioncurrently a ctive in th e display r egion

A Mar ker measurements a rea

Toggle th e ma rkers on a nd off

Set ma rker types

Turn on th e Wha t ’s This h elp

Page 240: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 240/798

6-10

O verview of the Filter Designer: Filter Design

Overview of the Filter Designer: Filter DesignThe Filter Designer provides an in tera ctive gra phica l environment for thedesign of digita l IIR a nd F IR fi l ters based on specifications tha t you enter on amagnitude or pole-zero plot.

Note You can a lso use th e Filter Design a nd Ana lysis Tool (FD ATool)described in Cha pter 5, “Filter Design an d Ana lysis Tool,” for filter design an danalys is .

Filter TypesYou can design filters of the follow ing t ypes using the F ilter Designer

• Bandpass• Lowpass• Bands top• Highpass

FIR Filter MethodsYou can use th e followin g filter meth ods to design FIR filters

Page 241: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 241/798

6-11

• Equiripple• Least squares• Window

IIR Filter MethodsYou can use th e followin g filter meth ods to design IIR filters

• Butterworth• Ch ebyshev Type I• Chebyshev Type II• Elliptic

6 SPTool: A Signal Processing G UI Suite

Pole/ Zero EditorYou can use th e P ole/Zero E dit or to design arbitra ry FIR a nd IIR fi l ters byplacing a nd m oving poles a nd zeros on th e complex z -plane.

Spectral Overlay FeatureYou can a lso superimpose spectra on a filter ’s ma gnit ude response t o see if th efi ltering requirements a re met.

Opening the Filter DesignerOpen t he Filter Designer from S P Tool by either

• P ress ing t he New button in the Filters list in SPTool• Selecting a fi l ter you w a nt to edit from the Filters list in SP Tool, and th en

pressing th e Edit button

Page 242: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 242/798

6-12

The Filter D esigner ha s t he followin g components

O verview of the Filter Designer: Filter Design

• A toolba r w ith t he follow ing butt ons

• A pulldow n Filter menu for selecting a filter from th e list in S P Tool• A Sampling Frequency text box• A pulldow n Algorithm menu for selecting a filter design method or a

pole-zero plot displa y

• A Specifications a rea for view ing or modifying a filter ’s design pa ra metersor pole-zero locations

• A plot displa y region for gra phically a djusting filter ma gnitu de responses orth e pole-zero loca tions

P rint a nd print preview

Zoom in and out

P assband view

Overlay spectrum

Turn on t he Wha t’s This h elp

Page 243: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 243/798

6-13

th e pole zero loca tions• A Measurements a rea for viewing t he response cha ra cterist ics a nd st a bili ty

of the current filter

6 SPTool: A Signal Processing G UI Suite

Overview of the Filter Viewer: Filter AnalysisYou can use t he Filter Viewer t o a na lyze the follow ing response cha ra cteristicsof selected filt ers

Magn itude r esponse• P ha se response• Impulse r esponse• St ep response• G roup dela y• P ole an d zero locat ions

The Filter Viewer can display up to six different response cha ra cteristics plotsfor a selected filter a t a ny t ime. The Filter View er provides fea tu res for

• Zooming• Measu ring filter responses• Overlaying filter responses• Modifying displa y para meters such a s frequency ra nges or ma gnitude units

Opening the Filter ViewerYou can open the Filter Viewer from SPTool by

1 Selecting one or more filters in t he Filters list in SPTool

Page 244: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 244/798

6-14

1 Selecting one or more filters in t he Filters list in SPTool

2 P ress ing the View button under the Filters list

When you first open the F ilter View er, it display s t he default plot configura tionfor th e selected filter (s).

O verview of the Filter Viewer: Filter A nalysis

The filter ’s ma gnitude an d phase plots a re displayed by default . In a ddit ion,the frequency is displayed w ith a l inea r scale on t he interval [0,Fs/2] .

The F ilter Viewer ha s t he following component s

Page 245: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 245/798

6-15

• A toolba r w ith but tons for convenient a ccess to frequently u sed functions

P rint a nd print preview

Zoom the signa l in an d out

Select one of severa l loa ded signa ls

Set t he display color a nd l ine style of a signal

6 SPTool: A Signal Processing G UI Suite

• A fil ter identif ica tion region t ha t displays the fi l ter na me an d sa mplingfrequency for th e currently selected filter(s)

• A Plots region for selecting t he response plots y ou wa nt to display in t hedisplay a rea , an d for specifying some frequency response display

characterist ics• A Frequency Axis region for specifying frequency scaling in t he display a rea• A display a rea for a na lyzing one or more frequency response plots for t he

selected filter(s)• A Mar ker measurements a rea

Toggle th e ma rkers on a nd off

Set ma rker types

Turn on t he Wha t’s This h elp

Page 246: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 246/798

6-16

O verview of the Spectrum Viewer: Spectral A nalysis

Overview of the Spectrum Viewer: Spectral AnalysisYou can use th e Spectr um View er for est imat ing and a na lyzing a signa l’spower spectra l density (PS D). You can use the P SD estimat es to understa nd asigna l’s frequency content .

U sing th e Spectrum View er you ca n

• Ana lyze and compare spectr a l density plots.• Use different spectral estimation methods to create spectra

- Burg (pburg )- Covarian ce (pcov )- FF T ( fft )- Modified covariance (pmcov )- MTM (multitaper method) ( pmtm)- MUSIC (pmusic )- Welch ( pwelch )- Yule-Wa lker AR ( pyulear )

• Modify power spectr a l densit y par a meters such as FF T length, w indow ty pe,

a nd sa mple frequency.• P rint spectra l plots.

Opening the Spectrum Viewer

Page 247: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 247/798

6-17

p g pTo open the Spectrum Viewer a nd creat e a P SD estima te from SP Tool

1 Select a signal from the Signal list box in S P Tool.

2 P ress the Create button in the Spectra l ist .

3 P ress the Apply button in the Spectrum Viewer.

To open t he Spectrum Viewer w ith a P SD estimat e a lready l isted in S P Tool

1 Select a P SD est imat e f rom t he Spectra list box in SP Tool.

2 P ress the View button in the Spectra l ist .

6 SPTool: A Signal Processing G UI Suite

For example

1 Select mtlb in the default Signals list in SPTool.

2 P ress the Create butt on in SP Tool to open t he Spectrum Viewer.

3 P ress the Apply butt on in t he Spectr um View er to plot t he spectrum.

Page 248: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 248/798

6-18

The Spectrum Viewer h a s t he follow ing components

• A toolba r w ith butt ons for convenient a ccess to frequently u sed functions

P rint a nd print preview

Zoom the signa l in an d out

Select one of severa l loa ded signa ls

O verview of the Spectrum Viewer: Spectral A nalysis

• A signal identification region that provides information about the signalwhose power spectral density estimate is displayed

• A Parameters region for modifying t he P SD para meters• A display r egion for ana lyzing spectra a nd a n Options menu for modifying

display chara cterist ics• Spectrum ma na gement contr ols

- Inherit from menu to inherit P SD specificat ions from anoth er PS D objectlisted in the menu

- Revert butt on to revert to the na med P SD ’s origina l specifica tions- Apply button for crea ting or upda ting P SD estima tes

Set t he display color a nd l ine style of a signal

Toggle th e ma rkers on a nd off

Set ma rker types

Turn on t he Wha t’s This h elp

Page 249: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 249/798

6-19

6 SPTool: A Signal Processing G UI Suite

Using SPTool: Filtering and Analysis of NoiseThe follow ing sections provide an example of using t he G U I-bas ed intera ctivetools t o

• Design and implement a n FIR ba ndpass digita l f il ter• Apply the filter t o a noisy signal• Ana lyze signals a nd t heir spectra

The st eps include

1 Creat ing a noisy signa l in the MATLAB workspace a nd importing i t intoS P Tool

2 Designing a bandpa ss fi lter using t he Fil ter Designer

3 Applying the filter to the origina l noise signal t o crea te a ba ndlimited noises ignal

4 Comparing th e t ime doma in informa tion of th e original a nd fi l tered signa lsusing the Signal Browser

5 Comparing the spectra of both signals using the Spectrum Viewer6 Exporting t he filter design to the MATLAB w orkspace a s a st ructur e

7 Accessing the filter coefficients from the exported MATLAB structure

Page 250: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 250/798

6-20

Importing a Signal into SPToolTo import a signa l into SP Tool from the w orkspa ce or disk, the signa l must be

either• A special MATLAB signa l struct ure, such as t ha t sa ved from a previous

S P Tool session• A signa l crea ted a s a va ria ble (vector or ma tr ix) in t he MATLAB w orkspace

For this exa mple, creat e a new signal a t t he comma nd line and t hen import i ta s a structure into SP Tool.

1 Creat e a ra ndom signal in t he MATLAB workspace by typing

Using SPTool: Filtering and Analysis of N oise

randn('state',0);x = randn(5000,1);

2 If S P Tool is not a lread y open, open SP Tool by t yping

sptool

The SPTool window is displayed.

3 Select Import from t he File menu in S P Tool. The Import to SPTool dialogopens.

Select FromWorkspace to displayall MATLAB workspace variables

Workspace/FileContents list

Sampling frequency of imported signal

Nameof imported

Import signals,filters, or spectra

Page 251: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 251/798

6-21

Notice tha t t he variable x is displayed in t he Workspace Contents list. (Ifit is not, select th e From Workspace ra dio button t o display t he content s ofthe workspace.)

4 Select t he signal a nd import i t into the Data field

a Make sure tha t Signal is selected in th e Import As pull-down menu.

Select FromDisk to load the

contents of a MAT-file into the Contents list.

(SPTool structures appear in

square brackets. Vectors andmatrices are not in brackets.)

Move selections(s) fromthe

Contents list to the Data field.

Name of importedsignal

6 SPTool: A Signal Processing G UI Suite

b Select the signa l varia ble x in the Workspace Contents l ist .

c Click on the a rrow t o th e left of the Data field or t ype x in the Data field.

d Type 5000 in the Sampling Frequency field.

e Nam e the signa l by typing noise in the Name field.

f Press OK .

At this point , t he signal noise[vector] is selected in S P Tool’s Signals list.

Note You ca n import filters a nd spectra into SP Tool in much t he same w a y a syou import signa ls. See “Importing Filt ers an d Spectr a into SP Tool” on page6-39 for specific details.

You can a lso import signa ls from MAT-files on your disk, ra th er th a n from t hew orkspa ce. See “Loading Varia bles from t he Disk” on pa ge 6-43 for moreinformation.

Type help sptool for informa tion a bout importing from th e comman d line.

Designing a FilterYou can import a n existing filter int o SP Tool, or you can d esign an d edit a new filter using the Filter Designer.

In t his exa mple

Page 252: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 252/798

6-22

p

1 Open a default f i l ter in t he Fil ter Designer.

2 Specify an equir ipple ban dpass F IR filter.

O pening the Filter De signerTo open t he Filt er D esigner, press the New but t on in S P Tool. This opens t heFil ter Designer with a defa ult f i lter na med filt1 .

Specifying the Bandpass FilterDesign an equiripple bandpass FIR fi lter w ith the following chara cterist ics

• Sa mpling frequency of 5000 H z

Using SPTool: Filtering and Analysis of N oise

• St opban d freq uency r a nges of [0 500] H z a nd [1500 2500] H z• P a ssba nd frequency ra nge of [750 1250] Hz• Ripple in t he pa ssba nd of 0.01 dB• St opband a tt enuat ion of 75 dB

To modify your filt er in t he Filt er Designer t o meet th ese specificat ions

1 Cha nge the filter sa mpling frequency to 5000 by entering t his va lue in th eSampling Frequency text box.

2 Select Equiripple FIR from t he Algorithm list.

3 Select bandpass from t he Type l ist .

4 Set t he passba nd edge frequencies by ent ering 750 for Fp1 a nd 1250 for Fp2 .

5 Set t he stopband edge frequencies by entering 500 for Fs1 a nd 1500 for Fs2 .

6 Type 0.01 into the Rp field a nd 75 into the Rs field.

Rp sets the ma ximum pa ssband ripple and Rs sets the stopband a tt enuat ionfor t he filter.

7 P ress the Apply butt on to design t he new filter.When t he new filter isdesigned, the ma gnit ude response of the filter is displa yed wit h a solid linein the display r egion.

Page 253: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 253/798

6-23

6 SPTool: A Signal Processing G UI Suite

The resultin g filter is a n order-78 ban dpa ss equiripple filter.

Note You ca n us e the solid line in th e plot to modify your filter design. See“Redesigning a Filt er Using t he Magn itude P lot” on page 6-49 for moreinformation.

Page 254: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 254/798

6-24

Applying a Filter to a SignalWhen you apply a filter t o a signa l, you creat e a new signa l in SP Toolrepresenting the filtered signal.

To apply t he filt er filt1 you just crea ted t o the signal noise

1 Select SPTool from th e Window menu in the Filter Designer.

Using SPTool: Filtering and Analysis of N oise

2 Select the signa l noise[vector] from th e Signals list a nd select t he filter(named filt1[design] ) from the Filters l ist , a s shown below.

3 Press Apply to apply th e filter filt1 to the signa l noise .

The Apply Filter dia log box is display ed.

Page 255: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 255/798

6-25

4 Keep th e defa ult filter str ucture selected in the Algorithm l ist .

5 Nam e the new signa l by typing blnoise in the Output Signal field in t hisdialog box.

6 SPTool: A Signal Processing G UI Suite

6 Press OK to close th e Apply Filter dialog box.

The filter is applied to th e selected signa l an d th e filtered signa lblnoise[vector] is l isted in t he Signals list in SPTool.

Analyzing Signals: Opening the Signal BrowserYou can a na lyze a nd print signals using the Signa l Browser. You ca n a lso pla ythe signals if your computer has audio output capabilities.

For example, compare th e signal noise to th e fi ltered signal blnoise

1 Shift + click on the noise a nd blnoise signals in the Signals list of SP Tool toselect both signa ls.

2 P ress the View button under the Signals list.

The Signal B rowser is a ctiva ted a nd both signa ls are displa yed in thedisplay r egion. (The na mes of both signa ls a re shown a bove the displayregion.) Init ia lly, the origina l noise signa l covers up the ban dlimitedblnoise signal.

3 Push the selection butt on on th e toolba r, , to select th e blnoise signal.

The display a rea is upda ted. Now you ca n see the blnoise s ignalsuperimposed on top of the noise signa l. The signa ls ar e displa yed indifferent colors in both t he display region and t he pann er. You ca n chan geth e color of th e selected signa l using t he Line Properties button on th etoolbar

Page 256: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 256/798

6-26

toolbar, .

Using SPTool: Filtering and Analysis of N oise

Pla ying a SignalWhen you press t he Play button in the Signa l B rowser toolbar, , the a ctivesignal is played on t he computer ’s a udio hardw ar e.

1 To hear a port ion of t he a ctive (selected) signa l

a U se the vertical markers to select a portion of the signa l you wa nt t o play

Page 257: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 257/798

6-27

a U se the vert ical markers to select a portion of the signa l you wa nt t o play.Vertica l ma rkers a re enabled by the an d buttons.

b P ress the Play button.

2 To hea r th e oth er signa l

a Select the signa l as in step 3 a bove. You ca n a lso select th e signa l directlyin th e display r egion.

b P ress the Play button aga in .

Printing a Signal

You can print from the Signa l Br owser using th e Print button, .

6 SPTool: A Signal Processing G UI Suite

You can use the l ine display buttons t o maximize the visual contra st betw eenth e signals by set ting th e line color for noise to gra y a nd t he line color forblnoise to white. Do this before printing two signals together.

Note You ca n follow th e same rules to print spectr a , but you ca n’t print filterresponses dir ectly fr om SP Tool.

U se the Signal B rowser region in the Preferences dia log box in S P Tool tosuppress printing of both the pan ner a nd t he ma rker sett ings.

To print both signa ls, press the Print button in the Signa l Browser toolbar.

Page 258: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 258/798

6-28

Spectral Analysis in the Spectrum ViewerYou can a na lyze the frequency content of a signa l using the Spectr um Viewer,wh ich est ima tes a nd displays a signal’s power spectra l density.

For exa mple, to ana lyze and compa re the spectr a of noise a nd blnoise

1 Crea te a pow er spectra l density (PS D) object, spect1 , tha t i s a ssocia ted wi th

the s ignal noise , an d a second P SD object, spect2 , tha t i s a ssocia ted wi ththe s ignal blnoise .

Using SPTool: Filtering and Analysis of N oise

2 Open th e Spectr um View er to ana lyze both of th ese spectr a .

3 P rint both spectra .

Creating a PSD O bject From a Signal

1 Cli ck on SP Tool, or select SPTool from th e Window menu of an y a ctive openG U I. SP Tool is now t he a ctive window.

2 Select the noise [vector] signal in the Signals list of SP Tool.

3 Press Create in the Spectra l ist .

The Spectr um Viewer is activa ted, a nd a P SD object ( spect1 ) correspondin g

to the noise signal is creat ed in the Spectra list. The P SD is not computedor display ed yet.

4 Press Apply in th e Spectrum Viewer t o compute a nd display t he P SDest imate spect1 using the default pa ra meters.

The P SD of th e noise signa l is displayed in t he display r egion. Theidentifying informa tion for t he P SD ’s a ssociat ed signa l (noise ) is displa yed

above the Parameters region.The PSD estimat e spect1 is within 2 or 3 dB of 0, so the noise ha s a fa ir ly“fla t” power spectral density.

5 Follow steps 1 through 4 for t he ban dlimited noise signa l blnoise to creat ed P SD ti t t2

Page 259: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 259/798

6-29

a second P SD est imat e spect2 .

The PSD estimat e spect2 i s fla t betw een 750 and 1250 Hz a nd ha s 75 dB

less pow er in t he st opba nd r egions of filt1 .

O pening the Spectrum V iew er w ith Tw o Spectra

1 Reactivate S P Tool a gain, a s in step 1 above.

2 Shift + click on spect1 a nd spect2 in the Spectra list t o select t hem both.

3 Press View in the Spectra l ist to reactivat e the Spectrum Viewer a nddisplay both spectra together.

6 SPTool: A Signal Processing G UI Suite

Printing the Spe ctraB efore printing t he tw o spectr a together, use th e color an d line style selectionbutt on, , to different iat e th e tw o plots by line sty le, ra th er th a n by color.

To print bot h spectr a

1 P ress the Print Preview butt on, , in th e toolbar on th e SpectrumViewer.

2 From the Spectrum Viewer Print Preview window, dra g th e legend out ofth e display region so tha t it doesn’t obscure par t of the plot.

Page 260: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 260/798

6-30

th e display region so tha t it doesn t obscure par t of the plot.

3 P ress the Print button in the Spectrum Viewer Print Preview window.

Using SPTool: Filtering and Analysis of N oise

Page 261: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 261/798

6-31

6 SPTool: A Signal Processing G UI Suite

Exporting Signals, Filters, and SpectraYou can export S P Tool signals, filters, an d spectr a a s stru ctures to theMATLAB w orkspa ce or to your dis k.

In ea ch ca se you

1 Select t he items in SP Tool you w a nt to export.

2 Select Export from t he File menu.

O pening the Exp ort Dialog BoxTo save t he filter filt1 you just crea ted in t his example, open the Export dia log box wit h filt1 preselected

1 Select filt1 in the SPTool Filters l ist .

2 Select Export from t he File menu.

The Export dia log box opens w ith filt1 preselected.

Export as objects for use withControl SystemToolbox

Page 262: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 262/798

6-32

Select items to export

Exporting Signals, Filters, and Spectra

Exp orting a Filter to the M ATLAB W orkspa ceTo export th e filter filt1 to the MATLAB workspace

1 Select filt1 from t he Export List a nd deselect all other items usingCtrl + click.

2 P ress the Export to Workspace button.

Page 263: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 263/798

6-33

6 SPTool: A Signal Processing G UI Suite

Accessing Filter Parameters

Accessing Filter Parameters in a Saved FilterThe MATLAB st ructur es creat ed by S P Tool ha ve severa l a ssocia ted fields,ma ny of wh ich a re a lso MATLAB st ructur es. See the MATLAB documenta tionfor genera l informa tion a bout MATLAB st ructur es.

For exa mple, a fter exporting a fi lter filt1 to t he MATLAB workspa ce, t ype

filt1

to displa y t he fields of t he MATLAB filter str ucture. The tf , Fs , and specs fields of the structure contain the information that describes the filter.

The tf Field: Accessing Filter CoefficientsThe tf field is a structure conta ining the t ra nsfer function r epresenta tion ofth e filter. U se this field to obta in t he filter coefficients

• filt1.tf.num cont a ins th e numera tor coefficients.• filt1.tf.den cont a ins t he denomina tor coefficient s.

The vectors cont a ined in t hese stru ctures represent polynomials in descending

powers of z . The numera tor a nd denomina tor polynomials a re used to specifythe t ra nsfer function

where

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 264: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 264/798

6-34

• b is a vector cont a ining t he coefficients fr om the tf.num field.• a is a vector cont a ining t he coefficients from t he tf.den field.• m is the numera tor order.• n is the denominat or order.

You can change th e fil ter representa tion from t he default t ra nsfer function toa nother form by using th e tf2ss or tf2zp functions.

The Fs Field: A ccessing Filter Sa m ple Freque ncyThe Fs field cont a ins th e sampling frequency of th e filter in hert z.

A ccessing Filter Parameters

The spe cs Field: Accessing other Filter Par a m etersThe specs field is a structure conta ining para meters tha t you specified for t hefilter design. The first field, specs.currentModule , contains a str ingrepresent ing t he most recent design met hod selected from the Filt er Designer ’sAlgorithm list before you export ed t he filter . The possible cont ent s of the

currentModule field a nd t he corresponding design met hods a re shown below .

Follow ing the specs.currentModule field, there ma y be up to seven ad ditiona lfields, with labels such a s specs.fdremez , specs.fdfirls , etc. The designspecifica tions for th e most recent ly exported filter a re cont a ined in t he fieldwh ose label ma tches the currentModule str ing. For exa mple, if the specs s tructure is

Table 6-1: Filter Specifications currentModule Field Values

Contents of the currentModule field Design Method

fdbutter Butterworth I IR

fdcheby1 Ch ebyshev Type I I IR

fdcheby2 Ch ebyshev Type II I IR

fdellip Elliptic IIR

fdfirls Least Squa res FIR

fdkaiser Kaiser Window FIR

fdremez Equiripple FIR

Page 265: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 265/798

6-35

filt1.specs

anscurrentModule: 'fdremez'fdremez: [1x1 struct]

th e filter specifica tions a re conta ined in the fdremez field, which is itself a d a tastructure.

The specifica tions include the par a meter va lues from t he Specifications region of the Filter Designer, such as ba nd edges an d filter order. For example,

6 SPTool: A Signal Processing G UI Suite

th e filter a bove ha s th e followin g specifica tions st ored infilt1.specs.fdremez .

filt1.specs.fdremez

ans =

setOrderFlag: 0type: 3

f: [0 0.2000 0.3000 0.5000 0.6000 1]m: [6x1 double]

Rp: 0.0100Rs: 75wt: [3.2371 1 3.2371]

order: 78

B eca use certa in fil ter para meters are unique to a pa rticula r design, thisstr ucture ha s a different set of fields for ea ch filter design.

The ta ble below describes the possible fields a ssociat ed w ith th e filter designspecification field (the specs field) tha t ca n a ppear in the exported st ructure.

Table 6-2: SPTool Structure Specifications for Filters

Parameter Description

Beta Ka iser w indow β parameter.

f Conta ins a vector of band -edge frequencies, norma lized soth a t 1 Hz corresponds to ha lf the sa mple frequency.

Fpass Pa ssband cutoff frequencies. Scala r for lowpa ss a nd

Page 266: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 266/798

6-36

highpa ss designs, two-element vector for ba ndpa ss a ndbandstop designs.

Fstop St opband cutoff frequencies. Scala r for lowpa ss a ndhighpa ss designs, two-element vector for ba ndpa ss a ndbandstop designs.

m The response ma gnit udes corresponding t o the ba nd-edgefrequencies in f .

order Filter order.

A ccessing Filter Parameters

Accessing Parameters in a Saved SpectrumThe following str ucture fields describe the spectr a sa ved by S P Tool.

Rp Pa ssband r ipple (dB )

Rs Stopband a t tenuat ion (dB)

setOrderFlag Contains 1 if th e filter order w a s specified ma nua lly (i.e.,t he Minimum Order box in th e Specifications regionwa s not checked). Conta ins 0 if the filter order wa scomputed automatically.

type Contains 1 for lowpa ss, 2 for highpass, 3 for ba ndpa ss, or4 for ba ndst op.

w3db -3 dB frequency for Butterworth IIR designs.

wind Vector of Kaiser window coefficients.

Wn Cut off frequency for t he Ka iser w indow FIR fi lter w hensetOrderFlag = 1 .

wt Vector of weight s, one w eight per frequency ba nd.

Field Description

P The spectr a l power vector

Table 6-2: SPTool Structure Specifications for Filters (Continued)

Parameter Description

Page 267: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 267/798

6-37

P The spectr a l power vector.

f The spectra l frequ ency vector.

6 SPTool: A Signal Processing G UI Suite

You can a ccess th e informa tion in t hese fields a s you do wit h every MATLABstructure.

For exa mple, if you export a n SP Tool PS D estima te spect1 to the w orkspace,type

spect1.P

to obta in th e vector of associat ed pow er values.

confid A structure containing the confidence intervals data

• The confid.level field cont a ins t he chosenconfidence level.

• The confid.Pc field cont a ins th e spectra l pow erdata for the confidence intervals.

• The confid.enable field cont a ins a 1 if confidencelevels ar e ena bled for the power spectra l density.

signalLabel The na me of the signa l from w hich the pow er spectra ldensity wa s generat ed.

Fs The a ssociat ed signa l’s sa mple ra te.

Field Description

Page 268: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 268/798

6-38

Importing Filters and Spectra into SPTool

Importing Filters and Spectra into SPToolIn a ddition t o importing signa ls into SP Tool, you can import filters or spectraint o SP Tool from either t he w orkspace or from a file.

The procedures a re very simila r t o those expla ined in

• “Importing a Signa l int o SP Tool” on page 6-20 for loa ding va ria bles from theworkspace

• “Loading Varia bles from t he Disk” on pa ge 6-43 for loading va ria bles fromyour disk

Imp orting FiltersWhen you import filters, first select th e a ppropriat e filter form from t he Form l is t .

Page 269: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 269/798

6-39

6 SPTool: A Signal Processing G UI Suite

For every filter you specify a va ria ble na me or a va lue for t he filter ’s sa mplingfrequency in th e Sampling Frequency field. E a ch filter form r equires differentvariables.

Transfer Function. For Transfer Function , you specify th e filter by it s tr a nsferfunction representation

• The Numerator field specifies a va ria ble na me or va lue for t he numera torcoefficient vector b , wh ich conta ins m + 1 coefficient s in descending pow ers ofz.

• The Denominator field specifies a va ria ble na me or va lue for th edenominator coefficient vector a , wh ich conta ins n + 1 coefficient s indescending powers of z.

Sta te Space. For State Space , you specify th e filter by it s st a te-spa cerepresentation

The A-Matrix , B-Matrix , C-Matrix , and D-Matrix fields specify a va ria blena me or a value for each ma trix in this system.

Zeros, Poles, Gain. For Zeros, Poles, Gain , you specify th e filter by itszero-pole-gain representation

H z ( ) B z ( )A z ( )----------- b 1( ) b 2( ) z 1– L b m 1+( ) z m –+ + +

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

x · A x B u +=

y C x D u +=

Z z( ) z z 1( )–( ) z z 2( )–( )L z z m( )–( )

Page 270: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 270/798

6-40

• The Zeros field specifies a va ria ble nam e or va lue for t he zeros vector z ,w hich conta ins th e loca tions of m zeros .

• The Poles field specifies a va ria ble nam e or va lue for t he zeros vector p ,w hich conta ins th e loca tions of n poles .

• The Gain field specifies a va ria ble na me or va lue for th e gain k .

Second O rder Sections. For 2nd Order Sections you specify th e filter by itssecond-order section representation

H z ( ) Z z ( )P z ( )---------- k

z z 1( )( ) z z 2( )( ) z z m ( )( )z p 1( )–( ) z p 2( )–( )L z p n ( )–( )

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

Importing Filters and Spectra into SPTool

The SOS Matrix field specifies a va ria ble na me or a va lue for t he L -by-6 S OS

mat r ix

whose rows contain the numerator and denominator coefficients b i k a nd a i k oft he second-order sect ions of H (z ).

Note If you import a filter tha t w a s not creat ed in SP Tool, you can only editt ha t filt er using t he Pole/Zero E dit or.

Imp orting SpectraWhen you import a pow er spectr a l density (P SD ), you specify

• A varia ble na me or a value for th e PS D vector in the PSD field• A va ria ble na me or a va lue for th e frequency vector in th e Freq. Vector field

The PS D va lues in the PSD vector correspond to t he frequencies cont a ined int h F V t t th t t t h th l th

H z ( ) H k z ( )

k 1=

L

∏b 0 k b 1 k z 1– b 2 k z 2–+ +

1 a 1 k z 1– a 2 k z 2–+ +--------------------------------------------------------- -

k 1=

L

∏= =

so s

b 01 b 11 b 21 1 a 11 a 21

b 02 b 12 b 22 1 a 12 a 22M M M M M M

b 0 L b 1 L b 2 L 1 a 1 L a 2 L

=

Page 271: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 271/798

6-41

t he Freq. Vector vector; the tw o vectors must ha ve the sa me length.

Page 272: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 272/798

Loading Variables from the Disk

Loading Variables from the Disk To import va ria bles represent ing sign a ls, filters, or spect ra from a M AT-file onyour disk

1 Select the From Disk ra dio butt on an d do either of the follow ing- Type the na me of the file you w a nt to import in to th e MAT-file Name field

a nd press either the Tab or th e Enter key on your keyboa rd.- Select Browse , an d th en find and select t he file you w an t t o import using

t he Select Fi le to Open dialog. P ress OK to close tha t dia log.

In either cas e, all va ria bles in the MAT-file you selected a re displayed in th eFile Contents list.

2 Select th e var iables t o be import ed into SP Tool.

You can now import one or more var iables from the File Contents l ist intoSP Tool, as long as t hese varia bles a re sca lar s, vectors, or mat rices.

Page 273: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 273/798

6-43

6 SPTool: A Signal Processing G UI Suite

Selecting Signals, Filters, and Spectra in SPToolAll signals, filters, or spectra listed in SPTool exist as special MATLABstructures. You can bring da ta representing signals, f i l ters, or spectra intoSP Tool from t he MATLAB w orkspa ce. In genera l, you can select one or severalitems in a given list box. An it em is selected w hen it is h ighlighted.

The Signals l ist shows a ll vector a nd a rra y signals in t he current S P Toolsession.

The Filters list shows a ll designed a nd imported filters in th e current SP Toolsession.

The Spectra list shows a ll spectra in th e current SP Tool session.

You can select a single dat a object in a list, a ra nge of da ta objects in a list, ormultiple separa te da ta objects in a l ist . You can a lso ha ve dat a objectssimulta neously selected in different lists

• To select a sing le item, click on it. All other item s in t ha t list box becomedeselected.

• To add or remove a ra nge of items, Shift + click on th e items a t t he top a ndbott om of the section of the l ist th a t y ou w an t t o add. You can a lso dra g yourmouse pointer to select th ese items.

• To add a single da ta object t o a selection or remove a s ingle dat a object froma multiple selection, Ctrl + click on the object.

Page 274: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 274/798

6-44

Editing Signals, Filters, or Spectra in SPTool

Editing Signals, Filters, or Spectra in SPToolYou can edit selected items in SPTool by

1 Selecting t he na mes of the signa ls, fi l ters, or spectra you w an t t o edit .

2 Selecting the appropriat e Edit menu item- Duplicate to copy a n it em in a n S P Tool list- Clear to delete an item in a n S P Tool list- Name to rena me an it em in an S P Tool list- Sampling Frequency to modify th e sampling frequency a ssociat ed wit h

either a signa l (a nd it s a ssociat ed spectra ) or filter in a n S P Tool list

The pull-down menu n ext t o ea ch menu it em shows th e na mes of all selecteditems.

You can a lso edit th e followin g signa l cha ra cteristics by right-clicking in t hedisplay r egion of th e Signa l Br owser, the Filter View er, or th e Spectr um View er

• The signal name• The sampling frequency•

The line st yle properties

Note If you modify t he sa mpling frequency a ssociat ed wit h a signal’sspectr um using th e right -click menu on t he Spectrum Viewer display r egion,the sa mpling frequency of the a ssocia ted signa l is aut oma tically updated.

Page 275: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 275/798

6-45

6 SPTool: A Signal Processing G UI Suite

Designing a Filter with the Pole/ Zero EditorTo design a filter tra nsfer function using th e Filter Designer P ole/Zero E dit or

1 Select the Pole/Zero Editor option from th e Algorithm list t o open theP ole/Zero E dit or in t he Fil ter Designer display.

2 En ter the desired fi lter ga in in the Gain edit box.

3 Select a pole or zero (or conjuga t e pa ir) by selectin g one of the (pole) or(zero) sym bols on th e plot.

4 Ch oose th e coordina tes t o work in by specifying Polar or Rectangular fromt he Coordinates list.

5 Specify t he new loca tion(s) of the selected pole, zero, or conjuga te pa ir bytyping values into the Mag a nd Angle fields (for a ngula r coordina tes) or X a nd Y (for r ecta ngula r coordina tes) fields. Alterna tively, position t he polesa nd zeros by dra gging the a nd symbols.

6 Use the Conjugate pair check box to creat e a conjuga te pa ir from a lone poleor zero, or t o brea k a conjugat e pair int o tw o individua l poles or zeros.

Design a new fi lter or edit a n exist ing fi lter in the sa me wa y.

Page 276: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 276/798

6-46

Tip Keep the F ilter View er open w hile designing a filter w ith th e Pole/ZeroEditor. Any chan ges tha t y ou ma ke to the fi lter t ra nsfer function in thePole/Zero Ed itor a re t hen simu lta neously r eflected in t he response plots of theFilt er View er.

Designing a Filter wi th the Pole/ Zero Editor

Positioning Poles and ZerosYou ca n us e your mouse t o move poles a nd zer os ar ound t he pole/zero plot a ndmodify your filter design

• Add poles or zeros using the toolba r butt ons for pole placement, , a nd zeroplacement, .

• Era se poles a nd zeros using the eraser button, .• Move both members of a conjuga te pa ir simulta neously by ma nipulat ing just

one of th e poles or zeros.

To ungroup conjuga tes, select th e desired pair a nd uncheck Conjugate pair int he Specifications region on the Filt er Designer.

Add poles Add zeros Delete poles/zeros

Move poles/zeros bydragging on plot

Page 277: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 277/798

6-47

When y ou place t w o or m ore poles (or tw o or m ore zeros) directly on top of eachother, a number is displa yed next t o the symbols (on the left for poles, and onth e right for zeros) indicat ing t he number of poles or zeros at th a t loca tion (e.g.,

for t hree zeros). This n umber ma kes it ea sy t o keep tra ck of a ll th e polesa nd zeros in t he plot a rea , even wh en severa l ar e superimposed on ea ch oth era nd a re not visually differentia ble. Note, however, tha t this num ber d oes n ot indica te the m u l t i p l i c i t y of th e poles or zeros to wh ich it is a tt a ched.

6 SPTool: A Signal Processing G UI Suite

To detect wh ether or not a set of poles or zeros a re tr uly mult iples, use t he zoomtools to ma gnify th e region a round t he poles or zeros in qu estion. Becausenumerical limita tions usua lly prevent a ny set of poles or zeros from sha ringexactly th e sam e value, a t a high enough zoom level even t ruly mu ltiple polesor zeros appear d istinct from each other.

A common w a y to a ssess wh ether a par ticular group of poles or zeros conta insmult iples is by compa ring t he mutu a l proximity of th e group members a ga insta s elected thr eshold va lue. As a n example, the residuez function defines a poleor zero as being a mult iple of anoth er pole or zero if the a bsolut e dista ncesepara ting t hem is less tha n 0.1%of the larger pole or zero’s ma gnit ude.

Page 278: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 278/798

6-48

Redesigning a Filter Using the M agnitude Plot

Redesigning a Filter Using the Magnitude PlotAfter designing a filt er in the Filter Designer, you ca n redesign it by dra ggingth e specifica tion lines on t he ma gnitu de plot. U se the specifica tion lines tochange pa ssband ripple, stopba nd a tt enuat ion, a nd edge frequencies.

In the following exam ple, crea te a Chebyshev fil ter a nd m odify i t by dr a ggingth e specifica tion lines

1 Select Chebyshev Type I IIR from th e Algorithm menu.

2 Select highpass from t he Type menu.

3 Type 2000 in the Sampling Frequency field.

4 Set t he following para metersa Fp = 800

b Fs = 700

c Rp = 2.5

d Rs = 35

5 Check Minimum Order so the Filter Designer can ca lcula te th e lowest filterorder that produces the desired characteristics.

6 Press Apply to compute t he filter an d upda te th e response plot.

7 P osition t he cursor over th e horizont a l filter specifica tion line for t hestopban d. This is th e first (leftmost) horizonta l specifica tion line you see.

The cursor chan ges to t he up/down dra g indica tor.

Page 279: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 279/798

6-49

g p g

8 Dra g the l ine unti l the Rs (stopband a tt enuat ion) f ield rea ds 100 .

Note The Order value in the Measurements region cha nges beca use ahigher filter order is n eeded t o meet th e new specifica tions.

6 SPTool: A Signal Processing G UI Suite

Setting PreferencesU se Preferences from th e SP Tool File menu to customize displays a nd certa inpara meters for S P Tool a nd i t s four component G U Is. The new sett ings a resa ved on disk a nd a re used wh en you resta rt SP Tool from MATLAB.

In the Preferences regions, y ou can• Select colors an d ma rkers for a ll displa ys.• Select colors an d line styles for displayed signa ls.• Configure labels, an d ena ble/disa ble ma rkers, pan ner, a nd zoom in t he

Signal Browser.• Configure displa y par a meters, a nd ena ble/disa ble ma rkers an d zoom in th e

Spectrum Viewer.• Configure filter a nd displa y par a meters, a nd ena ble/disa ble zoom in the

Filter Viewer.• Configure tiling preferences in t he Filter Viewer.• Specify FF T length, a nd ena ble/disa ble mouse zoom a nd grid in th e Filter

Designer.• E na ble/disa ble use of a d efa ult s ession file.• E xport filters for use wit h t he Cont rol Syst em Toolbox.• E na ble/disa ble sea rch for plug-ins a t sta rt -up.

When y ou first select Preferences , the Preferences dia log box opens w ithMarkers selected by default .

Page 280: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 280/798

6-50

Setting Preferences

You ca n

• Cha nge the sett ings for ma rkers from th is panel of the Preferences dialog.• Choose a ny of the other cat egories listed t o cust omize its sett ings.

Click once on a ny listed cat egory in t he left pa ne of the Preferences dialog toselect it .

Page 281: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 281/798

6-51

6 SPTool: A Signal Processing G UI Suite

Making Signal Measurements: Using MarkersYou can use t he mar kers on the Signal B rowser, the Filter Viewer , or th eSpectrum Viewer t o ma ke mea surement s on a ny of th e follow ing

• A signal in the Signa l Browser• A filter r esponse in t he Filt er View er• A power spectra l density plotted in t he Spectrum Viewer

The ma rker butt ons from left t o right a re

• t oggle ma rker s on/off• vertical ma rkers• horizonta l ma rkers• vertical ma rkers wit h tra cking• vertical ma rkers with t ra cking an d slope• display peaks (local maxima)• display va lleys (local minima )

To ma ke a mea surement

1 Select a line to mea sure (or pla y, if you a re in the S igna l Br owser).

2 Select one of the ma rker buttons to a pply a ma rker to the display ed signal.

3 P osit ion a ma rker in th e main displa y a rea by gra bbing i t w ith your mouseand dra gging

Page 282: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 282/798

6-52

and dra gging

a Select a ma rker settin g. If you choose the Vertical , Track , or Slope buttons, you can dra g a ma rker to the right or left . If you choose theHorizontal button, you can dra g a ma rker up or down.

b Move the mouse over the ma rker (1 or 2) th a t you w a nt to dra g.

The ha nd cursor with the ma rker number inside i t is displa yed wh enyour mouse pass es over a ma rker.

M aki ng Signal M easurements: U sing M arkers

c Dra g the marker to wh ere you wa nt i t on the signa l.

As you drag a ma rker, the bott om of the Signa l Br owser shows t he currentposition of both ma rkers. Depending on wh ich ma rker sett ing you select,some or a ll of th e followin g fields ar e displayed — x1 , y1 , x2 , y2 , dx , dy , m .These fields are a lso displayed w hen you print from the Signa l Br owser,

unless you suppress th em.You ca n a lso position a ma rker by typing its x1 a nd x2 or y1 a nd y2 va lues inthe region a t t he bott om.

Page 283: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 283/798

6-53

6 SPTool: A Signal Processing G UI Suite

Page 284: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 284/798

6-54

7

Funct ion Reference

Function Category List . . . . . . . . . . . . . . . 7-3

Alphabetical List of Functions . . . . . . . . . . . . 7-20

Page 285: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 285/798

7 Function Reference

Deta iled descriptions of a ll Signa l P rocessing Toolbox functions a re in t hesetw o sections:

• “Function C a tegory List” – a list of functions, grouped by subject a rea• “Alphabetica l List of Functions” – reference pa ges in a lphabetica l order

Page 286: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 286/798

7-2

Function C ategory List

Function Category ListThe Signal Processing Toolbox functions are divided into the followingcategories

• “Filter Analysis”• “Fil ter Im plementa tion”• “FIR Digita l Filter Design”• “IIR D igital Fil ter Design—Cla ssica l and Direct”• “IIR Fil ter Order Est imat ion”• “Analog Lowpass Filter Prototypes”• “Ana log Filter D esign”•

“Ana log Filter Tra nsforma tion”• “Filter Discretization”• “Linea r S ystem Tra nsforma tions”• “Windows”• “Transforms”• “Cepstra l Analysis”• “Sta tist ical Signa l Processing a nd Spectra l Ana lysis”• “Pa ra metric Modeling”• “Linea r P rediction”• “Multira te Signa l P rocessing”• “Waveform Generation”• “Specialized Opera tions”• “Gra phical U ser Interfaces”.

Page 287: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 287/798

7-3

Filter Analysis

abs Absolute value (magnitude).

angle P hase angle.

freqs Frequency response of an a log filters.

freqspace Frequency spa cing for fr equency response.

7 Function Reference

freqz Compute t he frequency response of digita l filters.

freqzplot P lot frequency response da ta .

grpdelay Compute t he a verage filter delay (group delay).

impz Compute t he impulse response of digita l filters.

unwrap Unw rap phase a ngles .

zplane Zero-pole plot.

Filter Implementation

conv Convolut ion a nd polynomia l multiplica tion.

conv2 Tw o-dimen siona l convolution.

deconv Deconvolution a nd polynomial division.

fftfilt FF T-bas ed FI R filtering using t he overla p-a dd m ethod.

filter Filter da ta w ith a recursive (II R) or nonrecursive (FIR )filter.

filter2 Tw o-dimensional digita l filtering.

filtfilt Zero-pha se digita l filtering.

filtic Find init ia l conditions for a t ra nsposed direct form II filter

implementation

Filter Analysis (Continued)

Page 288: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 288/798

7-4

implementation.

latcfilt La tt ice a nd lat t ice-ladder f i lter implementa tion.

medfilt1 One-dimensional m edian filtering.

sgolayfilt Savitzky-Golay filtering.

sosfilt Second-order (biqua dra tic) II R digita l filtering.

Function C ategory List

upfirdn U psample, apply an FIR fi lter, an d downsa mple.

FIR Digital Filter Design

convmtx Convolution matrix.

cremez Complex a nd n onlinea r-pha se equiripple FIR filter d esign.

fir1 Design a w indow-bas ed finite impulse response filter.

fir2 Design a frequency sa mpling-ba sed finite impulse responsefilter.

fircls Constra ined least squa re FIR fi l ter design for multibandfilters.

fircls1 Constra ined least squa re fil ter design for lowpa ss a ndhighpass l inear pha se FIR fi l ters.

firls Least squa re l inea r-phase FI R fi l ter design.

firrcos Ra ised cosine FIR filter design.

intfilt Int erpolat ion FIR fi lter design.

kaiserord Est imat e pa ra meters for an F IR fi lter design with K a iserwindow.

remez Compute the Parks-McClellan optimal FIR filter design.

remezord Parks-McClellan optimal FIR filter order estimation

Filter Implementation (Continued)

Page 289: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 289/798

7-5

remezord Parks McClellan optimal FIR filter order estimation.

sgolay Savitzky-Golay filter design.

7 Function Reference

IIR Digital Filter Design—Classical and Direct

butter B utt erworth an a log and digita l f i lter design.

cheby1 Ch ebyshev Type I filter design (pas sba nd ripple).cheby2 Ch ebyshev Type II filter design (stopban d ripple).

ellip E lliptic (Ca uer) filter design.

maxflat G enera lized digita l But terworth fi l ter design.

prony P rony’s meth od for t ime-domain II R filter design.

stmcb Compute a linea r model using St eiglitz-McBride itera tion.

yulewalk Recursive digita l filter design.

IIR Filter Order Estimation

buttord Ca lculat e the order a nd cutoff frequency for a B utt erworthfilter.

cheb1ord Ca lcula te t he order for a Ch ebyshev Type I filter.

cheb2ord Ca lcula te t he order for a Ch ebyshev Type II filter.

ellipord Ca lcula te t he minimum order for elliptic filters.

Page 290: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 290/798

7-6

Function C ategory List

Analog Lowpass Filter Prototypes

besselap Bessel analog lowpass filter prototype.

buttap B utt erworth a na log lowpa ss fi lter prototype.

cheb1ap Ch ebyshev Type I a na log low pass filter prototype.

cheb2ap Ch ebyshev Type II a na log low pass filter prototype.

ellipap Elliptic ana log low pass filter prototype.

Analog Filter Design

besself Bessel analog filter design.

butter B utt erworth an alog a nd digita l fi l ter design.

cheby1 Ch ebyshev Type I filter design (pass ban d r ipple).

cheby2 Chebyshev Type II filter design (stopband ripple).

ellip Elliptic (Ca uer) filter d esign.

Analog Filter Transformation

lp2bp Tra nsform lowpass a na log fi l ters to bandpa ss.

lp2bs Tra nsform lowpa ss a na log fi l ters to ba ndstop.

Page 291: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 291/798

7-7

lp2hp Tra nsform lowpa ss a na log fi l ters to highpass.

lp2lp Ch a nge th e cut -off frequency for a lowpa ss a na log filter.

7 Function Reference

Filter Discretization

bilinear Bilinear transformation method for analog-to-digital filterconversion.

impinvar Impulse inva ria nce method for a na log-to-digita l filter

conversion.

Linear System Transformations

latc2tf Convert lat t ice fi l ter para meters to tra nsfer function form.

polystab St abil ize a polynomial.polyscale Sca le the roots of a polynomial.

residuez z -transform partial-fraction expansion.

sos2ss Convert digit a l filter second-order section par a meters t osta te-space form.

sos2tf Convert digita l filter second-order section da ta to tra nsferfunction form.

sos2zp Convert digit a l filter second-order sections par a meters t ozero-pole-gain form.

ss2sos Convert digital f i l ter sta te-space pa ra meters tosecond -order s ections form.

ss2tf Convert sta te-space fil ter para meters to tr a nsfer functionform.

Page 292: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 292/798

7-8

ss2zp Convert sta te-space filter pa ra meters t o zero-pole-ga inform.

tf2latc Convert tra nsfer function fi l ter para meters to lat t ice fi l terform.

Function C ategory List

tf2sos Convert digita l filter tra nsfer function da ta to second-ordersections form.

tf2ss Convert tra nsfer function fi lter pa ra meters to sta te-space

form.tf2zp Convert t ra nsfer function fil ter para meters to

zero-pole-gain form.

zp2sos Convert digit a l filter zero-pole-ga in pa ra meters t osecond -order s ections form.

zp2ss Convert zero-pole-ga in filter pa ra meters to st a te-space

form.zp2tf Convert zero-pole-ga in filter pa ra meters t o tra nsfer

function form.

Windows

barthannwin Compute a modified B a rtlet t-Ha nn w indow.

bartlett Compute a Ba r t let t window.

blackman Compute a B lackman w indow.

blackmanharris Compute a minimum 4-term B lackman-Ha rris w indow.

bohmanwin Compute a B ohma n window.

chebwin Compute a Chebyshev window.

Linear System Transformations (Continued)

Page 293: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 293/798

7-9

Compute a Chebyshev window.

gausswin Compute a G a ussian w indow.

hamming Compute a Ha mming window.

hann Compute the Ha nn (Ha nning) window.

kaiser Compute a K aiser w indow.

7 Function Reference

nuttallwin Compute a Nut ta ll-defined minimum 4-termB lackman-Ha rris w indow.

rectwin Compute a recta ngular w indow.

triang Compute a t r ian gular w indow.

tukeywin Compute a Tukey (tapered cosine) window.

window Window funct ion ga tew a y.

Window s (Continued)

Page 294: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 294/798

7-10

Function C ategory List

Transforms

bitrevorder Perm ute in put into bit-reversed order.

czt Chirp z-transform.

dct Discrete cosine transform (DCT).

dftmtx Discrete Fourier tra nsform ma trix.

fft Compute th e one-dimensional fa st Fourier tra nsform.

fft2 Compute the two-dimensional fast Fourier transform.

fftshift Rear ra nge the outputs of the FFT functions.

goertzel Compute th e discrete Fourier tr a nsform using t he secondorder Goertzel algorithm.

hilbert Compute th e discrete-time a na lytic signal using th e Hilberttransform.

idct Inverse discrete cosine tra nsform.

ifft One-dimensional inverse fast Fourier tr a nsform.

ifft2 Two-dimensional inverse fa st Fourier t ra nsform.

Cepstral Analysis

cceps Complex cepstral analysis.

icceps Inverse complex cepstrum.

Page 295: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 295/798

7-11

rceps Real cepstrum an d minimum phase reconstruction.

7 Function Reference

Statistical Signal Processing and Spectral Analysis

cohere Est imat e ma gnitude squa red coherence function betw eentw o signals.

corrcoef Compute t he correla tion coefficient ma tr ix.

corrmtx Compute a da ta ma trix for aut ocorrelation mat rixestimation.

cov Compute t he covaria nce matr ix.

csd Est imat e the cross spectra l density (CSD ) of tw o signa ls.

pburg Est imat e the power spectral density using the Burgmethod.

pcov Est imat e the power spectra l density using t he covaria ncemethod.

peig Es tima te th e pseudospectr um using t he eigenvectormethod.

periodogram Est imat e the power spectra l density (PS D) of a signal usinga periodogra m.

pmcov Est imat e the power spectral density using t he modifiedcovariance method.

pmtm Est imat e the power spectra l density using the multi ta permet hod (MTM).

pmusic Est imat e the power spectral density using MUSI Calgorithm

Page 296: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 296/798

7-12

algorithm.

psdplot P lot power spectral density (P SD ) da ta .

pwelch Est imat e the power spectra l density (PS D) of a signal usingWelch’s m et hod.

Function C ategory List

pyulear Est ima te t he pow er spectr a l density using t he Yule-Wa lkerAR m ethod.

rooteig Est imat e frequency a nd power content using the

eigenvector method.rootmusic Est imat e frequency a nd power content using t he root

MUSIC algor i thm.

tfe Est imat e the tra nsfer function from input an d output.

xcorr Est ima te t he cross-correla tion function.

xcorr2 Est ima te t he tw o-dimensional cross-correla tion.

xcov Est ima te t he cross-cova ria nce function (equa l tomea n-removed cross-correla tion).

Parametric Modeling

arburg Compute an estimat e of AR model para meters using theB urg method.

arcov Compute an estimat e of AR model para meters using thecovariance method.

armcov Compute an estimat e of AR model para meters using themodified cova ria nce method.

aryule Compute an estimat e of AR model para meters using theYule-Wa lker m et hod.

Statistical Signal Processing and Spectral Analysis (Continued)

Page 297: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 297/798

7-13

ident See th e Syst em Id entificat ion Toolbox document a tion.

invfreqs Ident ify continuous-time filter par a meters from frequencyresponse dat a .

7 Function Reference

invfreqz Ident ify discrete-time filter par a meters from frequencyresponse da ta .

prony P rony’s method for time domain I IR filter design.

stmcb Compute a linea r model using St eiglitz-McBride itera tion.

Parametric Modeling (Continued)

Page 298: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 298/798

7-14

Function C ategory List

Linear Prediction

ac2poly Convert a n a ut ocorrelat ion sequence to predictionpolynomial.

ac2rc Convert a n a ut ocorrelat ion sequence to reflection

coefficients.is2rc Convert inverse sine par a meters t o reflection coefficient s.

lar2rc Convert log area ra tio para meters t o reflection coefficient s.

levinson Compute t he Levinson-Dur bin recursion.

lpc Compute linear prediction filter coefficients.

lsf2poly Convert line spectra l frequencies t o a prediction filtercoefficients.

poly2ac Convert a prediction filter polynomial to a n a ut ocorrela tionsequence.

poly2lsf Convert prediction filter coefficient s t o line spectra lfrequencies.

poly2rc Convert a prediction filter polynomial t o reflectioncoefficients.

rc2ac Convert reflection coefficients t o an a utocorrela tionsequence.

rc2is Convert reflection coefficients t o inverse sine para meters.

rc2lar Convert reflection coefficient s to log a rea r a tio para meters.

rc2poly Convert reflection coefficients to a prediction filterpolynomial.

Page 299: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 299/798

7-15

rlevinson Compute t he reverse Levinson-Dur bin recursion.

schurrc Compute r eflection coefficients from a n a ut ocorrelat ionsequence.

7 Function Reference

Multirate Signal Processing

decimate Decrease th e sam pling rat e for a sequence (decima tion).

downsample Reduce the sa mpling ra te by a n integer factor.

interp Increase sampling rate by an integer factor (interpolation).

interp1 One-dimensional d a ta int erpola tion (ta ble lookup).

resample Cha nge sa mpling ra te by a ny ra tional factor.

spline Cubic spline interpola tion.

upfirdn U psample, apply an FIR fi l ter, an d downsa mple.

upsample Increase the sampling rat e by a n integer factor

Waveform Generation

chirp G enera te a sw ept-frequency cosine.

diric Compute t he Dir ichlet or periodic sinc function.

gauspuls G enera te a G a ussian-modula ted sinusoidal pulse.

gmonopuls G enera te a G a ussian monopulse.

pulstran G enerat e a pulse t ra in .

rectpuls G enera te a sam pled a periodic rectangle.

sawtooth G enerat e a sa wt ooth or t r iangle wave.

sinc Sinc function.

Page 300: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 300/798

7-16

square G enerat e a square wave.

tripuls G enera te a sam pled a periodic tr ia ngle.

vco Volta ge cont rolled oscilla t or.

Function C ategory List

Page 301: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 301/798

7-17

7 Function Reference

Specialized Operations

buffer B uffer a signa l vector into a ma trix of dat a fra mes.

cell2sos Convert a cell a rra y for second-order sections t o asecond-order section matrix.

cplxpair G roup complex numbers int o complex conjuga te pa irs.

demod Demodulation for communications simulation.

dpss Discrete prolat e spheroidal sequences (Slepia n sequences).

dpssclear Remove discrete prolat e spheroidal sequ ences fromda tabase .

dpssdir Discrete prola te spheroida l sequences dat a ba se directory.dpssload Load discrete prolate spheroidal sequences from database.

dpsssave Sa ve discrete prolat e spheroidal sequences in da ta base.

eqtflength Make th e lengths of a tra nsfer function’s numera tor a nddenominat or equa l.

modulate Modulation for communications simulation.

seqperiod Compute t he period of a sequence.

sos2cell Convert a second-order section ma tr ix to cell arra ys.

specgram Time-dependent frequency a na lysis (spectr ogram ).

stem P lot discrete sequence data .

strips Strip plot.

udecode Decode 2 n -level qua nt ized integer input s t o floa ting -pointoutputs

Page 302: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 302/798

7-18

outputs.

uencode Qua nt ize and encode floa ting-point input s to integeroutputs.

Function C ategory List

Graphical User Interfaces

fdatool Open t he Filt er Design a nd Ana lysis Tool.

fvtool Open the Filter Visualization Tool.

sptool In t era ctive digita l signa l processin g tool (SP Tool).

Page 303: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 303/798

7-19

7

Alphabetical List of Functions 7

a bs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-26a c2poly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-27a c2rc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-28a ngle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-29

a rbur g . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-30a rcov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-31a rmcov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-32a ryu le . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-33ba rt ha nn w in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-34ba rt lett . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-36bessela p . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-38besself . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-39bilinea r . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-42bitr evorder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-47bla ckma n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-49bla ckma nh a rris . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-51bohma nw in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-53buffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-55but ta p . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-64

but ter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-65but tord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-70cceps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-75cell2sos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-77cheb1ap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-78cheb1ord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-79cheb2ap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-83cheb2ord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-84chebwin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-89cheby1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-90

Page 304: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 304/798

7-20

cheby2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-95chir p . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-100cohere . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-106conv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-110conv2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-111

convm tx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-113

A lphabetical List of Functions

corrcoef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-115corr mt x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-116cov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-119cplxpa ir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-120cremez . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-121csd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-129

czt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-133dct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-136decima t e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-138deconv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-141dem od . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-142dft mt x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-144dir ic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-145dow nsa mple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-146dpss . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-148dpssclea r . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-151dpssd ir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-152dpssloa d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-153dpsss a ve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-154ellip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-155ellipap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-161

ellipord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-162eqt flengt h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-167fda t ool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-168fft . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-170fft 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-173fftfilt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-174ffts hift . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-176filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-177filt er2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-180filtern orm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-181fil fil 7 183

Page 305: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 305/798

7-21

filtfilt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-183filt ic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-184fir1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-186fir2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-190fircls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-193

fircls 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-196

7

firls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-199firr cos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-204freqs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-206freqs pa ce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-208freqz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-209freqzplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-213

fvt ool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-216ga uspuls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-220ga ussw in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-222gm onopuls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-224goertzel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-226grpdela y . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-231ha mmin g . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-234ha nn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-236hilbert . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-238icceps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-242idct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-243ifft . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-244ifft 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-245impinva r . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-246impz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-248

int erp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-251int filt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-253invfreq s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-255invfreq z . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-259is2rc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-262ka iser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-263ka iserord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-265la r2rc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-270la tc2tf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-271la tcfilt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-272levinson 7 274

Page 306: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 306/798

7-22

levinson . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-274lp2bp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-276lp2bs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-279lp2hp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-281lp2lp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-283

lpc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-285

A lphabetical List of Functions

lsf2poly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-289ma xfla t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-290medfilt 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-292modula te . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-293nu tt a llw in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-296pburg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-299

pcov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-304peig . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-309periodogra m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-316pmcov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-321pmt m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-326pmus ic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-331poly2a c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-339poly2lsf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-340poly2rc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-341polyscale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-343polysta b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-344prony . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-345psdplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-347pulst ra n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-349pw elch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-353

pyulea r . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-359rc2a c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-364rc2is . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-365rc2lar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-366rc2poly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-367rceps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-368rectpuls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-369rectw in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-370remez . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-371remezord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-378resa mple 7-381

Page 307: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 307/798

7-23

resa mple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-381residu ez . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-384rlevinson . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-387rooteig . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-390rootmu sic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-393

sa w tooth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-396

7

schur rc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-397seq period . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-398sgola y . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-400sgola yfilt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-404sin c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-406sos2cell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-408

sos2ss . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-409sos2t f . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-411sos2zp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-413sosfilt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-415specgra m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-416spt ool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-420squ a re . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-425ss2sos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-426ss2tf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-430ss2zp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-431st mcb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-433st rips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-436tf2la tc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-438t f2sos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-439tf2ss . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-442

t f2zp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-444t fe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-447tr ia ng . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-451tr ipuls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-453tu keyw in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-454ud ecode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-456uen code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-459unw ra p . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-462upfirdn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-463upsa mple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-467vco . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-469

Page 308: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 308/798

7-24

vco . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7 469w indow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-471xcorr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-473xcorr2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-477xcov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-478

yulew a lk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-481

A lphabetical List of Functions

zp2sos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-483zp2ss . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-487zp2t f . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-488zpla ne . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-489

Page 309: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 309/798

7-25

abs

7absPurpose Absolut e value (magn itud e)

Syntax y = abs(x)

Description y = abs(x) retur ns t he absolute value of th e element s of x . I f x is complex, abs retur ns t he complex modulus (magn itude).

abs(x) = sqrt(real(x).^2 + imag(x).^2)

I f x is a MATLAB st ring, abs returns the n umeric values of the ASCI Ichara cters in t he str ing. The display format of the str ing changes; the interna lrepresent a tion does not.

The abs function is pa rt of the sta nda rd MATLAB langua ge.

Example Ca lcula te th e magn itude of th e FFT of a s equence.

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

P lot the ma gni tude.

f = (0:length(y)-1)'/length(y)*100; % frequency vector

plot(f,m)

See Also angle

Page 310: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 310/798

7-26

ac2poly

7ac2polyPurpose Convert a n a ut ocorrela tion sequence to a linea r prediction filter polynomia l

Syntax a = ac2poly(r)[a,efinal] = ac2poly(r)

Description a = ac2poly(r) finds th e linea r prediction, FIR filter polynomia l a

corresponding to th e au tocorrela tion sequence r . a is the same length a s r , anda(1) = 1 . The prediction filter polynomial represents the coefficients of theprediction filter wh ose output produces a signa l wh ose a ut ocorrelat ionsequence is approximat ely the sam e as t he given a ut ocorrelat ion sequence r .

[a,efinal] = ac2poly(r) retur ns t he final prediction error efinal ,determined by run ning t he filter for length(r) steps.

Remarks You can a pply this function to real or complex dat a .

Example Consider the autocorrelation sequence

r = [5.0000 -1.5450 -3.9547 3.9331 1.4681 -4.7500];

The corresponding prediction filter polynomial is

[a,efinal] = ac2poly(r)

a =1.0000 0.6147 0.9898 0.0004 0.0034 -0.0077

efinal =

0.1791

See Also ac2rc , poly2ac , rc2poly

References [1] Ka y, S .M. M odern Spectr a l Est im at ion . Englewood Cliffs, NJ :Prentice-Hall, 1988.

Page 311: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 311/798

7-27

ac2rc

7ac2rcPurpose Convert a n a utocorrela tion sequence to reflection coefficients

Syntax [k,r0] = ac2rc(r)

Description [k,r0] = ac2rc(r) finds the reflection coefficients k corresponding t o theautocorrelation sequence r . r0 contains the initial zero-lag autocorrelation.

These reflection coefficients can be used to specify the lattice prediction filtertha t produces a sequence wit h a pproximately th e same a utocorrelationsequence as t he given sequence r .

Remarks You can a pply this function to real or complex dat a .

See Also ac2poly , poly2rc , rc2ac

References [1] Ka y, S .M. M odern Spectr a l Est im at ion . Englewood Cliffs, NJ :Prentice-Hall, 1988.

Page 312: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 312/798

7-28

angle

7anglePurpose Pha se ang le

Syntax p = angle(h)

Description p = angle(h) retur ns th e pha se an gles, in ra dia ns, of th e elements of complexvector or a rra y h . The pha se a ngles lie betw een - π a nd π.

For complex sequence h = x + iy = m e i p , the magnit ude and pha se are given by

m = abs(h)p = angle(h)

To convert to the original h from its ma gnitude and pha se, type

i = sqrt(-1)h = m.*exp(i*p)

The angle function is part of the st a nda rd MATLAB langua ge.

Example Ca lcula te t he pha se of the FF T 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

P lot th e pha se.

f = (0:length(y)-1)'/length(y)*100; % frequency vectorplot(f,p)

Algorithm angle can be expressed a s

angle(x) = imag(log(x)) = atan2(imag(x),real(x))

See Also abs

Page 313: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 313/798

7-29

arburg

7arburgPurpose Compute an estima te of AR model para meters using the B urg method

Syntax a = arburg(x,p)[a,e] = arburg(x,p)[a,e,k] = arburg(x,p)

Description a = arburg(x,p) uses the Bu rg method to fit a p th order a ut oregressive (AR)model to the input signa l, x , by minimizing (least squa res) the forwa rd a ndbackwa rd prediction errors w hile constra ining the AR pa ra meters to sat isfyth e Levinson-Dur bin r ecursion. x is ass umed to be th e output of a n AR systemdriven by wh ite n oise. Vector a cont a ins th e norma lized estima te of th e ARsystem parameters, A(z ), in descendin g powers of z .

Since the method chara cterizes t he input da ta using a n a ll-pole model, thecorr ect choice of t he m odel order p is importa nt.

[a,e] = arburg(x,p) returns the varia nce estimat e, e , of th e wh ite noise inputt o the AR model.

[a,e,k] = arburg(x,p) returns a vector, k , of r eflection coefficient s.

See Also arcov , armcov , aryule , lpc , pburg , prony

H z ( ) e

A z ( )------------ e

1 a 2 z 1–

… a p 1+( )z p –

+ + +----------------------------------------------------------------------= =

Page 314: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 314/798

7-30

arcov

7arcovPurpose Compute an estimate of AR model parameters using the covariance method

Syntax a = arcov(x,p)[a,e] = arcov(x,p)

Description a = arcov(x,p) uses the cova ria nce meth od to fit a p th order a utoregressive(AR) model to t he input signa l, x , wh ich is a ssumed t o be the output of an ARsyst em driven by w hite noise. This meth od minimizes the forw a rd predictionerror in t he least -squa res sense. Vector a conta ins th e normalized estima te ofthe AR system para meters, A (z ), in descendin g powers of z .

B eca use the method chara cterizes th e input da ta using a n a ll-pole model, thecorrect choice of th e model order p is importa nt.

[a,e] = arcov(x,p) returns the varia nce estimat e, e , of the wh ite noise inputto the AR model.

See Also arburg , armcov , aryule , lpc , pcov , prony

H z ( ) e A z ( )------------ e

1 a 2 z 1– … a p 1+( )z

p –+ + +

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

Page 315: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 315/798

7-31

armcov

7armcovPurpose Compute a n estima te of AR model pa ra meters using t he modified cova ria ncemethod

Syntax a = armcov(x,p)[a,e] = armcov(x,p)

Description a = armcov(x,p) uses th e modified covaria nce meth od to fit a p th ordera ut oregressive (AR) model to t he input signa l, x , which is assumed to be theoutput of a n AR system dr iven by wh ite noise. This meth od minimizes theforward and backward prediction errors in the least-squares sense. Vector a conta ins the norma lized estimat e of the AR system para meters, A (z ), indescending pow ers of z .

B eca use the method chara cterizes the input da ta using a n a ll-pole model, thecorr ect choice of t he m odel order p is importa nt.

[a,e] = armcov(x,p) returns the varia nce estimat e, e , of th e wh ite noise inputt o the AR model.

See Also arburg , arcov , aryule , lpc , pmcov , prony

H z ( ) e

A z ( )------------ e

1 a 2 z 1–

… a p 1+( )z p –

+ + +

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

Page 316: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 316/798

7-32

aryule

7aryulePurpose Compute a n estima te of AR model par a meters using t he Yule-Wa lker meth od

Syntax a = aryule(x,p)[a,e] = aryule(x,p)[a,e,k] = aryule(x,p)

Descriptiona = aryule(x,p) uses t he Yule-Wa lker m ethod, a lso ca lled t he a utocorrela tionmeth od, to fit a p th order a utoregressive (AR) model to the w indowed inputsignal, x , by minimizing the forw a rd prediction error in th e lea st-squa ressense. This formula tion lea ds t o the Yule-Wa lker equa tions, w hich a re solvedby t he Levinson-Dur bin recursion. x is assu med to be th e output of a n ARsyst em driven by w hite n oise. Vector a contains the norma lized estimat e of theAR system para meters, A(z ), in descendin g powers of z .

B eca use the method chara cterizes th e input da ta using a n a ll-pole model, thecorrect choice of th e model order p is importa nt.

[a,e] = aryule(x,p) returns the varia nce estimat e, e , of th e wh ite noise inputto the AR model.

[a,e,k] = aryule(x,p) returns a vector, k , of reflection coefficient s.

See Also arburg , arcov , armcov , lpc , prony , pyulear

H z ( ) e A z ( )------------ e 1 a 2 z

1– … a p 1+( )z p –

+ + +----------------------------------------------------------------------= =

Page 317: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 317/798

7-33

barthannwin

7barthannwinPurpose Compute a modified B a rtlet t-Ha nn w indow

Syntax w = barthannwin(n)

Description w = barthannwin(n) re turns an n-point modified B a rtlet t-Ha nn window int he column vect or w. Like Ba r t let t , H ann, a nd Ha mming windows, th is window ha s a ma inlobe at the origin a nd a symptotica lly decaying sidelobes on bothsides. I t is a l inear combinat ion of weighted B ar tlet t a nd Ha nn w indows w ithnear sidelobes lower th a n both B a rtlet t a nd Ha nn a nd w ith fa r sidelobes lowertha n both B a rtlet t a nd H a mming windows. The mainlobe width of the modifiedB a rtlet t-Ha nn window is not increa sed relative to either B a rtlet t or Ha nnwindow ma inlobes.

Note The Ha nn w indow is also ca lled th e Ha nning w indow.

Example N=64;w = barthannwin(N);plot(w); axis([1 N 0 1]);title('64-point Modified Bartlett-Hann window');

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

164−point Modified Bartlett−Hann window

Page 318: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 318/798

7-34

10 20 30 40 50 600

0.1

barthannwin

Algorithm The equa tion for computing t he coefficients of a Modified Ba rt lett-Ha nningwindow is

where .

See Also bartlett , hann , blackman , blackmanharris , bohmanwin , chebwin , gausswin ,hamming , kaiser , nuttallwin , rectwin , triang , tukeywin , window

References [1] Ha , Y.H., and J .A. P earce. “A New Window a nd C ompar ison t o Sta nda rdWindows.” I EE E T r an sacti ons on Acousti cs, Speech, an d Si gnal Pr ocessing .Vol. 37, No. 2, (February 1999). pp. 298-301.

[2] Oppenheim, A.V., a nd R.W. S cha fer. D i scr ete-Ti m e Si gnal Pr ocessi ng .U pper S a ddle River, NJ : P rent ice-Ha ll, 1999, p. 468.

w k 1+[ ] 0.62 0.48 k n 1–------------ - 0.5– – 0.38 2π k

n 1–------------ - 0.5–

cos+=

0 k n 1–( )≤ ≤

Page 319: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 319/798

7-35

bartlett

7bart let tPurpose Compute a B ar t let t window

Syntax w = bartlett(n)

Description w = bartlett(n) re turns an n-point B a rt lett w indow in th e column vector w,where n must be a positive integer. The coefficient s of a B a rt lett w indow a recomput ed a s follows:

• For n odd

For n even

The Ba rtlet t w indow is very simila r to a tr ia ngular w indow a s returned by thetriang function. The Ba rtlet t w indow a lwa ys ends with zeros at sa mples 1 a nd

n , however, w hile the tr ia ngular window is nonzero at those points. For n odd,th e center n-2 points of bartlett(n) ar e equivalent to triang(n-2) .

Note If you specify a one-point window (set n=1 ), th e value 1 is returned.

Example N=64;w = bartlett(N);plot(w); axis([1 N 0 1]);title('Bartlett Window')

w k 1+[ ]

2 k n 1–------------ - 0 k

n 1–2

------------ -≤ ≤,

2 2 k ( )n 1–------------ -– n 1–

2------------- k n 1–≤ ≤,

=

w k 1+[ ]

2 k ( )n 1–------------ - 0 k n

2--- 1–≤ ≤,

2 n k – 1–( )n 1–

------------------------------ n 2--- k n 1–≤ ≤,

=

Page 320: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 320/798

7-36

bartlett

See Also barthannwin , blackman , blackmanharris , bohmanwin , chebwin , gausswin ,hamming , hann , kaiser , nuttallwin , rectwin , triang , tukeywin , window

References [1] Oppenheim, A.V., a nd R.W. Scha fer. D i scr ete-Ti m e Si gnal Pr ocessi ng .U pper Sa ddle River, NJ : P rent ice-H a ll, 1999, pp. 468-471.

10 20 30 40 50 600

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1Bartlett Window

Page 321: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 321/798

7-37

besselap

7besselapPurpose Bessel analog lowpass filter prototype

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

Description [z,p,k] = besselap(n) returns t he poles a nd ga in of a n order n B essel ana loglow pass filter prototype. n must be less t ha n or equa l to 25. The functionretur ns th e poles in th e length n column vector p and t he gain in scala r k . z isa n empty ma tr ix beca use there ar e no zeros. The tra nsfer function is

besselap normalizes the poles a nd ga in so tha t a t low frequency and h ighfrequency the B essel prototype is asymptotically equiva lent to th e B utt erworthprototype of th e sa me order [1]. The ma gnitu de of the filter is less th a n

a t the unit y cutoff frequency Ωc = 1.Ana log B essel f i lters a re cha ra cterized by a group delay t ha t is ma ximally flata t zero frequency an d a lmost consta nt throughout th e passband. The groupdelay a t zero frequency is

Algorithm besselap finds t he filter roots fr om a look-up ta ble constru cted using t heSy mbolic Ma t h Toolbox.

See Also besself , buttap , cheb1ap , cheb2ap , ellipap

Also see the Symbolic Math Toolbox documentation.

References [1] Ra biner, L.R., an d B . G old. Th eory and Appl i cat ion of Di gi ta l Si gnal

Processing . E nglewood Cliffs, NJ : P rent ice-Ha ll, 1975. Pg s. 228-230.

H s ( ) k s p 1( )–( ) s p 2( )–( )L s p n ( )–( )--------------------------------------------------------------------------------=

1 2 ⁄

2 n ( )!2 n n !-------------- 1 n ⁄

Page 322: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 322/798

7-38

besself

7besselfPurpose Bessel analog 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 lowpa ss, ba ndpass, highpass, a nd ba ndstop ana log B esselfi lters. Ana log B essel f i lters a re chara cterized by a lmost consta nt group delaya cross th e entire passband, t hus preserving the w ave sha pe of f i ltered signalsin the passban d. Digita l Bessel f il ters do not retain t his qua li ty, and besself th erefore does not support t he design of digita l B essel filters.

[b,a] = besself(n,Wn) designs an order n lowpa ss a na log fi lter w ith cutofffrequency Wn . It r eturn s th e filter coefficients in t he lengt h n+1 row vectors b a nd a , w ith coefficients in descending powers of s, derived from the transferfunction

Cu toff fr equency is the frequency at wh ich th e magn itude response of the filterbegins to decrea se significa nt ly. For besself , th e cutoff frequency Wn must be

grea ter t ha n 0. The ma gnit ude response of a B essel filter designed by besself is alw ay s less tha n a t the cutoff frequency, a nd i t decreases a s the ordern increases.

I f Wn is a tw o-element vector, Wn = [w1 w2] wi th w1 < w2, then besself(n,Wn)returns a n order 2*n bandpass a na log f i lter wi th passband w1 < ω < w2.

[b,a] = besself(n,Wn,' ftype ') designs a highpass or ban dstop fil ter, where

the str ing ' ftype ' is :• 'high' for a highpass a na log fi l ter with cutoff frequency Wn• 'stop' for a n order 2*n bandst op an a log fi lter if Wn is a tw o-element vector,

Wn = [w1 w2]

H s ( ) B s ( )A s ( )----------- b 1( ) s n b 2( ) s n 1– L b n 1+( )+ + +

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

1 2 ⁄

Page 323: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 323/798

7-39

The stopband is w1 < ω < w2.

besself

With different numbers of output arguments, besself directly obtains otherrea lizat ions of t he a na log filter. To obta in zero-pole-ga in form, use t hree outputa rguments a s shown below.

[z,p,k] = besself(n,Wn) or

[z,p,k] = besself(n,Wn,' ftype ') retur ns th e zeros and poles in lengt h n or

2*n column vectors z a nd p and the gain in the scala r k .To obta in sta te-spa ce form, use four output a rgument s a s shown below.

[A,B,C,D] = besself(n,Wn) or

[A,B,C,D] = besself(n,Wn,' ftype ') where A , B, C, and D a re

a nd u is the input, x is the sta te vector, and y is the output.

Example Design a fifth-order ana log low pass B essel filter tha t suppresses frequenciesgrea ter t ha n 10,000 ra d/s a nd plot t he frequency response of the filter usingfreqs .

[b,a] = besself(5,10000);freqs(b,a) % Plot frequency response

x · A x B u +=

y C x D u +=

Page 324: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 324/798

7-40

besself

Limitations Lowpass Bessel filters have a monotonically decreasing magnitude response,a s do lowpa ss But terworth fi l ters. Compa red to the B utt erworth, Chebyshev,a nd elliptic filters, th e Bessel filter ha s th e slowest rolloff and r equires thehighest order t o meet a n a tt enuat ion specifica tion.

For high order filters, th e sta te-space form is the most num erica lly accurat e,follow ed by t he zero-pole-ga in form. The t ra nsfer fu nction coefficient form isth e least a ccura te; numerical problems ca n a rise for filter orders a s low a s 15.

Algorithm besself performs a four-step a lgorith m:

1 It find s low pass a na log prototy pe poles, zeros, an d ga in using the besselap function.

2 It converts t he poles, zeros, an d ga in into sta te-spa ce form.3 It tra nsforms th e lowpass fi l ter into a band pass, highpass, or ban dstop fi l ter

with desired cutoff frequencies using a state-space transformation.

4 It converts th e sta te-spa ce filter ba ck to tr a nsfer fun ction or zero-pole-ga inf i d

102

103

104

105

-200

0

200

Frequency (radians)

P h a s e

( d e g r e e s

)

102

103

104

105

10-5

100

Frequency (radians)

M a g n

i t u d e

Frequency Response

Page 325: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 325/798

7-41

form, as required.

See Also besselap , butter , cheby1 , cheby2 , ellip

bilinear

7bilinearPurpose B ilinear t ra nsforma tion method for a na log-to-digita l filter 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 bi l i near t ran sform at ion is a ma thema tical mapping of varia bles. In digita lfi ltering, it is a sta nda rd method of mapping the s or a na log plane into the z ordigital pla ne. I t tra nsforms a na log fi l ters, designed using classical f i l ter designtechniques, into their discrete equivalents.

The bilinear t ra nsforma tion maps t he s -plan e into the z -pla ne by

This tra nsforma tion maps the j Ωa xis (from Ω= -∞ t o +∞) repeat edly aroundt he un it circle ( , from ω = −πt o π) by

bilinear can a ccept a n optional para meter Fp tha t specifies prewa rping. Fp , inher tz , indica tes a “mat ch” frequency, tha t is , a frequency for w hich t hefrequency responses before and after mapping match exactly. In prewarpedmode, the bil inea r tra nsforma tion maps the s -plane int o the z -plane w ith

H z ( ) H s ( )s 2 f s

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

=

e j ω

ω 2 t a n 1– Ω2 f s -------- =

H z ( ) H s ( )s

2 πf p

πf p

f s ----

t a n

------------------------ z 1–( )z 1+( )-----------------=

=

Page 326: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 326/798

7-42

bilinear

With t he prewa rping option, bilinear maps the j Ωa xis (from Ω= -∞ t o +∞)r epea t e dl y a r ou n d t h e u n it ci rcl e ( , fr om ω = −πt o π) by

In prewa rped mode, bilinear ma tches the frequency 2 πf p (in ra dians persecond) in the s -plan e to the norma lized frequency 2 πf p/f s (in ra dians persecond) in the z -plane.

The bilinear function works wit h t hree different l inear systemrepresenta tions: zero-pole-ga in, tr a nsfer function, a nd st a te-space form.

Zero-Pole-Gain[zd,pd,kd] = bilinear(z,p,k,fs) a nd

[zd,pd,kd] = bilinear(z,p,k,fs,Fp) convert t he s -domain t ra nsfer functionspecified by z , p , and k to a discrete equiva lent. I nputs z a nd p a re columnvectors cont a ining t he zeros a nd poles, k i s a scala r gain , and fs is the sa mplingfrequency in hert z. bilinear retur ns t he discrete equiva lent in column vectorszd a nd pd and scala r kd . Fp is the optiona l ma tch frequency, in hertz, forprewarping.

Transfer Function

[numd,dend] = bilinear(num,den,fs) a nd

[numd,dend] = bilinear(num,den,fs,Fp) convert an s -doma in tra nsferfunction given by num a nd den to a discrete equivalent . Row vectors num a nd den specify th e coefficients of th e numera tor a nd d enominat or, respectively, indescending powers of s .

e j ω

ω 2 t a n 1–Ω π

f p

f s ----

t a n

2πf p -----------------------------

=

n u m s ( )d en s ( )------------------- - n u m 1( ) s n L n u m n ( ) s n u m n 1+( )+ + +

d en 1( ) s m L d en m ( ) s d en m 1+( )+ + +---------------------------------------------------------------------------------------------------------- -=

Page 327: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 327/798

7-43

bilinear

fs is the sa mpling frequency in h ertz. bilinear returns the discrete equivalentin row vectors numd a nd dend in descending powers of z (a scending pow ersof z -1). Fp is the optional match frequency, in hertz, for prewarping.

State-Space

[Ad,Bd,Cd,Dd] = bilinear(A,B,C,D,fs) a nd

[Ad,Bd,Cd,Dd] = bilinear(A,B,C,D,fs,Fp) convert th e cont inuous-timesta te-space system in m a trices A , B, C, D,

to t he discrete-time sy stem

fs is the sa mpling frequency in h ertz. bilinear returns the discrete equivalentin ma trices Ad , Bd, Cd, Dd. Fp is the optiona l ma tch frequency, in hertz, forprewarping.

Algorithm bilinear uses one of tw o a lgorith ms depending on the forma t of the inputlinear syst em you supply. One algorithm w orks on t he zero-pole-ga in forma ta nd t he other on th e sta te-space forma t. For t ra nsfer function representa tions,bilinear converts to state-space form, performs the transformation, andconverts t he resulting sta te-space system ba ck to tra nsfer function form.

Zero-Pole-G a in Algori thmFor a system in zero-pole-gain form, bilinear performs four steps:

1 I f Fp is present , k = 2*pi*Fp/tan(pi*Fp/fs) ; otherwise k = 2*fs .

2 It st r ips a ny zeros at ±∞usingz = z(find(finite(z)));

x · A x B u +=

y C x D u +=

x n 1+[ ] A d x n [ ] B d u n [ ]+=

y n [ ] C d x n [ ] D d u n [ ]+=

Page 328: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 328/798

7-44

bilinear

3 It tra nsforms t he zeros, poles, an d ga in usingpd = (1+p/k)./(1-p/k);zd = (1+z/k)./(1-z/k);kd = real(k*prod(fs-z)./prod(fs-p));

4 It a dds extra zeros a t -1 so the result ing system ha s equivalent numera tora nd denomina tor order.

Sta te-Spa ce A lgorithmFor a sy stem in st a te-spa ce form, bilinear performs t w o steps:

1 I f Fp is present , k = 2*pi*Fp/tan(pi*Fp/fs) ; else k = 2*fs .

2 It comput es Ad , Bd, Cd, and Dd in terms of A , B, C, and D using

bilinear implement s t hese relat ions using convent iona l MATLABsta tements. The scalar r i s arbit ra ry; bilinear uses to ensur e goodqua ntiza tion noise properties in t he result ing system.

Diagnostics bilinear requires tha t t he numerat or order be no great er tha n thedenomina tor order. If th is is not th e ca se, bilinear displays

Numerator cannot be higher order than denominator.

For bilinear to distingu ish betw een the zero-pole-ga in a nd t ra nsfer functionlinea r system forma ts, the first tw o input par a meters must be vectors wit h th esa me orientat ion in t hese ca ses. If this is not th e case, bilinear displays

First two arguments must have the same orientation.

A d I 1k --- A+

I 1k --- A–

1–=

B d 2 k r

------- I 1k --- A–

1–B =

C d r C I 1k --- A–

1–=

D d 1k --- C I

1k --- A–

1–B D +=

r 2 k ⁄ =

Page 329: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 329/798

7-45

See Also impinvar , lp2bp , lp2bs , lp2hp , lp2lp

bilinear

References [1] P a rks, T.W., a nd C .S. B urru s. Di gi ta l F i l ter D esign . New York: J ohn Wiley& S ons, 1987. P gs. 209-213.

[2] Oppenheim, A.V., a nd R.W. S cha fer. D i scr ete-Ti m e Si gnal Pr ocessing .U pper Sa ddle River, NJ : P rent ice-H a ll, 1999, pp. 450-454.

Page 330: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 330/798

7-46

bitrevorder

7bitrevorderPurpose Permute data into bit-reversed order

Syntax y = bitrevorder(x)[y,i] = bitrevorder(x)

Description bitrevorder is useful for pre-a rra nging filter coefficients so tha t bit-reversedordering does not h a ve to be performed a s pa rt of a n F FT or inverse FF Tcomputa tion. This ca n im prove run -time efficiency for externa l a pplicat ions orfor Simulink B lockset models. Note t ha t MATLAB fft a nd ifft process linea rinput an d output .

y = bitrevorder(x) retur ns t he input da ta in bit-reversed order in vector ormat r ix y . The lengt h of x must be an int eger power of 2. If x i s a ma tr ix , thebit-reversal occurs on t he first dimension of x wit h size great er tha n 1. y is thesa me size as x .

[y,i] = bitrevorder(x) retur ns t he bit-reversed vector or ma tr ix y and thebit-reversed indices i , such t hat y = x(i) . Recall t ha t MATLAB u ses 1-ba sedindexing, so the first index of y w ill be 1, not 0.

The follow ing t a ble shows t he numbers 0 th rough 7, the corresponding bits a ndth e bit-reversed numbers.

LinearIndex

Bits Bit-Reversed

Bit-ReversedIndex

0 000 000 0

1 001 100 4

2 010 010 2

3 011 110 64 100 001 1

5 101 101 5

6 110 011 3

Page 331: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 331/798

7-47

7 111 111 7

bitrevorder

Example Obta in th e bit-reversed ordered output of a vector.

x=[0:7]'; % Create a column vector[x,bitrevorder(x)]ans =

0 01 42 23 64 15 56 37 7

See Also fft , ifft

Page 332: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 332/798

7-48

blackman

7blackmanPurpose Compute a B lackman w indow

Syntax w = blackman(n)w = blackman(n,' sflag ')

Description w = blackman(n) re turns the n-point symm etric Blackman window in thecolumn vector w, where n is a positive integer.

w = blackman(n,' sflag ') re turns an n-point B lackman w indow using thew indow sa mpling specified by ' sflag ' , which can be eith er 'periodic' or'symmetric' (th e defa ult ). When 'periodic' is specified, blackman computesa length n+1 window a nd returns the first n points.

Note If you specify a one-point window (set n=1 ), th e value 1 is returned.

Algorithm The equa tion for computing t he coefficients of a B lackma n w indow is

B lackman w indows h ave sl ightly w ider centr al lobes and less sideband leaka ge

tha n equivalent length H amming and H an n windows.

Examples N=64;w = blackman(N);plot(w); axis([1 N 0 1]);title('Blackman Window')

w k 1+[ ] 0.42 0.5 2 π k n 1–------------ -

cos– 0.08 4 π k n 1–------------ -

cos+ k 0= … n 1–, , ,=

Page 333: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 333/798

7-49

blackman

Algorithm The equa tion for computing t he coefficients of a B lackma n w indow is

B lackman w indows ha ve slightly wider centr al lobes and less sideba nd leakagetha n equivalent length H amming and H ann w indows.

See Also barthannwin , bartlett , blackmanharris , bohmanwin , chebwin , gausswin ,hamming , hann , kaiser , nuttallwin , rectwin , triang , tukeywin , window

References [1] Oppenheim, A.V., a nd R.W. S cha fer. D i scr ete-Ti m e Si gnal Pr ocessing .U pper Sa ddle River, NJ : P rent ice-H a ll, 1999, pp. 468-471.

10 20 30 40 50 600

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1Blackman Window

w k 1+[ ] 0.42 0.5 2 π k n 1–------------ -

cos– 0.08 4 π k n 1–------------ -

cos+ k 0= … n 1–, , ,=

Page 334: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 334/798

7-50

blackmanharris

7blackmanharrisPurpose Compute a minimum 4-term B lackman-ha rris w indow

Syntax w = blackmanharris(n)

Description w = blackmanharris(n) re turns an n-point, m inimu m , 4-t ermB lackman-ha rris w indow in t he column vector w. The w indow is minimu m inthe sense tha t i ts ma ximum sidelobes a re minimized.

Example N=32;w = blackmanharris(N);plot(w); axis([1 N 0 1]);title('32-point Blackman-harris window');

Algorithm The equation for computing the coefficients of a minimum 4-termB lackman-ha rris window is

where .

5 10 15 20 25 300

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

132−point Blackman−harris window

w k 1+[ ] a 0 a 1 2 π k n 1–------------ -

a 2 4π k n 1–------------ -

cos a 3 6π k n 1–------------ -

cos–+cos–=

0 k n 1–( )≤ ≤

Page 335: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 335/798

7-51

blackmanharris

The coefficients for t his w indow a re

See Also barthannwin , bartlett , blackman , bohmanwin , chebwin , gausswin , hann ,hamming , kaiser , nuttallwin , rectwin , triang , tukeywin , window

References [1] ha rris, f. j. “On th e Use of Windows for H a rmonic Ana lysis wit h t he DiscreteFourier Tra nsform.” Pr oceedi ngs of th e I EE E . Vol. 66 (J a nua ry 1978). pp.51-84.

a 0 = 0.35875

a 1 = 0.48829

a 2 = 0.14128

a 3 = 0.01168

Page 336: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 336/798

7-52

bohmanwin

7bohmanwinPurpose Compute a B ohma n window

Syntax w = bohmanwin(n)

Description w = bohmanwin(n) re turns an n-point B ohma n w indow in column vector w. AB ohma n w indow is th e convolution of tw o half-dura tion cosine lobes. In t hetime doma in, i t is the product of a tr ia ngular window a nd a single cycle of acosine with a term a dded to set t he first derivat ive to zero at the boundary.B ohma n w indows fa ll off as 1/w 4.

Example Compute a 64-point Bohman window.

N=64;w = bohmanwin(N);plot(w); axis([1 N 0 1]);

title('64-point Bohman window');

Algorithm The equa tion for computing t he coefficients of a B ohma n w indow is

10 20 30 40 50 60

0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

164−point Bohman window

Page 337: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 337/798

7-53

bohmanwin

where .

See Also barthannwin , bartlett , blackman , blackmanharris , chebwin , gausswin , hann ,hamming , kaiser , nuttallwin , rectwin , triang , tukeywin , window

References [1] ha rris, f. j. “On th e Use of Windows for H a rmonic Ana lysis wit h t he DiscreteFourier Tra nsform.” Pr oceedi ngs of th e I EE E . Vol. 66 (J a nu a ry 1978). p. 67.

w k 1+[ ] 1.0k N

2----–

N 2----

-------------------– πk N

2----–

N 2----

------------------- 1π--- π

k N 2----–

N 2----

-------------------sin+cos=

0 k N ≤ ≤

Page 338: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 338/798

7-54

buffer

7bufferPurpose B uffer a signa l vector into a ma trix of dat a fra mes

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) part i t ions a length- L signa l vector x into nonoverla pping da tasegments (fra mes) of length n . Ea ch dat a fra me occupies one column of ma tr ixoutput y , which ha s n rows a nd ceil(L/n) columns. If L is not evenly divisibleby n , the la st column is zero-pad ded to length n .

y = buffer(x,n,p) overlaps or und erlaps successive frames in t he outputmat r ix by p samples:

• For 0 < p < n (overlap), buffer repeat s the fina l p sam ples of each frame a tth e beginnin g of the following fra me. For example, if x = 1:30 a nd n = 7 , a noverlap of p = 3 looks like th is.

The first fra me start s with p zeros (th e defa ult init ial condit ion), an d th enumber of columns in y is ceil(L/(n-p)) .

y =0 2 6 10 14 18 22 260 3 7 11 15 19 23 270 4 8 12 16 20 24 281 5 9 13 17 21 25 292 6 10 14 18 22 26 303 7 11 15 19 23 27 04 8 12 16 20 24 28 0

Page 339: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 339/798

7-55

buffer

• For p < 0 (underlap), buffer skips p sa mples betw een consecut ive fra mes.For exam ple, if x = 1:30 a nd n = 7 , a buffer with un derlap of p = -3 looks likethis.

The n umber of column s in y is ceil(L/(n-p)) .

y = buffer(x,n,p,opt) specifies a vector of sam ples to precede x(1) in an

overla pping buffer, or the number of initia l sam ples to skip in a n und erlappingbuffer:

• For 0 < p < n (overlap), opt specifies a length- p vector t o insert before x(1) inth e buffer. This vector can be considered a n i n i t i a l cond i t ion , w hich is neededw hen t he current buffering opera tion is one in a sequence of consecutivebuffering opera tions. To ma inta in t he desired fra me overla p from one bufferto the next, opt should conta in th e fina l p sa mples of t he previous buffer inth e sequence. See “Continuous B uffering” below.

By defaul t , opt is zeros(p,1) for a n overlapping buffer. Set opt t o'nodelay' to skip the initia l condition an d begin filling t he bufferimmedia tely with x(1) . In th is ca se, L must be length(p) or longer. Forexample, if x = 1:30 a nd n = 7 , a buffer wit h overla p of p = 3 looks like th is.

• For p < 0 (underlap), opt is an integer value in th e range [0,-p] specifying

y =1 11 212 12 223 13 234 14 245 15 256 16 267 17 27

8 18 289 19 29

10 20 30skipped

y =1 5 9 13 17 21 252 6 10 14 18 22 263 7 11 15 19 23 274 8 12 16 20 24 285 9 13 17 21 25 296 10 14 18 22 26 307 11 15 19 23 27 0

Page 340: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 340/798

7-56

the num ber of init ia l input sa mples, x(1:opt) , to skip before a dding sa mples

buffer

to th e buffer. The first va lue in th e buffer is t herefore x(opt+1) . By defaul t ,opt is zero for an underla pping buffer.

This option is especia lly useful w hen t he current buffering opera tion is onein a sequence of consecutive buffering operat ions. To ma inta in t he desiredfra me underla p from one buffer to the next, opt should equa l the differencebetw een the tota l number of points t o skip betw een fra mes ( p) and thenumber of points th a t w ere ava i l ab le to be skipped in t he previous input tobuffer . If the previous input ha d fewer tha n p point s t ha t could be skippeda fter f i ll ing the final fram e of tha t buffer, the rema ining opt points n eed tobe removed from t he first fra me of th e current buffer. See “ContinuousB uffering” below for a n example of how th is works in pract ice.

[y,z] = buffer(...) part i t ions th e length- L signa l vector x into fra mes oflength n , and outputs only the f u l l fram es in y . I f y is a n overlapping buffer, itha s n rows a nd mcolumns, w here

m = floor(L/(n-p)) % When length(opt) = p

or

m = floor((L-n)/(n-p))+1 % When opt = 'nodelay'

I f y is an underlapping buffer, i t ha s n rows a nd mcolumns, w here

m = floor((L-opt)/(n-p)) + (rem((L-opt),(n-p)) >= n)

If t he number of samples in the input vector (a fter t he a ppropriat e overlappingor underla pping opera tions) exceeds the num ber of places ava ilable in th en-by- mbuffer, th e rema ining sa mples in x a re output in vector z , which for a noverla pping buffer has lengt h

length(z) = L - m*(n-p) % When length(opt) = p

or

length(z) = L - ((m-1)*(n-p)+n)% When opt = 'nodelay'

a nd for an underlapping buffer has length

length(z) = (L-opt) - m*(n-p)

Page 341: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 341/798

7-57

buffer

Output z sha res the sa me orienta tion (row or column) as x . If there are norema ining sa mples in th e input a fter th e buffer wit h th e specified overlap orunderla p is filled, z is an empt y vector.

[y,z,opt] = buffer(...) re turns the las t p sa mples of a overlapping buffer inoutput opt . In a n underla pping buffer, opt is the difference betw een th e tota lnumber of points to skip betw een fra mes ( -p ) a nd t he number of points in x t h a t

were ava i l ab le to be skipped aft er filling the la st fra me:• For 0 < p < n (overlap), opt (a s a n output) conta ins the fina l p sa mples in the

las t fra me of th e buffer. This vector can be used as t he i n i t i a l cond i t ion for asubsequent buffering opera tion in a sequence of consecutive bufferingopera tions. This a llows th e desired fra me overlap t o be ma inta ined from onebuffer t o the next. See “Continuous B uffering” below .

• For p < 0 (underlap), opt (a s a n output) is the difference betw een the tota l

number of points t o skip betw een fra mes ( -p ) a nd t he number of points in x t ha t w ere ava i l ab le to be skipped aft er filling the la st fra me.opt = m*(n-p) + opt - L % z is the empty vector.

where opt on the right-ha nd side is the input a rgument t o buffer , and opt on t he left-ha nd side is the output a rgument. H ere m is the num ber ofcolumns in th e buffer, w hich ism = floor((L-opt)/(n-p)) + (rem((L-opt),(n-p))>=n)

Note th a t for a n underla pping buffer output opt is alwa ys zero whenoutput z conta ins dat a .

The opt output for an u nderla pping buffer is especia lly useful wh en thecurrent buffering opera tion is one in a sequence of consecutive bufferingoperations. The opt output from each buffering opera tion specifies t henumber of sa mples t ha t need t o be skipped a t the st a rt of th e next bufferingopera tion to maint a in th e desired frame underlap from one buffer to the

next. If fewer tha n p point s were a va ilable to be skipped a fter filling t he finalframe of the current buffer, the remaining opt points n eed to be removedfrom the first fra me of the next buffer.

In a sequence of buffering operat ions, th e opt output from ea ch operat ionshould be used as t he opt input t o the subsequent buffering operat ion. Thisensures tha t t he desired frame overlap or underlap is ma inta ined from buffer

Page 342: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 342/798

7-58

buffer

to buffer, as w ell as from frame t o fra me within t he same buffer. See“Contin uous Buffering” below for an exa mple of how t his w orks in pra ctice.

Continuous BufferingIn a cont inuous buffering operat ion, th e vector input t o the buffer functionrepresents one fram e in a sequence of frames t ha t ma ke up a discrete signal .These signal fra mes ca n originat e in a fra me-ba sed dat a a cquisition process, or

wit hin a frame-based a lgorithm like the FF T.As a n exam ple, you might a cquire da ta from an A/D ca rd in fra mes of 64sa mples. In t he simplest ca se, you could rebuffer t he da ta into fra mes of 16samples; buffer wi th n = 16 creat es a buffer of four fra mes from each64-element input fra me. The result is t ha t t he signa l of fra me size 64 has beenconverted t o a signa l of fra me size 16; no sa mples w ere add ed or removed.

In the general case w here the original signal fra me size, L, is not equa llydivisible by the new fra me size, n , the overflow from the last fra me needs to becaptur ed a nd r ecycled int o the follow ing buffer. You ca n do th is by itera tivelycalling buffer on input x with the t wo-output-a rgument synt a x.

[y,z] = buffer([z;x],n) % x is a column vector.

[y,z] = buffer([z,x],n) % x is a row vector.

This simply ca ptures a ny buffer overflow in z , and prepends the data to the

subsequent input in the next call t o buffer . Again, t he input signal , x , of fra mesize L, ha s been converted t o a signa l of fra me size n wit hout an y insert ion ordeletion of sam ples.

Note tha t cont inuous buffering ca nnot be done wit h th e single-output synt a xy = buffer(...) , because the last frame of y in th is ca se is zero pa dded, wh icha dds new sa mples to the signal .

Cont inuous buffering in the presence of overla p and un derla p is ha ndled wit ht he opt para meter, wh ich is used a s both a n input and output to buffer . Thefollowing tw o examples demonstra te how the opt parameter should be used.

Page 343: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 343/798

7-59

buffer

Examples Exa mple 1 : Continuous O verla pping BuffersFirst creat e a buffer conta ining 100 fra mes, ea ch with 11 sa mples.

data = buffer(1:1100,11); % 11 samples per frame

Ima gine tha t the fra mes (columns) in th e mat rix called data a re the sequentia loutputs of a da ta a cquisit ion boa rd sa mpling a physica l signa l: data(:,1) isth e first D/A output, cont a ining t he first 11 signal sa mples; data(:,2) is thesecond out put, cont a ining t he next 11 signa l sam ples, a nd so on.

You w an t t o rebuffer this signa l from t he a cquired fra me size of 11 to a framesize of 4 wit h a n overlap of 1. To do this, you w ill repea tedly ca ll buffer t oopera te on each successive input fra me, using the opt para meter to mainta inconsist ency in th e overlap from one buffer t o the next.

Set t he buffer pa ra meters.

n = 4; % New frame sizep = 1; % Overlapopt = -5; % Value of y(1)z = []; % Initialize the carry-over vector.

Now repea tedly call buffer , each t ime passing in a new signa l frame fromdata . Note th a t overflow sa mples (retur ned in z ) a re carried over a ndprepended to th e input in t he subsequent call to buffer .

for i=1:size(data,2), % Loop over each source frame (column).x = data(:,i); % A single frame of the D/A output

[y,z,opt] = buffer([z;x],n,p,opt);

disp(y); % Display the buffer of data.pause

end

Page 344: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 344/798

7-60

buffer

Here’s wh a t h a ppens during the f irst four i terat ions.

Note tha t t he size of the output ma trix, y , ca n va ry by a single column from oneitera tion t o the next. This is ty pica l for buffering opera tions w ith overla p orunderlap.

[1:11]i=1

5– 3 61 4 72 5 8

3 6 9

Iteration Input frame [z;x]' opt (input) opt (output) Output buffer (y) Overflow (z)

[10 11]–5 9

i=2 [10 11 12:22] 9 21

9 12 15 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 345: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 345/798

7-61

buffer

Exa mple 2 : Continuous Underlap ping BuffersAga in crea te a buffer conta ining 100 fra mes, ea ch with 11 samples.

data = buffer(1:1100,11); % 11 samples per frame

Aga in, ima gine tha t data(:,1) is th e first D /A output, conta ining t he first 11signal sa mples; data(:,2) is the second output , conta ining t he next 11 signa lsa mples, a nd so on.

You w an t t o rebuffer this signa l from t he a cquired fra me size of 11 to a framesize of 4 wit h a n un derla p of 2. To do this, you will repeat edly call buffer t oopera te on each successive input fra me, using the opt para meter to mainta inconsist ency in the un derla p from one buffer to the next.

Set t he buffer pa ra meters.

n = 4; % New frame size

p = -2; % Underlapopt = 1; % Skip the first input element, x(1).z = []; % Initialize the carry-over vector.

Now repea tedly call buffer , each t ime passing in a new signa l frame fromdata . Note th a t overflow sa mples (retur ned in z ) a re carried over a ndprepended to th e input in t he subsequent call to buffer .

for i=1:size(data,2), % Loop over each source frame (column).

x = data(:,i); % A single frame of the D/A output

[y,z,opt] = buffer([z;x],n,p,opt);

disp(y); % Display the buffer of data.pause

end

Page 346: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 346/798

7-62

buffer

Here’s wha t ha ppens during the f irst t hree itera tions.

Diagnostics Er ror messages a re displayed w hen p ≥n or length(opt) ≠ length(p) i n anoverla pping buffer case.

Frame overlap P must be less than the buffer size N.Initial conditions must be specified as a length-P vector.

See Also reshape

[1:11]i=1

2 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 014151617

[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

Page 347: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 347/798

7-63

buttap

7buttapPurpose B utt erworth a na log lowpa ss fil ter prototype

Syntax [z,p,k] = buttap(n)

Description [z,p,k] = buttap(n) returns t he poles a nd ga in of an order n Butterwortha na log low pas s filter prototype. The function return s th e poles in t he length n column vector p and the gain in scala r k . z is an empty ma trix beca use there

a re no zeros. The tr a nsfer function is

B utt erworth fi lters ar e cha ra cterized by a ma gnitude response tha t isma xima lly flat in the passba nd a nd monotonic overall . In the lowpa ss ca se, thefirst 2n–1 deriva tives of the squa red ma gnit ude response a re zero a t ω = 0. Thesquared magnitude response function is

corresponding t o a tr a nsfer function with poles equa lly spaced around a circlein th e left ha lf plan e. The ma gnit ude response a t t he cutoff frequency ω0 isa lwa ys regardless of the f i lter order. buttap sets ω0 to 1 for a norma lizedresult .

Algorithm z = [];p = exp(sqrt(-1)*(pi*(1:2:2*n-1)/(2*n)+pi/2)).';k = real(prod(-p));

See Also besselap , butter , cheb1ap , cheb2ap , ellipap

References [1] P a rks, T.W., a nd C .S. B urrus. Di gi ta l F i l ter D esign . New York: J ohn Wiley& Sons, 1987. Cha pter 7.

H s ( ) z s ( )p s ( )---------- k

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

H ω( ) 2 11 ω ω0 ⁄ ( )2 n +----------------------------------- -=

1 2 ⁄

Page 348: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 348/798

7-64

butter

7butterPurpose B utt erworth an a log and digital f i lter 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 lowpa ss, ban dpass, highpass, and ban dstop digita l and a na logB utt erworth fil ters. B utt erworth fil ters are cha ra cterized by a ma gnituderesponse tha t is ma ximally fla t in t he passban d a nd monotonic overall .

B utt erwort h filters sa crifice rolloff steepness for monotonicity in t he pass- andstopba nds. U nless th e smoothn ess of the B utt erworth fi l ter is needed, an

elliptic or Chebyshev filter can genera lly provide st eeper rolloff cha ra cteristicswit h a lower fi l ter order.

Digital Domain

[b,a] = butter(n,Wn) designs an order n lowpa ss digita l Butt erworth fi lterw ith cutoff frequency Wn . It r eturn s th e filter coefficient s in length n+1 row vectors b a nd a , w ith coefficients in descending powers of z .

Cu toff fr equency is tha t frequency wh ere the ma gnitude response of the fi lteris . For butter , th e norma lized cutoff frequency Wn must be a n umberbetw een 0 a nd 1, w here 1 corresponds t o the Nyq uist frequency, π radians persample.

I f Wn is a tw o-element vector, Wn = [w1 w2] , butter returns a n order 2*n digi ta lbandpass f i lter wi th passban d w1 < ω < w2.

H z ( ) B z ( )A z ( )----------- b 1( ) b 2( ) z 1– L b n 1+( ) z n –+ + +

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

1 2 ⁄

Page 349: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 349/798

7-65

butter

[b,a] = butter(n,Wn,' ftype ') designs a highpass or ban dstop fil ter, wherethe str ing ' ftype ' is either:

• 'high' for a highpass digital filter with cutoff frequency Wn• 'stop' for a n order 2*n bandst op digita l f i lter if Wn is a tw o-element vector,

Wn = [w1 w2] . The stopband is w1 < ω < w2.

With different numbers of output arguments, butter directly obtains otherrealizations of the filter. To obtain zero-pole-gain form, use three outputa rguments a s shown below.

[z,p,k] = butter(n,Wn) or

[z,p,k] = butter(n,Wn,' ftype ') retur ns th e zeros and poles in lengt h n column vectors z a nd p , and t he gain in the scala r k .

To obta in sta te-spa ce form, use four output a rgument s a s shown below.

[A,B,C,D] = butter(n,Wn) or

[A,B,C,D] = butter(n,Wn,' ftype ') where A , B, C, and D a re

a nd u is the input, x is the sta te vector, and y is the output.

Analog Domain

[b,a] = butter(n,Wn,' s ') designs an order n lowpass ana log B ut terworthfilter wit h cutoff frequency Wn ra d/s. It retur ns t he filter coefficients in t helength n+1 row vectors b a nd a , in descending powers of s, derived from th etra nsfer function

butter ’s cutoff freq uency Wn must be great er tha n 0 ra d/s.

I f Wn is a tw o-element vector w ith w1 < w2, butter(n,Wn,' s ') returns a n order2*n bandpass a nalog fi lte r w i th passband w1 < ω < w2.

x n 1+[ ] A x n [ ] B u n [ ]+=

y n [ ] C x n [ ] D u n [ ]+=

H s ( ) B s ( )A s ( )----------- b 1( ) s n b 2( ) s n 1– L b n 1+( )+ + +

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

Page 350: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 350/798

7-66

butter

[b,a] = butter(n,Wn,' ftype ',' s ') designs a highpass or ban dstop fi l ter.

With different numbers of output arguments, butter directly obta ins oth errea lizat ions of t he a na log filter. To obta in zero-pole-ga in form, use t hree outputa rguments a s shown below.

[z,p,k] = butter(n,Wn,' s ') or

[z,p,k] = butter(n,Wn,' ftype ',' s ') retur ns th e zeros and poles in lengt hn or 2*n column vectors z a nd p and t he gain in the scala r k .

To obta in sta te-space form, use four output a rgument s a s shown below.

[A,B,C,D] = butter(n,Wn,' s ') or

[A,B,C,D] = butter(n,Wn,' ftype ',' s ') where A , B, C, and D a re

a nd u is the input, x is the sta te vector, and y is the output.

Examples Exa mple 1For dat a sampled at 1000 Hz, design a 9th-order highpass B utt erworth fi lterw ith cutoff frequency of 300 H z.

[b,a] = butter(9,300/500,'high');

The filt er ’s frequen cy response is

freqz(b,a,128,1000)

x · A x B u +=y C x D u +=

Page 351: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 351/798

7-67

butter

Exa mple 2Design a 10th-order bandpa ss B utt erworth fi l ter with a passban d from 100 to200 Hz a nd plot its impulse response, or un i t sam pl e r esponse.

n = 5; Wn = [100 200]/500;[b,a] = butter(n,Wn);[y,t] = impz(b,a,101);stem(t,y)

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

−600

−400

−200

0

200

Frequency (Hz)

P h a s e

( d e g r e e s

)

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

−300

−200

−100

0

100

Frequency (Hz)

M a g n

i t u d e

( d B )

0 10 20 30 40 50 60 70 80 90 100−0.25

−0.2

−0.15

−0.1

−0.05

0

0.05

0.1

0.15

0.2

Page 352: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 352/798

7-68

butter

Limitations For high order filters, th e sta te-space form is the most num erica lly accurat e,follow ed by t he zero-pole-ga in form. The t ra nsfer fu nction coefficient form isth e least a ccura te; numerical problems ca n a rise for filter orders a s low a s 15.

Algorithm butter uses a five-step a lgorith m:

1 It f inds the lowpa ss a na log prototype poles, zeros, and ga in using th e buttap function.

2 It converts t he poles, zeros, an d ga in into sta te-spa ce form.

3 It tra nsforms th e lowpass fi l ter into a band pass, highpass, or ban dstop fi l terwith desired cutoff frequencies, using a state-space transformation.

4 For digital filter design, butter uses bilinear to convert th e ana log filterinto a digita l f il ter through a bilinear t ra nsforma tion with frequencyprewar ping. Ca reful frequency ad justment gua ra ntees tha t th e a na logfilters a nd t he digital f i lters w ill have the sa me frequency responsemagni tude a t Wn or w1 a nd w2.

5 It converts th e sta te-spa ce filter ba ck to tr a nsfer fun ction or zero-pole-ga inform, as required.

See Also besself , buttap , buttord , cheby1 , cheby2 , ellip , maxflat

Page 353: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 353/798

7-69

buttord

7buttordPurpose Ca lculat e the order a nd cutoff frequency for a B utt erworth fi l ter

Syntax [n,Wn] = buttord(Wp,Ws,Rp,Rs)[n,Wn] = buttord(Wp,Ws,Rp,Rs,' s ')

Description buttord calculat es the minimum order of a digita l or a na log B utt erworth fi l terrequired t o meet a set of filter design specifica tions.

Digital Domain

[n,Wn] = buttord(Wp,Ws,Rp,Rs) returns the lowest order, n , of the digita lB utt erworth fi lter tha t loses no more tha n Rp dB in the passband and has a tleast Rs dB of a tt enua tion in t he stopban d. The scala r (or vector) ofcorresponding cutoff frequencies, Wn , is also returned. Use th e outputarguments n a nd Wn in butter .

Choose the input a rguments t o specify the stopba nd a nd pa ssband a ccording toth e follow ing ta ble.

Table 7-1: Description of Stopband and Passband Filter Parameters

Wp Pa ssband corner frequency Wp , th e cut off frequency, is a scala ror a tw o-element vector with va lues betw een 0 and 1, with 1corresponding to t he norma lized Nyq uist fr equency, π r ad ians

per sa mple. Ws St opba nd corner frequency Ws , is a scala r or a t wo-element

vector w ith va lues betw een 0 a nd 1, with 1 corresponding t oth e norma lized Nyqu ist frequency.

Rp Pa ssba nd ripple, in decibels. This va lue is the ma ximumpermissible pas sba nd loss in decibels.

Rs St opba nd a tt enua tion, in decibels. This va lue is th e number ofdecibels the st opband is down from th e passban d.

Page 354: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 354/798

7-70

buttord

U se th e follow ing guide t o specify filters of different types.

If your fi l ter specifications ca ll for a bandpa ss or bandst op fi lter w ith u nequalripple in ea ch of the pa ssbands or st opbands, design sepa ra te lowpa ss a ndhighpass fi l ters a ccording t o the specifications in t his ta ble, a nd cascad e thetw o fil ters together.

Analog Domain

[n,Wn] = buttord(Wp,Ws,Rp,Rs,' s ') finds th e minimum order n a nd cutofffrequencies Wn for a n a na log Bu tt erwort h filter. You specify the frequencies Wp a nd Ws simila r to Ta ble 7-1 , only in th is case you specify th e frequency inra dians per second, a nd t he passban d or the stopba nd can be infinite.

U se buttord for lowpass, highpass, ba ndpass, a nd ba ndstop fi lters a s describedin Ta ble 7-2 .

Table 7-2: Filter Type Stopband and Passband Specifications

Filter Type Stopband and Passband Conditions Stopband Passband

Lowpass Wp < Ws , both scala rs (Ws,1) (0,Wp)

Highpass Wp > Ws , both scala rs (0,Ws) (Wp,1)

B andpa ss The in t erva l specified by Ws containsth e one specified by Wp ( Ws(1) < Wp(1) < Wp(2) < Ws(2) ).

(0,Ws(1)) a nd(Ws(2),1)

(Wp(1),Wp(2))

B andst op The in t erva l specified by Wp containsth e one specified by Ws ( Wp(1) < Ws(1) < Ws(2) < Wp(2) ).

(0,Wp(1)) a nd(Wp(2),1)

(Ws(1),Ws(2))

Page 355: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 355/798

7-71

buttord

Examples Exa mple 1For da ta sampled a t 1000 Hz, des ign a lowpass f i lter wi th less tha n 3 dB ofripple in the passband , defined from 0 to 40 Hz, a nd a t least 60 dB ofa tt enuat ion in t he stopband, defined from 150 Hz t o the Nyquist frequency(500 Hz). Plot th e filter ’s frequency response.

Wp = 40/500; Ws = 150/500;[n,Wn] = buttord(Wp,Ws,3,60)

n =5

Wn =0.0810

[b,a] = butter(n,Wn);freqz(b,a,512,1000); title('n=5 Butterworth Lowpass Filter')

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

−400

−300

−200

−100

0

Frequency (Hz)

P h a s e

( d e g r e e s )

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

−300

−200

−100

0

100

Frequency (Hz)

M a g n

i t u d e

( d B )

n=5 Butterworth Lowpass Filter

Page 356: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 356/798

7-72

buttord

Exa mple 2Next des ign a bandpass f i lter wi th pa ssband of 60 Hz to 200 Hz, wi th less than3 dB of r ipple in the passband, and 40 dB a t tenuat ion in the s topbands t hat are50 Hz w ide on both sides of the passban d.

Wp = [60 200]/500; Ws = [50 250]/500;Rp = 3; Rs = 40;[n,Wn] = buttord(Wp,Ws,Rp,Rs)

n =16

Wn =0.1198 0.4005

[b,a] = butter(n,Wn);freqz(b,a,128,1000)title('n=16 Butterworth Bandpass Filter')

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

−2000

−1500

−1000

−500

0

500

Frequency (Hz)

P h a s e

( d e g r e e s

)

0 50 100 150 200 250 300 350 400 450 500

−500

−400

−300

−200

−100

0

100

Frequency (Hz)

M a g n

i t u d e

( d B )

n=16 Butterworth Bandpass Filter

Page 357: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 357/798

7-73

buttord

Algorithm buttord ’s order prediction formula is described in [1]. It opera tes in th e a na logdomain for both a na log a nd digita l cases. For the digita l ca se, it converts th efrequency pa ra meters to the s -doma in before est imating t he order a nd na tura lfrequency, and then converts ba ck to the z -domain.

buttord initia lly develops a lowpass filter prototype by tra nsforming th epassba nd frequencies of th e desired filter to 1 ra d/s (for low pass a nd highpa ssfilters) a nd t o -1 a nd 1 ra d/s (for ba ndpa ss a nd ba ndst op filters). It t hencomputes th e minimum order required for a low pass filter t o meet th e stopba ndspecification.

See Also butter , cheb1ord , cheb2ord , ellipord , kaiserord

References [1] Ra biner, L.R., an d B . G old. Th eory and Appl i cat ion of Di gi ta l Si gnal Processing . Englew ood Cliffs, NJ : Pr entice-Ha ll, 1975. Pg . 227.

Page 358: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 358/798

7-74

cceps

7ccepsPurpose Complex cepstra l a na lysis

Syntax xhat = cceps(x)[xhat,nd] = cceps(x)[xhat,nd,xhat1] = cceps(x)[...] = cceps(x,n)

Description Cepstra l an alysis is a nonlinear signa l processing technique tha t is appliedmost commonly in speech processing a nd h omomorphic filt ering [1].

xhat = cceps(x) retur ns t he complex cepstrum of th e (a ssumed rea l)sequence x . The input is alt ered, by the a pplicat ion of a linea r pha se term, toha ve no phase discontinuity a t ±πra dia ns. Tha t is, it is circularly shift ed (a fterzero pa dding) by some sa mples, if necessa ry, t o have zero phase a t π r ad ians .

[xhat,nd] = cceps(x) returns t he number of samples nd of (circular ) delayadded to x prior t o finding t he complex cepstrum.

[xhat,nd,xhat1] = cceps(x) retur ns a second complex cepstrum, computedusing an a lternat e rooting algorithm, in xhat1 . The alt erna te meth od([1] p.795) is useful for short sequ ences t ha t can be rooted a nd d o not ha ve zeroson the un it circle. For t hese signa ls, xhat1 can provide a verificat ion of xhat .

[...] = cceps(x,n) zero pad s x to length n a nd returns the length n complexcepstru m of x .

Algorithm cceps , in its basic form, is an M-file implementation of algorithm 7.1 in [2]. Alength y Fort ra n progra m 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 special version of unwrap tha t subtracts a s t ra ight l ine from thephase.

See Also icceps , hilbert , rceps , unwrap

References [1] Oppenheim, A.V., a nd R.W. Scha fer. D i scr ete-Ti m e Si gnal Pr ocessi ng .U pper Sa ddle River, NJ : P rent ice-H a ll, 1999, pp. 788-789.

Page 359: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 359/798

7-75

cceps

[2] IE E E. Program s for Di gital Signal Pr ocessin g . IEE E P ress. New York: J ohnWiley & Sons, 1979.

Page 360: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 360/798

7-76

cell2sos

7cell2sosPurpose Convert a cell a rra y for second-order sections t o a second-order section ma tr ix

Syntax m = cell2sos(c)

Description m = cell2sos(c) chan ges a 1-by- L cell arra y c consis tin g of 1-by-2 cell a rr a ysinto an L -by-6 second -order section m a tr ix m. Matr ix m ta kes the sam e form a sthe ma trix generat ed by tf2sos . You can use m = cell2sos(c) to invert t he

results of c = sos2cell(m) .c must be a cell a rra y of the form

c = b1 a1 b2 a2 ... bL aL

w here both bi a nd ai a re row vectors of at most length 3, an d i = 1, 2, ..., L . Theresult ing matrix m is given by

m = [b1 a1;b2 a2; ... ;bL aL]

See Also sos2cell , tf2sos

Page 361: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 361/798

7-77

cheb1ap

7cheb1apPurpose Ch ebyshev Type I an a log low pass filter prototype

Syntax [z,p,k] = cheb1ap(n,Rp)

Description [z,p,k] = cheb1ap(n,Rp) returns t he poles a nd ga in of an order n ChebyshevType I an a log low pass filter prototype wit h Rp dB of ripple in th e passba nd. Thefunction return s the poles in the lengt h n column vector p an d the gain in

scalar k . z is an empt y ma tr ix, beca use there a re no zeros. The tra nsferfunction is

Ch ebyshev Type I filters a re equiripple in the pass ban d a nd monotonic in th estopban d. The poles are evenly spaced a bout a n ellipse in th e left h a lf plane.The Ch ebyshev Type I cutoff frequency is set to 1.0 for a norma lized result.

This is the frequency a t w hich th e pa ssband ends a nd th e fi l ter ha s ma gnituderesponse of 10 -Rp/20 .

See Also besselap , buttap , cheby1 , cheb2ap , ellipap

References [1] P a rks, T.W., a nd C .S. B urru s. Di gi ta l F i l ter D esign . New York: J ohn Wiley& Sons, 1987. Cha pter 7.

H s ( ) z s ( )p s ( )---------- k

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

ω0

Page 362: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 362/798

7-78

cheb1ord

7cheb1ordPurpose Ca lcula te t he order for a C hebyshev Type I filter

Syntax [n,Wn] = cheb1ord(Wp,Ws,Rp,Rs)[n,Wn] = cheb1ord(Wp,Ws,Rp,Rs,' s ')

Description cheb1ord calculat es the minimum order of a digita l or a na log ChebyshevType I filter requ ired to meet a set of filter design specifica tions.

Digital Domain

[n,Wn] = cheb1ord(Wp,Ws,Rp,Rs) returns the lowest order n of th e ChebyshevType I filter tha t loses no more tha n Rp dB in the passband a nd has a t leas tRs dB of at tenua tion in t he st opban d. The scala r (or vector) of correspondingcutoff frequencies Wn , is also return ed. Use the output a rguments n a nd Wn wi tht he cheby1 function.

Choose the input a rguments t o specify the stopba nd a nd pa ssband a ccording toth e follow ing ta ble.

Table 7-3: Description of Stopband and Passband Filter Parameters

Wp Pa ssband corner frequency Wp , th e cut off frequency, is a scala ror a tw o-element vector with va lues betw een 0 a nd 1, with 1corresponding to t he norma lized Nyq uist frequency, π r ad ians

per sa mple. Ws St opban d corner frequency Ws , is a scala r or a t wo-element

vector w ith va lues betw een 0 an d 1, with 1 corresponding toth e norma lized Nyqu ist frequency.

Rp Pa ssba nd r ipple, in decibels. This va lue is the ma ximumpermissible pa ssba nd loss in decibels.

Rs St opban d a tt enua tion, in decibels. This va lue is th e number ofdecibels the stopband is down from the passband.

Page 363: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 363/798

7-79

cheb1ord

U se th e followin g guide t o specify filters of different t ypes

If your filter specifica tions call for a ba ndpa ss or ban dstop filter wit h unequa lripple in each of the passba nds or stopba nds, design separa te lowpa ss a ndhighpass filters according to the specifications in this table, and cascade thetw o fi lters t ogether.

Analog Domain

[n,Wn] = cheb1ord(Wp,Ws,Rp,Rs,' s ') finds th e minimum order n a nd cutofffrequencies Wn for a n a na log Ch ebyshev Type I filter. You specify t hefrequencies Wp a nd Ws similar t o Ta ble 7-3 , only in t his case you specify th efrequency in radia ns per second, a nd t he passban d or the stopban d can beinfinite.

U se cheb1ord for lowpa ss, highpass, ban dpass, a nd ba ndstop fi l ters a sdescribed in Ta ble 7-4 .

Examples For da ta sampled a t 1000 Hz, des ign a lowpass f i lter wi th less tha n 3 dB ofripple in the passba nd defined from 0 to 40 Hz a nd a t least 60 dB of r ipple inth e stopba nd defined from 150 Hz t o the Nyquist frequency (500 Hz).

Wp = 40/500; Ws = 150/500;Rp = 3; Rs = 60;[n,Wn] = cheb1ord(Wp,Ws,Rp,Rs)

Table 7-4: Filter Type Stopband and Passband Specifications

Filter Type Stopband and Passband Conditions Stopband Passband

Lowpass Wp < Ws , both sca lars (Ws,1) (0,Wp)

Highpass Wp > Ws , both sca lars (0,Ws) (Wp,1)

B andpa ss The in t erva l specified by Ws containsth e one specified by Wp ( Ws(1) < Wp(1) < Wp(2) < Ws(2) ).

(0,Ws(1)) a nd(Ws(2),1)

(Wp(1),Wp(2))

B andst op The in t erva l specified by Wp containsth e one specified by Ws ( Wp(1) < Ws(1) < Ws(2) < Wp(2) ).

(0,Wp(1)) a nd(Wp(2),1)

(Ws(1),Ws(2))

Page 364: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 364/798

7-80

cheb1ord

n =4

Wn =0.0800

[b,a] = cheby1(n,Rp,Wn);freqz(b,a,512,1000);title('n=4 Chebyshev Type I Lowpass Filter')

Next des ign a bandpass f i lter wi th a passban d of 60 Hz t o 200 Hz, wi th lesstha n 3 dB of r ipple in the passband, and 40 dB a t tenuat ion in the s topbandstha t a re 50 Hz w ide on both sides of the pa ssband.

Wp = [60 200]/500; Ws = [50 250]/500;Rp = 3; Rs = 40;[n,Wn] = cheb1ord(Wp,Ws,Rp,Rs)

n =7

Wn =0.1200 0.4000

[b,a] = cheby1(n,Rp,Wn);freqz(b,a,512,1000);title('n=7 Chebyshev Type I Bandpass Filter')

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

−300

−200

−100

0

Frequency (Hz)

P h a s e

( d e g r e e s )

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

−250

−200

−150

−100

−50

0

Frequency (Hz)

M a g n

i t u d e

( d B )

n=4 Chebyshev Type I Lowpass Filter

Page 365: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 365/798

7-81

cheb1ord

Algorithm cheb1ord uses th e Chebyshev lowpa ss filter order prediction formula describedin [1]. The function performs it s calculat ions in th e a na log doma in for botha na log a nd digita l cases. For t he digital case, i t converts th e frequencypara meters to the s -domain before the order a nd na tu ra l frequency estima tionprocess, and t hen converts t hem back to the z -domain.

cheb1ord initially develops a lowpass filter prototype by transforming thepas sba nd frequencies of th e desired filter t o 1 ra d/s (for low - or highpa ss filters)or to -1 an d 1 ra d/s (for ba ndpa ss or ba ndst op filters). It th en comput es theminimum order requir ed for a lowpa ss filter to meet th e stopba nd specifica tion.

See Also buttord , cheby1 , cheb2ord , ellipord , kaiserord

References [1] Ra biner, L.R., an d B . G old. Th eory and Appl i cat ion of Di gi ta l Si gnal Processing . Englew ood Cliffs, NJ : Pr entice-Ha ll, 1975. Pg . 241.

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

−1000

−500

0

500

Frequency (Hz)

P h a s e

( d e g r e e s

)

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

−400

−300

−200

−100

0

Frequency (Hz)

M a g n

i t u d e

( d B )

n=7 Chebyshev Type I Bandpass Filter

Page 366: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 366/798

7-82

cheb2ap

7cheb2apPurpose Ch ebyshev Type II a na log low pas s filter prototy pe

Syntax [z,p,k] = cheb2ap(n,Rs)

Description [z,p,k] = cheb2ap(n,Rs) finds t he zeros, poles, and ga in of an order n Ch ebyshev Type II a na log low pass filter prototype with s topban d ripple Rs dBdown from th e pa ssband peak va lue. cheb2ap retur ns t he zeros a nd poles inlength n column vectors z a nd p and the gain in scala r k . I f n is odd, z is lengt hn-1 . The t ra nsfer function is

Ch ebyshev Type II filters a re monotonic in t he passba nd a nd equiripple in th estopband. The pole locations are the inverse of the pole locations of cheb1ap ,w hose poles ar e evenly spaced a bout a n ellipse in th e left h a lf pla ne. The

Chebyshev Type II cutoff frequency ω0 is set t o 1 for a norma lized result . Thisis the frequency at w hich th e stopband begins a nd th e fi l ter has ma gnituderesponse of 10 -Rs/20 .

Algorithm Ch ebyshev Type II filters a re sometimes called i nv er se Ch ebyshev filtersbeca use of th eir relat ionship t o Chebyshev Type I filters. The cheb2ap functionis a modificat ion of the Ch ebyshev Type I prototype algorithm :

1 cheb2ap replaces the frequency variable ω with 1/ω, turning th e lowpa ssfilter into a highpa ss filter while preserving th e performa nce a t ω = 1.

2 cheb2ap subtra cts the fi lter tr a nsfer function from unity.

See Also besselap , buttap , cheb1ap , cheby2 , ellipap

References [1] P a rks, T.W., an d C .S. B urru s. Di gi ta l F i l ter D esign . New York: J ohn Wiley& Sons, 1987. Cha pter 7.

H s ( ) z s ( )p s ( )---------- k

s z 1( )–( ) s z 2( )–( )L s z n ( )–( )s p 1( )–( ) s p 2( )–( )L s p n ( )–( )--------------------------------------------------------------------------------= =

Page 367: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 367/798

7-83

cheb2ord

7cheb2ordPurpose Ca lcula te t he order for a C hebyshev Type II filter

Syntax [n,Wn] = cheb2ord(Wp,Ws,Rp,Rs)[n,Wn] = cheb2ord(Wp,Ws,Rp,Rs,' s ')

Description cheb2ord calculat es the minimum order of a digita l or a na log ChebyshevType II filt er required to meet a set of filter design specifica tions.

Digital Domain

[n,Wn] = cheb2ord(Wp,Ws,Rp,Rs) returns the lowest order n of th e ChebyshevType II filter th a t loses no more tha n Rp dB in the passband a nd has a t leas tRs dB of at tenua tion in t he st opba nd. The scala r (or vector) of correspondingcutoff frequencies Wn , is also returned. Use the output a rguments n a nd Wn incheby2 .

Choose the input a rguments t o specify the stopba nd a nd pa ssband a ccording toth e follow ing ta ble.

Table 7-5: Description of Stopband and Passband Filter Parameters

Wp Pa ssband corner frequency Wp , th e cut off frequency, is a scala ror a tw o-element vector with va lues betw een 0 and 1, with 1corresponding to t he norma lized Nyq uist fr equency, π r ad ians

per sa mple. Ws St opba nd corner frequency Ws , is a scala r or a t wo-element

vector w ith va lues betw een 0 a nd 1, with 1 corresponding t oth e norma lized Nyqu ist frequency.

Rp Pa ssba nd ripple, in decibels. This va lue is the ma ximumpermissible pas sba nd loss in decibels.

Rs St opba nd a tt enua tion, in decibels. This va lue is th e number ofdecibels the st opband is down from th e passban d.

Page 368: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 368/798

7-84

cheb2ord

U se th e follow ing guide t o specify filters of different types.

If your fi l ter specifications ca ll for a bandpa ss or bandst op fi lter w ith u nequalripple in ea ch of the pa ssbands or st opbands, design sepa ra te lowpa ss a ndhighpass fi l ters a ccording t o the specifications in t his ta ble, a nd cascad e thetw o fil ters together.

Analog Domain

[n,Wn] = cheb2ord(Wp,Ws,Rp,Rs,' s ') finds th e minimum order n a nd cutofffrequencies Wn for a n a na log Ch ebyshev Type II filter. You specify th efrequencies Wp a nd Ws simila r to Ta ble 7-5, only in this ca se you specify th efrequency in radia ns per second, and t he passban d or the stopba nd can beinfinite.

U se cheb2ord for lowpa ss, highpass, ban dpass, a nd ba ndstop fi l ters asdescribed in Ta ble 7-6 .

Table 7-6: Filter Type Stopband and Passband Specifications

Filter Type Stopband and Passband Conditions Stopband Passband

Lowpass Wp < Ws , both scala rs (Ws,1) (0,Wp)

Highpass Wp > Ws , both scala rs (0,Ws) (Wp,1)

B andpa ss The in t erva l specified by Ws containsth e one specified by Wp ( Ws(1) < Wp(1) < Wp(2) < Ws(2) ).

(0,Ws(1)) a nd(Ws(2),1)

(Wp(1),Wp(2))

B andst op The in t erva l specified by Wp containsth e one specified by Ws ( Wp(1) < Ws(1) < Ws(2) < Wp(2) ).

(0,Wp(1)) a nd(Wp(2),1)

(Ws(1),Ws(2))

Page 369: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 369/798

7-85

cheb2ord

Examples Exa mple 1For da ta sampled a t 1000 Hz, des ign a lowpass f i lter wi th less tha n 3 dB ofripple in the passband defined from 0 to 40 Hz, an d at lea st 60 dB ofa tt enuat ion in the stopba nd defined from 150 Hz t o the Nyquist frequency(500 Hz).

Wp = 40/500; Ws = 150/500;Rp = 3; Rs = 60;

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

n =4

Wn =0.2597

[b,a] = cheby2(n,Rs,Wn);

freqz(b,a,512,1000);title('n=4 Chebyshev Type II Lowpass Filter')

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

−300

−200

−100

0

100

Frequency (Hz)

P h a s e

( d e g r e e s )

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

−100

−80

−60

−40

−20

0

Frequency (Hz)

M a g n

i t u d e

( d B )

n=4 Chebyshev Type II Lowpass Filter

Page 370: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 370/798

7-86

cheb2ord

Exa mple 2Next des ign a bandpass f i lter wi th a passban d of 60 Hz t o 200 Hz, wi th lesstha n 3 dB of r ipple in the passband, and 40 dB a t tenuat ion in the s topbandstha t a re 50 Hz w ide on both sides of the pa ssband.

Wp = [60 200]/500; Ws = [50 250]/500;Rp = 3; Rs = 40;[n,Wn] = cheb2ord(Wp,Ws,Rp,Rs)

n =7

Wn =0.1019 0.4516

[b,a] = cheby2(n,Rs,Wn);freqz(b,a,512,1000)

title('n=7 Chebyshev Type II Bandpass Filter')

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

−200

0

200

400

Frequency (Hz)

P h a s e

( d e g r e e s )

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

−250

−200

−150

−100

−50

0

50

Frequency (Hz)

M a g n

i t u d e

( d B )

n=7 Chebyshev Type II Bandpass Filter

Page 371: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 371/798

7-87

cheb2ord

788

Algorithm cheb2ord uses th e Chebyshev lowpa ss filter order prediction formula describedin [1]. The function performs it s calculat ions in th e a na log doma in for botha na log a nd digita l cases. For t he digital case, i t converts th e frequencypara meters to the s -domain before the order a nd na tu ra l frequency estima tionprocess, and t hen converts t hem back to the z -domain.

cheb2ord initially develops a lowpass filter prototype by transforming thestopban d frequ encies of the desired filter t o 1 rad/s (for low- an d h ighpa ss

filters) a nd t o -1 and 1 rad /s (for ba ndpa ss a nd ba ndst op filters). It th encomput es the minimum order required for a lowpa ss filter to meet th epassband specification.

See Also buttord , cheb1ord , cheby2 , ellipord , kaiserord

References [1] Ra biner, L.R., an d B . G old. Th eory and Appl i cat ion of Di gi ta l Si gnal Processing . Englew ood Cliffs, NJ : Pr entice-Ha ll, 1975. Pg . 241.

Page 372: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 372/798

7-88

chebwin

789

7chebwinPurpose Compute a Chebyshev w indow

Syntax w = chebwin(n,r)

Description w = chebwin(n,r) retur ns t he column vector w conta ining the length n Ch ebyshev win dow wh ose Fourier tra nsform sidelobe magn itude is r dB below the ma inlobe magnitude.

Note If you specify a one-point window (set n=1 ), th e value 1 is returned.

Examples N=64;w = chebwin(N,100);plot(w); axis([1 N 0 1]);

title('Chebyshev Window')

See Also barthannwin , bartlett , blackman , blackmanharris , bohmanwin , gausswin ,hamming , hann , kaiser , nuttallwin , rectwin , triang , tukeywin , window

References [1] IE EE . Program s for Di gital Signal Processin g . IEE E P ress. New York: J ohnWiley & Sons, 1979. P rogra m 5.2.

10 20 30 40 50 600

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1Chebyshev Window

Page 373: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 373/798

7-89

cheby1

7-90

7cheby1Purpose Ch ebyshev Type I filter design (pass ba nd 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 lowpa ss, band pass, highpa ss, and ban dstop digital a nd a na logCh ebyshev Type I filters. C hebyshev Type I filters a re equiripple in th epas sba nd a nd monotonic in the st opba nd. Type I filters roll off fast er tha ntype II f i l ters, but a t t he expense of greater devia tion from unity in t hepassband.

Digital Domain[b,a] = cheby1(n,Rp,Wn) designs an order n Chebyshev lowpa ss digita lCh ebyshev filter w ith cut off frequency Wn a nd Rp dB of peak-t o-peak ripple inthe pa ssband. I t returns the fi l ter coefficients in t he length n+1 row vectors b a nd a , w ith coefficient s in descending pow ers of z .

Cu toff fr equency is the frequency at w hich the ma gnitu de response of th e filteris equa l to -Rp dB . For cheby1 , th e cutoff frequency Wn is a n umber betw een 0a nd 1, wh ere 1 corresponds to th e Nyquist frequency, π ra dians per sample.Sma ller va lues of passband ripple Rp lead to wider tra nsit ion w idths (sha llowerrolloff char a cteristics).

I f Wn is a tw o-element vector, Wn = [w1 w2] , cheby1 returns a n order 2*n

bandpass f i lter w i th passband w1 < < w2.

H z ( ) B z ( )A z ( )----------- b 1( ) b 2( ) z 1– L b n 1+( ) z n –+ + +

1 a 2( ) z 1– L

a n 1+( ) z n –

+ + +

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

ω

Page 374: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 374/798

7-90

cheby1

7-91

[b,a] = cheby1(n,Rp,Wn,' ftype ') designs a highpass or ban dstop fil ter,wh ere the str ing ' ftype’ is eith er:

• 'high' for a highpass digita l f i lter w ith cutoff frequency Wn• 'stop' for a n order 2*n bandstop digital filter if Wn is a tw o-element vector,

Wn = [w1 w2]

The stopband is w1 < ω < w2.

With different numbers of output arguments, cheby1 directly obta ins oth errealizations of the filter. To obtain zero-pole-gain form, use three outputa rguments a s shown below.

[z,p,k] = cheby1(n,Rp,Wn) or

[z,p,k] = cheby1(n,Rp,Wn,' ftype ') retur ns th e zeros and poles in lengt h n column vectors z a nd p and the gain in the scala r k .

To obta in sta te-space form, use four output a rgument s a s shown below.

[A,B,C,D] = cheby1(n,Rp,Wn) or

[A,B,C,D] = cheby1(n,Rp,Wn,' ftype ') where A , B, C, and D a re

a nd u is the input, x is the sta te vector, and y is the output.

Analog Domain

[b,a] = cheby1(n,Rp,Wn,' s ') designs an order n lowpa ss a na log ChebyshevType I filter w ith cutoff frequency Wn rad/s. It retur ns t he filter coefficientsin length n+1 row vectors b a nd a , in descending powers of s , derived from th etra nsfer function

Cu toff fr equency is the frequency at wh ich th e magn itude response of the filteris -Rp dB . For cheby1 , th e cutoff frequency Wn must be grea ter t ha n 0 rad/s.

x n 1+[ ] A x n [ ] B u n [ ]+=

y n [ ] C x n [ ] D u n [ ]+=

H s ( ) B s ( )A s ( )----------- b 1( ) s n b 2( ) s n 1– L b n 1+( )+ + +

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

Page 375: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 375/798

791

cheby1

7-92

I f Wn is a tw o-element vector Wn = [w1 w2] wi th w1 < w2, thencheby1(n,Rp,Wn,' s ') returns a n order 2*n bandpa ss ana log fil ter withpassband w1 < ω< w2.

[b,a] = cheby1(n,Rp,Wn,' ftype ',' s ') designs a highpass or ban dstop fil ter.

You can s upply different nu mbers of output a rgument s for cheby1 to directlyobta in other rea lizat ions of the a na log filter. To obta in zero-pole-ga in form, usethr ee output a rguments a s shown below.

[z,p,k] = cheby1(n,Rp,Wn,' s ') or

[z,p,k] = cheby1(n,Rp,Wn,'ftype',' s ') retur ns t he zeros a nd poles inlength n or 2*n column vectors z a nd p and the gain in the scala r k .

To obta in sta te-spa ce form, use four output a rgument s a s shown below.

[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 a re defineda s

a nd u is the input, x is the sta te vector, and y is the output.

Examples Ex a mp le 1 : Low pa ss FilterFor da ta sam pled a t 1000 Hz, design a 9th-order lowpa ss Chebyshev Type Ifi lter w ith 0.5 dB of r ipple in the passband a nd a cutoff frequency of 300 Hz.

[b,a] = cheby1(9,0.5,300/500);

The freq uency response of th e filter is

freqz(b,a,512,1000)

x · A x B u +=

y C x D u +=

Page 376: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 376/798

cheby1

7-93

Example 2: Bandpass FilterDesign a 10th-order bandpa ss Chebyshev Type I fi l ter with a passba nd from100 to 200 H z a nd plot its 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)

P h a s e

( d e g r e e s

)

0 50 100 150 200 250 300 350 400 450 500-300

-200

-100

0

100

Frequency (Hertz)

M a g n

i t u d e

R e s p o n s e

( d B )

n = 9 Chebyshev Type I Lowpass Filter

Page 377: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 377/798

cheby1

7-94

Limitations For high order filters, th e sta te-spa ce form is th e most nu merically a ccura te,followed by the zero-pole-gain form. The transfer function form is the leasta ccura te; numerical problems can a rise for filter orders as low a s 15.

Algorithm cheby1 uses a five-step a lgorith m:

1 It f inds the lowpa ss a na log prototype poles, zeros, and ga in using thecheb1ap function.

2 It converts t he poles, zeros, an d ga in into sta te-spa ce form.3 It tra nsforms th e lowpass fi l ter into a band pass, highpass, or ban dstop fi l ter

with desired cutoff frequencies, using a state-space transformation.

4 For digital filter design, cheby1 uses bilinear to convert th e ana log filterinto a digita l f il ter through a bilinear t ra nsforma tion with frequencyprewar ping. Ca reful frequency ad justment gua ra ntees tha t th e a na logfilters a nd t he digital f i lters w ill ha ve the sa me frequency responsemagni tude a t Wn or w1 a nd w2.

5 It converts th e sta te-spa ce filter ba ck to tr a nsfer fun ction or zero-pole-ga inform, as required.

See Also besself , butter , cheb1ap , cheb1ord , cheby2 , ellip

0 10 20 30 40 50 60 70 80 90 100-0.2

-0.15

-0.1

-0.05

0

0.05

0.1

0.15Impulse Response of n = 10 Chebyshev Type I Filter

Page 378: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 378/798

cheby2

7-95

7cheby2

Purpose Ch ebyshev Type II filter design (stopban d 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 lowpa ss, highpass, bandpa ss, and ban dstop digita l and a na logCh ebyshev Type II filters. C hebyshev Type II filt ers a re monotonic in t hepa ssba nd a nd equiripple in t he stopband . Type II filters do not r oll off as fa sta s type I filters, but a re free of pas sba nd ripple.

Digital Domain

[b,a] = cheby2(n,Rs,Wn) designs an order n low pass d igita l Chebyshev TypeII filter w ith cutoff frequency Wn a nd st opband ripple Rs dB down from the pea kpassba nd va lue. I t returns t he fi lter coefficients in th e length n+1 row vectorsb a nd a , w ith coefficients in descending powers of z .

Cu toff fr equency is the beginning of the stopba nd, wh ere the magnitud eresponse of the filter is equa l to -Rs dB . For cheby2 , the norma lized cutofffrequency Wn is a number betw een 0 an d 1, wh ere 1 corresponds t o the Nyquistfrequency. Larger va lues of stopband a tt enuat ion Rs lea d to wider tra nsit ionw idth s (sha llow er rolloff char a cteristics).

I f Wn is a tw o-element vector, Wn = [w1 w2] , cheby2 returns a n order 2*n bandpass f i lter wi th passban d w1 < ω < w2.

[b,a] = cheby2(n,Rs,Wn,' ftype ') designs a highpass or ban dstop fil ter,wh ere the str ing ' ftype ' is eith er:

• 'high' for a highpass digita l f i lter w ith cutoff frequency Wn• 'stop' for a n order 2*n bandstop digital filter if Wn is a tw o-element vector,

Wn = [w1 w2] . The stopband is w1 < ω < w2.

H z ( ) B z ( )A z ( )----------- b 1( ) b 2( ) z 1– L b n 1+( ) z n –+ + +

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

Page 379: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 379/798

cheby2

7-96

With different numbers of output arguments, cheby2 directly obtains otherrealizations of the filter. To obtain zero-pole-gain form, use three outputa rguments a s shown below.

[z,p,k] = cheby2(n,Rs,Wn) or

[z,p,k] = cheby2(n,Rs,Wn,' ftype ') retur ns th e zeros and poles in lengt h n column vectors z a nd p and the gain in the scala r k .

To obta in sta te-spa ce form, use four output a rgument s a s shown below.

[A,B,C,D] = cheby2(n,Rs,Wn) or

[A,B,C,D] = cheby2(n,Rs,Wn,' ftype ') where A , B, C, and D a re

a nd u is the input, x is the sta te vector, and y is the output.

Analog Domain

[b,a] = cheby2(n,Rs,Wn,' s ') designs an order n lowpa ss a na log ChebyshevType II filter w ith cutoff frequency Wn . It r eturn s th e filter coefficients in t helength n+1 row vectors b a nd a , w ith coefficients in descending powers of s ,derived from the transfer function.

Cu toff fr equency is the frequency at w hich the ma gnitu de response of the filteris equa l to -Rs dB . For cheby2 , t he cutoff frequency Wn must be great er than 0ra d/s.

I f Wn is a tw o-element vector Wn = [w1 w2] wi th w1 < w2, thencheby2(n,Rs,Wn,' s ') returns a n order 2*n bandpa ss ana log fil ter withpassband w1 < ω< w2.

[b,a] = cheby2(n,Rs,Wn,' ftype ',' s ') designs a highpass or ban dstop fil ter.

x n 1+[ ] A x n [ ] B u n [ ]+=

y n [ ] C x n [ ] D u n [ ]+=

H s ( ) B s ( )A s ( )----------- b 1( ) s n b 2( ) s n 1– L b n 1+( )+ + +

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

Page 380: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 380/798

cheby2

7-97

With different numbers of output arguments, cheby2 directly obta ins oth errea lizat ions of t he a na log filter. To obta in zero-pole-ga in form, use t hree outputa rguments a s shown below.

[z,p,k] = cheby2(n,Rs,Wn,' s ') or

[z,p,k] = cheby2(n,Rs,Wn,' ftype ',' s ') retur ns t he zeros a nd poles inlength n or 2*n column vectors z a nd p and the gain in the scala r k .

To obta in sta te-space form, use four output a rgument s a s shown below.

[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

a nd u is the input, x is the sta te vector, and y is the output.

Examples Exa mp le 1 : Low pa ss FilterFor da ta sam pled a t 1000 Hz, design a ninth-order lowpa ss Chebyshev Type IIf il ter w i th s topband a t tenuat ion 20 dB down from the passband a nd a cutofffrequency of 300 Hz.

[b,a] = cheby2(9,20,300/500);

The freq uency response of th e filter is

freqz(b,a,512,1000)

x · A x B u +=

y C x D u +=

Page 381: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 381/798

cheby2

7-98

Example 2: Bandpass FilterDesign a fifth-order bandpa ss Chebyshev Type II filter with passba nd from 100to 200 Hz a nd plot th e 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)

P h a s e

( d e g r e e s

)

0 50 100 150 200 250 300 350 400 450 500-80

-60

-40

-20

0

20

Frequency (Hertz)

M a g n

i t u d e

R e s p o n s e

( d B )

n = 9 Chebyshev Type II Filter

0 10 20 30 40 50 60 70 80 90 100-0.2

-0.15

-0.1

-0.05

0

0.05

0.1

0.15

0.2Impulse Response of n = 5 Chebyshev Type II Filter

Page 382: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 382/798

cheby2

7-99

Limitations For high order filters, th e sta te-space form is the most num erica lly accurat e,follow ed by t he zero-pole-ga in form. The t ra nsfer fu nction coefficient form isth e least a ccura te; numerical problems ca n a rise for filter orders a s low a s 15.

Algorithm cheby2 uses a five-step a lgorith m:

1 It f inds the lowpa ss a na log prototype poles, zeros, an d ga in using th echeb2ap function.

2 It converts poles, zeros, and ga in int o sta te-space form.3 It tra nsforms th e lowpass fi l ter into a band pass, highpass, or ban dstop fi l ter

with desired cutoff frequencies, using a state-space transformation.

4 For digital filter design, cheby2 uses bilinear to convert th e ana log filterinto a digita l f il ter through a bilinear t ra nsforma tion with frequencyprewar ping. Ca reful frequency ad justment gua ra ntees tha t th e a na logfilters a nd t he digital f i lters w ill have the sa me frequency response

magni tude a t Wn or w1 a nd w2.5 It converts th e sta te-spa ce filter ba ck to tr a nsfer fun ction or zero-pole-ga in

form, as required.

See Also besself , butter , cheb2ap , cheb1ord , cheby1 , ellip

Page 383: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 383/798

chirp

7-100

7chirp

Purpose Generate a swept-frequency cosine

Syntax y = chirp(t,f0,t1,f1)y = chirp(t,f0,t1,f1,' method ')y = chirp(t,f0,t1,f1,' method ',phi)y = chirp(t,f0,t1,f1,'quadratic',phi, ’shape’ )

Description y = chirp(t,f0,t1,f1) genera tes sa mples of a linea r sw ept-frequency cosinesignal a t t he t ime insta nces defined in a rra y t , where f0 is the instantaneousfrequency a t t ime 0, and f1 is the insta nta neous frequency a t t ime t1 . f0 a ndf1 a re both in hert z. If unspecified, f0 is 0 , t1 is 1 , and f1 is 100 .

y = chirp(t,f0,t1,f1,' method ') specifies a lterna tive sw eep method options,where method can be:

• linear , which specifies an instantaneous frequency sweep f i (t ) given by

where

β ensures that the desired frequency breakpoint f 1 a t t ime t 1 i s mainta ined.• quadratic , which specifies an instantaneous frequency sweep f i (t ) given by

where

I f f 0 > f 1 (downsw eep), th e default sha pe is convex. If f 0 < f 1 (upsw eep), t hedefau lt sha pe is conca ve.

• logarithmic specifies an instantaneous frequency sweep f i (t ) given by

where

f i t ( ) f 0 βt +=

β f 1 f 0–( ) t 1 ⁄ =

f i t ( ) f 0 βt 2+=

β f 1 f 0–( ) t 12 ⁄ =

f i t ( ) f 0 10 βt +=

Page 384: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 384/798

chirp

7-101

For a log-sw eep, f1 must be greater tha n f0 .

Ea ch of the a bove methods can be entered as 'li' , 'q' , and 'lo' , respect ively.

y = chirp(t,f0,t1,f1,' method ',phi) al lows an in it ia l phase phi to bespecified in d egrees. If un specified, phi is 0 . Default va lues a re substi tuted forempty or omitt ed tra il ing input a rguments.

y = chirp(t,f0,t1,f1,'quadratic',phi, ’shape’ ) specifies th e shape of thequadratic swept-frequency signal’s spectrogram. shape is either concave orconvex , wh ich describes th e sha pe of th e para bola in th e positive frequencya xis. If shape is omitted, th e default is convex for down sw eep ( f 0 > f 1 ) and i sconca ve for upsw eep ( f 0 < f 1 ).

β log 10 f 1 f 0–( )[ ] t 1 ⁄ =

Convex downsweepshape Concave upsweepshape

t

f f

t

Page 385: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 385/798

chirp

7-102

Examples Exa mple 1Compute the spectrogra m of a chirp with l inea r insta nta neous frequencydeviation.

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

F r e q u e n c y

Linear chirp

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.60

50

100

150

200

250

300

350

400

450

500

Page 386: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 386/798

chirp

7-103

Exa mple 2Compute the spectrogra m of a chirp with q ua dra tic insta nta neous frequencydeviation.

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

F r e q u e n c y

Quadratic chirp

0 0.5 1 1.5 2 2.5 3 3.50

50

100

150

200

250

300

350

400

450

500

Page 387: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 387/798

chirp

7-104

Exa mple 3Compute th e spectr ogram of a convex qua dra tic chirp.

t= -1:0.001:1; % +/-1 second @ 1kHz sample ratefo=100; f1=400; % Start at 100Hz, go up to 400Hzy=chirp(t,fo,1,f1,'q',[],'convex');specgram(y,256,1000) % Display the spectrogram.

Time

F

r e q u e n c y

Convex chirp

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.60

50

100

150

200

250

300

350

400

450

500

Page 388: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 388/798

chirp

7-105

Exa mple 4Compute the spectrogram of a concave quadratic chirp.

t= 0:0.001:1; % 1 second @ 1kHz sample ratefo=100; f1=25; % Start at 100Hz, go down to 25Hzy=chirp(t,fo,1,f1,'q',[],'concave');specgram(y,256,1000) % Display the spectrogram.

See Also cos , diric , gauspuls , pulstran , rectpuls , sawtooth , sin , sinc , square ,tripuls

Time

F r e q u e n c y

Concave chirp

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.60

50

100

150

200

250

300

350

400

450

500

Page 389: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 389/798

cohere

7-106

7cohere

Purpose Est imat e ma gnitude squa red coherence function betw een t wo signals

Syntax Cxy = cohere(x,y)Cxy = cohere(x,y,nfft)[Cxy,f] = cohere(x,y,nfft,fs)Cxy = cohere(x,y,nfft,fs,window)Cxy = cohere(x,y,nfft,fs,window,numoverlap)Cxy = cohere(x,y,...,' dflag ')cohere(x,y)

Description Cxy = cohere(x,y) finds the magnitude squared coherence between length n signa l vectors x a nd y . The coheren ce is a fun ction of the power s pectr a of x a nd y a nd t he cross spectr um of x a nd y .

x a nd y must be the sam e length.

nfft specifies th e FFT length t ha t cohere uses. This va lue determines th efrequencies a t w hich the coherence is estima ted. fs is a scala r th a t specifies thesampling frequency. window specifies a w indowing function a nd t he number ofsamples cohere uses in its sectioning of th e x a nd y vectors. numoverlap is thenumber of samples by wh ich t he win dow sections overlap for both x a nd y . Any

a rguments th a t you omit from the end of the pa ra meter l ist use the defaultvalues shown below.

Cxy = cohere(x,y) uses the follow ing default va lues:

• nfft = min(256,length(x))• fs = 2• window is a periodic Han n w indow of length nfft .• numoverlap = 0

I f x is real , cohere estima tes t he coherence function a t positive frequenciesonly; in t his case, the output Cxy is a column vector of length nfft/2 + 1 fornfft even a nd (nfft + 1)/2 for n odd. If x or y is complex, cohere est imat es thecoherence function at both positive an d nega tive frequencies, and Cxy ha slength nfft .

C x y f ( )P x y f ( ) 2

P x x

f ( ) P y y

f ( )-------------------------------=

Page 390: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 390/798

cohere

7-107

Cxy = cohere(x,y,nfft) uses th e FFT length nfft in estimat ing the powerspectr um for x . S pecify nfft a s a pow er of 2 for fa stest execution.

Cxy = cohere(x,y,nfft,fs) returns a vector f of frequencies a t w hich thefunction evalua tes t he coherence. fs is the sampling frequency. f i s the samesize a s Cxy , so plot(f,Cxy) plots th e coherence fun ction versus properly sca ledfrequency. fs ha s no effect on t he output Cxy ; it is a frequency sca lingmultiplier.

cohere(x,y,nfft,fs,window) specifies a w indowing function an d the numberof sam ples per section of th e vect ors x a nd y . If you supply a scala r for window ,cohere uses a Ha nn w indow of tha t length. The length of the window must beless tha n or equal to nfft ; cohere zero pad s th e sections if the w indow lengthexceeds nfft .

cohere(x,y,nfft,fs,window,numoverlap) overla ps t he sections of x bynumoverlap samples.

Note If you use cohere on tw o linear ly relat ed signals [1] w ith a single,non-overla pping w indow, th e output for a ll frequencies is Cxy = 1.

You can use th e empty ma trix [] to specify the defau lt va lue for any inputargument except x or y . For exa mple,

cohere(x,y,[],[],kaiser(128,5));

uses 256 as the va lue for nfft a nd 2 a s the va lue for fs .

cohere(x,y,...,' dflag ') specifies a detrend option, w here ' dflag ' is :

• 'linear' , to remove th e best str a ight -line fit fr om the prew indowed sectionsof x a nd y

• 'mean' , to remove th e mean from the prew indowed sections of x a nd y• 'none' , for no detrend ing (defau lt)

The ' dflag ' para meter must appear last in the l ist of input argument s. cohere recognizes a ' dflag ' s t r ing no mat ter how many in termediat e arguments a reomitted.

Page 391: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 391/798

cohere

7-108

cohere wit h n o output a rguments plots the coherence estimat e versusfrequency in the current figure window.

Example Compute a nd plot t he coherence estima te betw een t w o colored noise sequencesx a nd y .

randn('state',0);h = fir1(30,0.2,rectwin(31));h1 = ones(1,10)/sqrt(10);r = randn(16384,1);x = filter(h1,1,r);y = filter(h,1,x);cohere(x,y,1024,[],[],512)

Diagnostics An a ppropriat e diagnostic message is displayed w hen incorrect ar guments 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.

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

Frequency

C o

h e r e n c e

F u n c t i o n

E s t i m a

t e

Page 392: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 392/798

cohere

7-109

Algorithm cohere estima tes th e magn itude squa red coherence function [2 ] using Welch’smet hod of pow er spectru m est ima tion (see references [3] a nd [4]), a s follow s:

1 I t divides the signals x a nd y into separa te overla pping sections, detrend seach section, an d mult iplies each section by window .

2 I t calculat es the length nfft fas t Fourier tra nsform of ea ch section.

3 I t a vera ges the squares of the spectra of the x sections t o form Pxx , averagesthe squa res of the spectra of the y sections t o form Pyy , and a verages the

products of th e spectra of th e x a nd y sections t o form Pxy . I t ca lculat es Cxy by th e followin g formula.

Cxy = abs(Pxy).^2/(Pxx.*Pyy)

See Also csd , pwelch , tfe

References [1] St oica, P ., a nd R. Moses. I nt r oduct ion to Spectr a l Anal ysis . Upper Sa ddle

River, NJ : P rentice-Ha ll, 1997. Pgs. 61-64.[2] Ka y, S .M. M odern Spectr a l Est im at ion . Englewood Cliffs, NJ :P rent ice-Ha ll, 1988. P g. 454.

[3] Ra biner, L.R., and B . Gold. Th eory and Appl i cat ion of Di gi ta l Si gnal Processing . En glewood C liffs, NJ : P rent ice-Ha ll, 1975.

[4] Welch, P .D. “The U se of Fas t Fourier Tra nsform for th e Est ima tion of P owerSpectr a : A Method B a sed on Time Avera ging Over Sh ort, ModifiedPeriodograms.” I EE E Tr ans. Aud io El ect r oacoust . Vol. AU -15 (J un e 1967).P gs. 70-73.

Page 393: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 393/798

conv

7-110

7conv

Purpose Convolut ion a nd polynomia l multiplica tion

Syntax c = conv(a,b)

Description c = conv(a,b) convolves vectors a a nd b . The convolution su m is

where N is th e ma ximum sequence length. The series is indexed from n + 1 a ndk + 1 instead of the usua l n a nd k becaus e MATLAB vect ors run from 1 to n inst ead of from 0 to n -1.

The conv function is part of the st a nda rd MATLAB langua ge.

Example The convolution of a = [1 2 3] a nd b = [4 5 6] is

c = conv(a,b)

c =4 13 28 27 18

Algorithm The conv function is a n M-file th a t uses th e filter primitive. conv computesth e convolution operat ion a s FIR filtering w ith a n a ppropriat e number of zerosa ppended to the input.

See Also conv2 , convmtx , convn , deconv , filter , residuez , xcorr

c n 1+( ) a k 1+( ) b n k –( )

k 0=

N 1–

∑=

Page 394: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 394/798

conv2

7-111

7conv2

Purpose Tw o-dimen siona l convolut ion

Syntax C = conv2(A,B)C = conv2(A,B,' shape ')

Description C = conv2(A,B) comput es th e tw o-dimensional convolution of ma tr ices A a nd B. If one of these ma tr ices describes a t w o-dimensional FI R filter, th e oth erma tr ix is filtered in tw o dimensions.

Ea ch dimension of the output ma trix C is equa l in size to one less th a n th e sumof the corresponding dimensions of th e input ma tr ices. When[ma,na] = size(A) a nd [mb,nb] = size(B) ,

size(C) = [ma+mb-1,na+nb-1]

C = conv2(A,B,' shape ') retur ns a subsection of the tw o-dimensionalconvolution with size specified by ' shape ' , wh ere:

• 'full' retur ns t he full tw o-dimensional convolution (default )• 'same' returns t he centra l part of the convolution t ha t is t he same size as A • 'valid' retur ns only those pa rt s of the convolution tha t a re computed

w ithout t he zero-pad ded edges. U sing th is option,size(C) = [ma-mb+1,na-nb+1] when size(A) > size(B)

conv2 executes most q uickly w hen size(A) > size(B) .

The conv2 function is part of the st a nda rd MATLAB langua ge.

Examples In ima ge processing, th e Sobel edge-finding opera tion is a tw o-dimensionalconvolution of an input a rra y w ith t he specia l mat rix

s = [1 2 1; 0 0 0; -1 -2 -1];

G iven any ima ge, th e follow ing code extr a cts th e horizonta l edges.

h = conv2(I,s);

The followin g code extr a cts th e vert ica l edges first, a nd t hen extra cts bothhorizont a l an d vertical edges combined.

v = conv2(I,s');v2 = (sqrt(h. 2 + v. 2))

Page 395: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 395/798

conv2

7-112

See Also conv , convn , deconv , filter2 , xcorr , xcorr2

Page 396: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 396/798

convmtx

7-113

7convmtx

Purpose Convolution ma trix

Syntax A = convmtx(c,n) A = convmtx(r,n)

Description A convolut i on m atr i x is a m a tr ix, formed from a vector, wh ose inner productw ith a nother vector is the convolution of th e tw o vectors.

A = convmtx(c,n) where c is a length mcolumn vector returns a ma trix A ofsize (m+n-1) -by-n . The pr oduct of A a nd a nother column vector x of lengt h n isthe convolution of c wi th x .

A = convmtx(r,n) where r is a length m row vector returns a ma trix A of sizen-by- (m+n-1) . The product of A a nd a nother row vector x of length n i s theconvolut ion of r wi th x .

Example G enera te a simple convolution ma trix.h = [1 2 3 2 1];convmtx(h,7)ans =

1 2 3 2 1 0 0 0 0 0 00 1 2 3 2 1 0 0 0 0 00 0 1 2 3 2 1 0 0 0 0

0 0 0 1 2 3 2 1 0 0 00 0 0 0 1 2 3 2 1 0 00 0 0 0 0 1 2 3 2 1 00 0 0 0 0 0 1 2 3 2 1

Note tha t convmtx ha ndles edge conditions by zero pa dding.

In pra ctice, it is more efficient to comput e convolution using

y = conv(c,x)

tha n by using a convolution ma trix.

n = length(x);y = convmtx(c,n)*x

Algorithm convmtx uses th e function toeplitz to generate the convolution matrix.

Page 397: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 397/798

convmtx

7-114

See Also conv , convn , conv2 , dftmtx

Page 398: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 398/798

corrcoef

7-115

7corrcoef

Purpose Compute t he correla tion coefficient m a tr ix

Syntax C = corrcoef(X)C = corrcoef(X,Y)

Description corrcoef retur ns a ma tr ix of correla tion coefficients ca lcula ted from a n inputma trix wh ose rows a re observat ions a nd w hose columns a re varia bles. IfC = cov(X) , then corrcoef(X) is the ma trix w hose element ( i , j ) is

C = corrcoef(X) is the zeroth lag of the covaria nce function, th a t is , th ezeroth la g of xcov(x,'coeff') packed in to a square arra y.

C = corrcoef(X,Y) i s the same a s corrcoef([X Y]) ; tha t is , it concat enat es X

a nd Y in t he row direction before its computa tion.corrcoef removes th e mean from ea ch column before calculat ing th e results.See the xcorr funct ion for cross-correla tion options.

The corrcoef function is part of the st an da rd MATLAB langua ge.

See Also cov , mean , median , std , xcorr , xcov

corrcoef i j ,( ) C i j ,( )C i i ,( ) C j j ,( )

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

Page 399: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 399/798

corrmtx

7-116

7corrmtx

Purpose Compute a d at a m at rix for a utocorrelation mat rix estima tion

Syntax X = corrmtx(x,m)X = corrmtx(x,m,' method ')[X,R] = corrmtx(...)

Description X = corrmtx(x,m) re turns an ( n +m)-by-( m+ 1) recta ngula r Toeplitz mat rix X,such tha t X'X is a (biased) estima te of th e aut ocorrelat ion ma tr ix for the

length n da ta vector x .

X = corrmtx(x,m,' method ') computes the ma trix X a ccording to the meth odspecified by t he str ing ' method ' :

• 'autocorrelation' : (defau lt) X is the (n +m)-by-( m+ 1) recta ngula r Toeplitzma trix tha t generat es an a utocorrelation estima te for the length n d a t avector x , derived using prewindowed a nd postwindowed dat a , based on anmth order prediction error m odel.

• 'prewindowed' : X is the n -by-( m+ 1) recta ngular Toeplitz ma trix th a tgenera tes a n a utocorrelation estimate for the length n da ta vector x , derivedusing prewindowed dat a , based on a n mth order prediction error model.

• 'postwindowed' : X i s the n -by-( m+ 1) recta ngular Toeplitz ma trix th a tgenera tes a n a utocorrelation estimate for the length n da ta vector x , derivedusing postwindowed dat a , based on a n mth order prediction error model.

• 'covariance' : X is the (n - m)-by-( m+ 1) recta ngular Toeplitz m a trix th atgenera tes a n a utocorrelation estimate for the length n da ta vector x , derivedusing nonwindowed dat a , based on a n mth order prediction error model.

• 'modified' : X is th e 2( n - m)-by-( m+ 1) modified recta ngula r Toeplitz ma tr ixtha t generat es an a utocorrelation estima te for the length n da ta vector x ,derived using forwa rd a nd ba ckwa rd prediction error estima tes, based on anmth order prediction error m odel.

[X,R] = corrmtx(...) also return s the ( m+ 1)-by-(m+ 1) a utocorrelation ma trixes t imate R, calculated a s X'*X .

Examples randn('state',1); n=0:99;s=exp(i*pi/2*n)+2*exp(i*pi/4*n)+exp(i*pi/3*n)+randn(1,100);X=corrmtx(s,12,'mod');

Page 400: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 400/798

corrmtx

7-117

Algorithm The Toeplitz da ta ma tr ix computed by corrmtx depends on t he method youselect. The ma tr ix determined by t he a ut ocorrelat ion (defa ult) method is givenby t he following ma trix.

In th is matr ix , m is the sa me as the input a rgument m t o corrmtx , and n is

length(x) . Va riat ions of this mat rix are used to return th e output Xof corrmtx for ea ch method:

• 'autocorrelation' : (defau lt) X = X , a bove.• 'prewindowed' : X is the n -by-( m + 1) submat rix of X tha t is given by the

portion of X a bove the low er gra y line.• 'postwindowed' : X i s the n -by-( m + 1) submat rix of X tha t is given by the

portion of X below t he upper gra y line.• 'covariance' : X is the (n -m )-by-( m + 1) submat rix of X tha t is given by the

portion of X betw een t he tw o gray l ines.• 'modified' : X is th e 2( n -m )-by-( m + 1) mat r ix X mod shown below .

X

x 1( ) L 0M O M

x m 1+( ) L x 1 )M O M

x n m –( ) L x m 1+( )M O M

x n ( ) L x n m –( )M O M

0 L x n ( )

=

Page 401: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 401/798

corrmtx

7-118

See Also peig , pmusic , rooteig , rootmusic , xcorr

References [1] Ma rple, S.L . Di gi ta l Spectr a l An alysis , Englewood Cliffs, NJ , Pr entice-Ha ll,1987, pp. 216-223.

X m od

x m 1+( ) L x 1 )M O M

x n m –( ) L x m 1+( )M O M

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

M N M

x ∗m 1+( ) L x ∗n m –( )M N M

x ∗n m –( ) L x ∗n ( )

=

Page 402: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 402/798

cov

7-119

7cov

PurposeCompute the covaria nce matr ix

Syntax c = cov(x)c = cov(x,y)

Description cov comput es the covaria nce ma tr ix. If x is a vector, c is a sca lar conta ining thevaria nce. For a n a rra y wh ere each row is an observat ion a nd each column avariable, cov(X) is the covaria nce matr ix. diag(cov(X)) is a vector of

variances for each column, and sqrt(diag(cov(X))) is a vector of sta nda rddeviations.

cov(x) is the zeroth la g of the cova ria nce function, tha t is, the zeroth lag ofxcov(x)/(n-1) packed in to a squa re arra y.

cov(x,y) where x a nd y a re column vectors of equa l lengt h is equivalent t ocov([x y]) , tha t is , it concat enat es x a nd y in t he row d irection before its

computation.cov removes th e mean from ea ch column before calculat ing th e results.

The cov function is part of the st a nda rd MATLAB langua ge.

Algorithm [n,p] = size(x);x = x-ones(n,1)*(sum(x)/n);y = x'*x/(n-1);

See Also corrcoef , mean , median , std , xcorr , xcov

Page 403: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 403/798

cplxpair

7-120

7cplxpairPurpose G roup complex numbers int o complex conjuga te pa irs

Syntax y = cplxpair(x)y = cplxpair(x,tol)

Description y = cplxpair(x) re turns x w ith complex conjuga te pa irs grouped togeth er.cplxpair orders the conjugate pa irs by increasing rea l part . Within a pair, theelement wit h n egative imagina ry pa rt comes first . The function retur ns a ll

purely real va lues follow ing a ll the complex pair s.

y = cplxpair(x,tol) includes a toleran ce, tol , for determ ining w hichnumbers ar e real a nd w hich a re paired complex conjugates. B y default ,cplxpair uses a toleran ce of 100*eps rela tive to abs(x(i)) . cplxpair forcesth e complex conjuga te pa irs t o be exa ct complex conjuga tes.

The cplxpair function is part of the st a nda rd MATLAB langua ge.

Example Order five poles evenly spa ced a round t he un it circle int o complex pairs.

cplxpair(exp(2*pi*sqrt(-1)*(0:4)/5)')

ans =-0.8090 - 0.5878i-0.8090 + 0.5878i

0.3090 - 0.9511i0.3090 + 0.9511i1.0000

Diagnostics If t here is a n odd nu mber of complex numbers, or if the complex numberscann ot be grouped into complex conjuga te pa irs w ithin th e tolera nce, cplxpair genera tes t he error messa ge.

Complex numbers can't be paired.

Page 404: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 404/798

cremez

7-121

7cremezPurpose Complex a nd n onlinear-pha se equiripple FIR filter d esign

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 a rbitra ry frequency-domain constra ints t o be specified for th edesign of a possibly complex FI R filter . The Ch ebyshev (or minima x) filter err oris optimized, producing equiripple FIR filter designs.

b = cremez(n,f,' fresp ') returns a length n+1 FIR fi l ter with t he besta pproximat ion t o the desired frequency response a s retur ned by functionfresp . f is a vector of frequency ban d edge pa irs, specified in t he ra nge -1a nd 1, w here 1 corresponds to the norma lized Nyqu ist frequency. Thefrequencies must be in increasing order, a nd f must ha ve even lengt h. Thefrequency bands spa n f(k) t o f(k+1) for k odd; the intervals f(k+1) t o f(k+2) for k odd are “transition bands” or “don’t care” regions during optimization.

b = cremez(n,f,' fresp ',w) uses the rea l, non-nega tive weight s in vector wt ow eight t he fit in each frequency band . The lengt h of w is ha lf the length of f , s othere is exactly one weight per ba nd.

b = cremez(n,f,' fresp ',p1,p2,...,...) supplies optional pa ra metersp1 , p2 , ... , t o th e frequency response function fresp . Pr edefined ' fresp ' frequency response functions a re included for a number of common filterdesigns, a s described below . For a ll of t he predefined frequency r esponse

functions, the symmet ry option ' sym ' defaults to 'even' if no nega tivefrequencies a re cont a ined in f a nd d = 0 ; otherwise ' sym ' defaults to 'none' .(See t he ' sym ' option below for d eta ils.) For a ll of the predefined frequencyresponse functions, d specifies a group-delay offset such t ha t th e filter response

Page 405: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 405/798

cremez

7-122

ha s a group dela y of n/2+d in units of the sa mple interval. Negat ive valuescreat e less delay; positive values creat e more delay. B y default d = 0 :

• lowpass , highpass , bandpass , bandstop

These functions sha re a common synt a x, exemplified below by th e string'lowpass' .

b = cremez(n,f,'lowpass',...) a nd

b = cremez(n,f,'lowpass',d,...) design a l inear -phase

(n/2+d delay ) filter.• multiband designs a l inear -phase frequency r esponse fi lter w ith a rbitra ry

band amplitudes.

b = cremez(n,f,'multiband',a,...) a nd

b = cremez(n,f,'multiband',a,d,...) specify vector a containingthe desired a mplitudes a t t he band edges in f . The desired am plitude a tfrequencies betw een pairs of point s f(k) a nd f(k+1) for k odd is the line

segment connecting t he points (f(k),a(k)) a nd (f(k+1),a(k+1)) .• differentiator designs a linea r-pha se differentia tor. For these designs,

zero-frequency must be in a tra nsit ion ba nd, a nd ba nd w eighting is set t o beinversely proportional to frequency.

b = cremez(n,f,'differentiator',fs,...) a nd

b = cremez(n,f,'differentiator',fs,d,...) specify the sample rat efs used t o determine th e slope of th e different iat or response. If omitt ed, fs

defaul ts to 1.• hilbfilt designs a linea r-pha se Hilbert t ra nsform filter response. For

Hilbert designs, zero-frequency must be in a t ra nsit ion ba nd.

b = cremez(n,f,'hilbfilt',...) a nd

b = cremez(N,F,'hilbfilt',d,...) design a l inea r-phase(n/2+d dela y) Hilbert t ra nsform fi lter.

b = cremez(n,f,a,w) is a sy nonym forb = cremez(n,f,'multiband',a,w) .

Page 406: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 406/798

cremez

7-123

b = cremez(...,' sym ') imposes a symmetry constra int on t he impulseresponse of the design, w here ' sym ' ma y be one of th e follow ing:

• 'none' indica tes no symmetry constra int . This is the default if any negat iveba nd edge frequencies ar e passed, or if fresp does not supply a defau lt.

• 'even' indicat es a r eal a nd even impulse response. This is th e default forhighpass, lowpa ss, ba ndpass, ban dstop, an d multiband designs.

• 'odd' indicat es a rea l an d odd impulse response. This is th e default for

Hilbert a nd differentia tor designs.• 'real' indicat es conjuga te symm etry for th e frequency response

I f any ' sym ' option other t ha n 'none' is specified, t he ba nd edges sh ould onlybe specified over positive frequen cies; th e nega tive freq uency region is filled infrom symmetry. I f a ' sym ' option is not specified, th e fresp function is qu eriedfor a default sett ing.

b = cremez(...,' skip_stage2 ') disa bles t he second-sta ge optimiza tiona lgorith m, wh ich executes only w hen cremez determines that an opt imalsolution ha s not been rea ched by th e sta nda rd Remez error-excha nge.Disa bling t his a lgorithm ma y increa se the speed of computa tion, but ma y incura reduction in a ccura cy. B y default , the second-sta ge optimiza tion is ena bled.

b = cremez(...,' debug ') enables the displa y of intermedia te results duringthe filter design, where ' debug ' ma y be one of 'trace' , 'plots' , 'both' , or 'off' . By default i t is set to 'off' .

b = cremez(...,lgrid) uses the integer lgrid to cont rol the density of thefrequency grid, wh ich h as roughly 2^nextpow2(lgrid*n) frequency point s.The defa ult va lue for lgrid is 25 . Note tha t the lgrid a rgument must be a1-by-1 cell a rra y.

Any combinat ion of th e ' sym ' , ' skip_stage2 ' , ' debug ' , and lgrid optionsmay be specified.

[b,delta] = cremez(...) returns the ma ximum ripple height delta .

Page 407: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 407/798

cremez

7-124

[b,delta,opt] = cremez(...) re turns a s t ructure opt of optiona l resultscomputed by cremez a nd cont a ins th e followin g fields.

U ser-definable functions ma y be used, instea d of the predefined frequency

response functions for fresp . The function is ca lled from w ithin cremez usingthe following syn ta x

[dh,dw] = fresp (n,f,gf,w,p1,p2,...)

where:

• n is th e filter order.• f is the vector of frequency ban d edges tha t a ppea r monotonica lly betw een -1

a nd 1, where 1 corresponds t o the Nyquist frequency.• gf is a vector of grid points t ha t h a ve been linearly int erpola ted over each

specified frequ ency ban d by cremez . gf determines t he frequency grid a tw hich the response function must be eva lua ted. This is the sa me da tareturned by cremez in the fgrid field of th e opt structure.

• w is a vector of real, positive weight s, one per ba nd, used dur ing optimizat ion.w is optional in t he ca ll to cremez ; if not specified, it is set t o unity w eighting

before being passed t o fresp .• dh a nd dw a re the desired complex frequency response a nd ba nd w eight

vectors, respectively, eva lua ted a t ea ch frequency in grid gf .• p1 , p2 , ... , are optiona l par a meters tha t ma y be passed to fresp .

opt.fgrid Frequ ency grid vector used for th e filter design optimiza tion

opt.des Desired frequency r esponse for each point in opt.fgrid

opt.wt Weighting for each point in opt.fgrid

opt.H Actua l frequency response for ea ch point in opt.fgridopt.error Err or a t ea ch point in opt.fgrid

opt.iextr Vect or of indices into opt.fgrid for extr ema l frequencies

opt.fextr Vector of extremal frequencies

Page 408: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 408/798

cremez

7-125

Additiona lly, a preliminar y call is ma de to fresp to determine the defaultsymmetry property ' sym ' . This call is made using t he synta x.

sym = fresp ('defaults',n,f,[],w,p1,p2,...)

The ar guments ma y be used in determining an appropriat e symmetry defaulta s necessary . The function private/lowpass.m ma y be useful as a template forgenera ting n ew frequency response functions.

Examples Exa mple 1Design a 31-ta p, linea r-pha se, low pass filter.

b = cremez(30,[-1 -0.5 -0.4 0.7 0.8 1],'lowpass');freqz(b,1,512,'whole');

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2−3500

−3000

−2500−2000

−1500

−1000

−500

0

Normalized Frequency ( ×πrad/sample)

P h a s e

( d e g r e e s

)

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2−100

−80

−60

−40

−20

0

20

Normalized Frequency ( ×πrad/sample)

M a g n

i t u d e

( d B )

Page 409: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 409/798

Page 410: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 410/798

cremez

7-127

The freqz plot shows t he frequency response of th e filter computed by cremezto a pproximat e the desired response. Check the a ccura cy of the a pproximat ionby overlaying the desired frequency response on t he 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')

Algorithm An extended version of the Remez excha nge meth od is implement ed for t hecomplex case. This excha nge meth od obta ins t he optima l filter wh en th eequiripple na tu re of the filter is restricted to ha ve n+2 extrema ls. When it doesnot converge, the a lgorithm switches to an a scent-descent a lgorithm tha t t a kesover t o finish th e convergence to the optima l solution. S ee the references forfurther details .

See Also fir1 , fir2 , firls , remez

References [1] Ka ra m, L.J ., an d J .H. McClella n. “Complex Chebyshev Approximat ion forFIR Fil ter Design.” I EE E T ran s. on Ci rcui ts and Systems I I . Ma rch 1995.P gs. 207-216.

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2−3000

−2000

−1000

0

Normalized Angular Frequency ( ×πrads/sample)

P h a s e

( d e g r e e s )

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2−0.2

−0.1

0

0.1

0.2

Normalized Angular Frequency ( ×πrads/sample)

M a g n

i t u d e

( d B )

ApproximationDesired

Page 411: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 411/798

cremez

7-128

[2] Ka ra m, L.J . Design of Com plex Digi tal FI R F il ters i n th e Chebyshev Sense .P h.D. Thesis, G eorgia Inst itut e of Technology, Ma rch 1995.

[3] Demja njov, V.F., a nd V.N. Ma lozemov. In t roduct ion to M in i max . New York:J ohn Wiley & S ons, 1974.

Page 412: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 412/798

csd

7-129

7csdPurpose Est imat e the cross spectra l density (CSD ) of two signals

Syntax Pxy = csd(x,y)Pxy = csd(x,y,nfft)[Pxy,f] = csd(x,y,nfft,fs)Pxy = csd(x,y,nfft,fs,window)Pxy = csd(x,y,nfft,fs,window,numoverlap)Pxy = csd(x,y,..., ' dflag ')

[Pxy,Pxyc,f] = csd(x,y,nfft,fs,window,numoverlap,p)csd(x,y,...)

Description Pxy = csd(x,y) estima tes th e cross spectr a l density of th e length n sequencesx a nd y using t he Welch met hod of spectr a l estima tion. Pxy = csd(x,y) usesthe following default values:

• nfft = min(256,length(x))•

fs = 2• window is a periodic Han n w indow of length nfft .• numoverlap = 0

nfft specifies th e FFT length t ha t csd uses. This va lue determines th efrequencies at which the cross spectrum is estimated. fs i s a scalar tha tspecifies t he sa mpling frequency. window specifies a w indowing function a ndth e number of sam ples csd uses in its sectioning of the x a nd y vectors.numoverlap is th e number of samples by w hich th e sections overla p. Anya rguments omitted from t he end of the par a meter l ist use th e default valuesshown above.

I f x a nd y ar e real , csd estimat es the cross spectra l density a t posit ivefrequencies only; in this ca se, the output Pxy is a column vector of lengthnfft/2 + 1 for nfft even an d (nfft + 1)/2 for nfft odd. If x or y is complex,csd estimat es the cross spectral density a t both posit ive a nd nega tive

frequencies and Pxy has length nfft .

Pxy = csd(x,y,nfft) uses th e FFT length nfft in estimat ing the crossspectr a l density of x a nd y . S pecify nfft a s a power of 2 for fa stest execution.

[Pxy,f] = csd(x,y,nfft,fs) returns a vector f of frequencies at which thefunction evaluat es the CSD. f is the same size as Pxy , s o plot(f,Pxy) plots the

Page 413: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 413/798

csd

7-130

spectr um versus properly scaled frequency. fs ha s no effect on t he out put Pxy ;it is a frequ ency sca ling multiplier.

Pxy = csd(x,y,nfft,fs,window) specifies a windowing function and thenumber of sa mples per section of t he x vector. If you supply a sca lar for window ,csd uses a H a nn w indow of tha t length. The length of the w indow must be lesstha n or equal to nfft ; csd zero pad s th e sections if the length of th e window isless tha n nfft . csd returns a n error if the length of the window is grea ter th annfft .

Pxy = csd(x,y,nfft,fs,window,numoverlap) overla ps t he sections of x a nd y by numoverlap samples.

You can use t he empty m a trix [] to specify th e defa ult va lue for any inputargument except x or y . For exam ple,

csd(x,y,[],10000)

is equivalent t ocsd(x)

but w ith a sa mpling frequency of 10,000 Hz instea d of the default of 2 Hz.

Pxy = csd(x,y,...,' dflag ') specifies a detrend option, where th e string' dflag’ is one of th e following :

'linear' , to remove the best str a ight-line fit from t he prewindowed sectionsof x a nd y• 'mean' , to remove the mea n from th e prewindowed sections of x a nd y• 'none' , for no detrend ing (defau lt)

The dflag para meter must appea r last in the l ist of input argument s. csd recognizes a dflag s t r ing no mat ter how many in termediat e arguments areomitted.

[Pxy,Pxyc,f] = csd(x,y,nfft,fs,window,numoverlap,p) where p is apositive sca lar bet w een 0 a nd 1 returns a vector Pxyc tha t conta ins an es t imateof th e p*100 percent confidence interval for Pxy . Pxyc is a two-column matrixthe same length a s Pxy . The int erval [Pxyc(:,1),Pxyc(:,2)] covers the t rue

Page 414: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 414/798

csd

7-131

CSD with probabili ty p . plot(f,[Pxy Pxyc]) plots th e cross spectr um insidet he p*100 percent confidence interva l. If unspecified, p default s t o 0.95.

csd(x,y,...) plots the C SD versus frequency in t he current f igure w indow. I ft he p par a meter is specified, the plot includes the confidence int erva l.

Example G enera te tw o colored noise signa ls an d plot their CS D w ith a confidenceint erval of 95%. Specify a length 1024 FF T, a 500 point tr ian gula r w indow w ithno overlap, a nd a sam pling frequency of 10 Hz.

randn('state',0);h = fir1(30,0.2,rectwin(31));h1 = ones(1,10)/sqrt(10);r = randn(16384,1);x = filter(h1,1,r);y = filter(h,1,x);csd(x,y,1024,10000,triang(500),0,[])

Algorithm csd implement s t he Welch m ethod of spectra l density estima tion (seerefer ences [1] a nd [2]):

1 It a pplies the wind ow specified by the window vector to each successivedetrend ed section.

2 It t ra nsforms each section w ith a n nfft -point FF T.

0 1000 2000 3000 4000 5000−70

−60

−50

−40

−30

−20

−10

0

10

20

Frequency

C r o s s

S p e c t r u m

M a g n

i t u d e

( d B )

Page 415: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 415/798

csd

7-132

3 It forms t he periodogram of ea ch section by scaling t he product of th etra nsform of the y section and the conjugate of the transformed x section.

4 It a vera ges th e periodogra ms of th e successive overla pping sections t o formPxy , th e cross spectra l density of x a nd y .

The num ber of sections t ha t csd a vera ges is k , where k is

fix((length(x)-numoverlap)/(length(window)-numoverlap))

Diagnostics An a ppropriat e diagnostic message is displayed w hen incorrect a rguments t ocsd ar e used.

Requires window's length to be no greater than the FFT length.Requires NOVERLAP to be strictly less than the window length.Requires positive integer values for NFFT and NOVERLAP.Requires vector (either row or column) input.Requires inputs X and Y to have the same length.Requires confidence parameter to be a scalar between 0 and 1.

See Also cohere , pburg , pmtm, pmusic , pwelch , pyulear , tfe

References [1] Ra biner, L.R., an d B . G old. Th eory and Appl i cat ion of Di gi ta l Si gnal Processing . E nglewood Cliffs, NJ : P rent ice-Ha ll, 1975. Pg s. 414-419.

[2] Welch, P .D. “The U se of Fa st Fourier Tra nsform for th e Est ima tion of P owerSpectr a : A Meth od Ba sed on Time Averag ing Over Sh ort, ModifiedPeriodograms.” I EE E Tr ans. Au di o El ectr oacoust . Vol. AU -15 (J un e 1967).P gs. 70-73.

[3] Oppenheim, A.V., a nd R.W. S cha fer. D i scr ete-Ti m e Si gnal Pr ocessing .U pper S a ddle River, NJ : P rent ice-Ha ll, 1999, pp. 737.

Page 416: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 416/798

czt

7-133

7cztPurpose Chirp z -transform

Syntax y = czt(x,m,w,a)y = czt(x)

Description y = czt(x,m,w,a) returns t he chirp z -transform of signal x . The ch irpz -tra nsform is t he z -tr a nsform of x a long a spiral cont our defined by w a nd a .m is a scala r t ha t specifies the length of the t ra nsform, w is the ra tio betw eenpoints a long t he z -plan e spira l contour of interest , an d scala r a is t he complexsta rt ing point on th a t contour. The contour, a spira l or “chirp” in th e z -plan e, isgiven by

z = a*(w.^-(0:m-1))

y = czt(x) uses the follow ing default va lues:

• m= length(x)•

w = exp(j*2*pi/m)• a = 1

With t hese defau lts, czt re turns the z -tr a nsform of x a t mequa lly spaced point sa round t he unit circle. This is equivalent to th e discrete Fourier tra nsform of x ,or fft(x) . The empty ma tr ix [] specifies the default value for a parameter.

I f x i s a mat r ix, czt(x,m,w,a) transforms the columns of x .

Examples Crea te a ra ndom vector x of lengt h 1013 an d compute its DF T using czt .randn('state',0);x = randn(1013,1);y = czt(x);

U se czt to zoom in on a na rrow-ba nd section (100 to 150 Hz) of a filter ’sfrequency response. First design th e filter.

h = fir1(30,125/500,rectwin(31)); % filter

Page 417: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 417/798

czt

7-134

Est a blish frequency a nd CZT para meters.

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 t he DF T a nd C ZT of the filter.

y = fft(h,1000);

z = czt(h,m,w,a);Create frequency vectors and compare the results.

fy = (0:length(y)-1)'*1000/length(y);fz = ((0:length(z)-1)'*(f2-f1)/length(z)) + f1;plot(fy(1:500),abs(y(1:500))); axis([1 500 0 1.2])title('FFT')figure

plot(fz,abs(z)); axis([f1 f2 0 1.2])title('CZT')

Algorithm czt uses t he next pow er-of-2 lengt h F FT to perform a fa st convolution wh en

computing the z -tr a nsform on a specified chirp cont our [1].

Diagnostics I f m, w, or a i s not a scala r, czt gives the following error messa ge.

Inputs M, W, and A must be scalars.

See Also fft , freqz

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

t

Page 418: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 418/798

czt

7-135

References [1] Ra biner, L.R., and B . G old. Th eory and Appl i cat ion of Di gi ta l Si gnal Processing . E nglewood Cliffs, NJ : P rent ice-Ha ll, 1975. P gs. 393-399.

d t

Page 419: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 419/798

dct

7-136

7dctPurpose Discrete cosine t ra nsform (DCT)

Syntax y = dct(x)y = dct(x,n)

Description y = dct(x) returns t he unita ry discrete cosine tra nsform of x

where

N is the length of x , and x a nd y ar e the sam e size. If x i s a mat r ix, dct tr a nsforms it s columns. The series is indexed from n = 1 a nd k = 1 in s t ea d ofthe usual n = 0 a nd k = 0 beca use MATLAB vectors run from 1 to N instead offrom 0 to N - 1.

y = dct(x,n) pads or truncates x to length n before transforming.

The D CT is closely relat ed t o the discrete F ourier t ra nsform. You ca n oftenreconst ruct a sequence very a ccura tely from only a few D CT coefficients, auseful property for applications requiring data reduction.

y k ( ) w k ( ) x n ( ) π 2 n 1–( ) k 1–( )

2 N

-------------------------------------------cos

n 1=∑k 1 … N , ,=,=

w k ( )

1N

--------- k 1=,

2N ---- 2 k N ≤ ≤,

=

dct

Page 420: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 420/798

dct

7-137

Example Find how m a ny D CT coefficients represent 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 fft , idct , dct2 , idct2

References [1] J a in, A.K. Fu nd am ent als of Di gital I m age Pr ocessin g . En glewood C liffs, NJ :Prentice-Hall, 1989.

[2] P ennebaker, W.B ., an d J .L. Mitchell. J PEG St i l l I mage Data Compr ession S tandard . New York, NY: Va n Nostr a nd R einhold, 1993. Cha pter 4.

decimate

Page 421: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 421/798

decimate

7-138

7decimatePurpose Decrease th e sampling ra te for a sequence (decima tion)

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 th e original sa mpling ra te for a sequence to a lower ra te,th e opposite of int erpola tion. The decima tion process filters t he input da ta w itha lowpa ss fil ter an d then resa mples the result ing smoothed signal a t a lowerra te .

y = decimate(x,r) reduces th e sample rat e of x by a fa ctor r . The decima t edvector y is r t imes shorter in length t ha n t he input vector x . By defa ult ,decimate employs a n eight h-order low pass Ch ebyshev Type I filter. It filtersth e input sequ ence in both t he forw a rd a nd reverse directions to remove allpha se distort ion, effectively doubling th e filter order.

y = decimate(x,r,n) uses an order n Ch ebyshev filter. Orders a bove 13 ar e notrecommended beca use of numerical insta bility . MATLAB displays a w a rningin th is ca se.

y = decimate(x,r,' fir ') uses a 30-point FI R filter, instea d of the Ch ebyshevIIR fi lter. Here decimate filters t he input sequence in only one direction. Thistechnique conserves memory an d is useful for w orking wit h long sequences.

y = decimate(x,r,n,' fir ') uses a length n FIR fi lter.

Example Decimat e 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);

decimate

Page 422: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 422/798

decimate

7-139

View t he original a nd 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 decimat ion a lgorith ms 8.2 a nd 8.3 from [1]:

1 It designs a lowpa ss fi lter. By defa ult , decimate uses a Chebyshev Type Ifilter wit h norma lized cutoff frequency 0.8/r and 0 .05 dB of passbandripple. For t he fir option, decimate designs a lowpa ss FIR fi lter w ith cutofffrequency 1/r using fir1 .

2 For the FI R fi l ter, decimate a pplies the filter t o the input vector in onedirection. In t he IIR ca se, decimate a pplies th e fil ter in forw ar d a nd reversedirections with filtfilt .

3 decimate resa mples the filtered da ta by selecting every r th point .

Diagnostics I f r is not a n integer, decimate gives the following error messa ge.

Resampling rate R must be an integer.

I f n specifies an IIR fi lter w ith order great er tha n 13, decimate gives thefollowing wa rning.

Warning: IIR filters above order 13 may be unreliable.

See Also downsample , interp , resample , spline , upfirdn , upsample

0 50 100-2

-1

0

1

2Original Signal

0 10 20 30-2

-1

0

1

2Decimated Signal

decimate

Page 423: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 423/798

decimate

7-140

References [1] IE E E. Program s for Di gital Signal Pr ocessin g . IEE E P ress. New York: J ohnWiley & Sons , 1979. Ch a pter 8.

deconv

Page 424: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 424/798

7-141

7deconvPurpose Deconvolution a nd polynomial division

Syntax [q,r] = deconv(b,a)

Description [q,r] = deconv(b,a) deconvolves vector a out of vector b , using long division.The result (qu otient ) is retu rn ed in vector q a nd t he remainder in vector r sucht h a t b = conv(q,a) + r .

I f a a nd b are vectors of polynomial coefficients, convolving them is equivalent

to polynomial mu ltiplica tion, a nd d econvolution is equiva lent t o polynomia ldivision. The resu lt of dividin g b by a is quotient q an d remainder r .

The deconv function is part of the st a nda rd MATLAB langua ge.

Example The convolution of a = [1 2 3] a nd b = [4 5 6] is

c = conv(a,b)c =

4 13 28 27 18

U se deconv to divide b ba ck out.

[q,r] = deconv(c,a)q =

4 5 6r =

0 0 0 0 0

Algorithm This function calls filter to compute t he deconvolution as th e impulseresponse of an II R filter.

See Also conv , filter , residuez

demod

Page 425: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 425/798

7-142

7demodPurpose Demodulation for communications simulation

Syntax x = demod(y,fc,fs,' method ')x = demod(y,fc,fs,' method ',opt)x = demod(y,fc,fs,' pwm',' centered ')[x1,x2] = demod(y,fc,fs,' qam ')

Description demod performs demodula tion, tha t is , i t obta ins th e original signa l from amodulat ed version of the signa l. demod undoes th e operat ion performed bymodulate .

x = demod(y,fc,fs,' method ') a nd

x = demod(y,fc,fs,' method ',opt) demodulat e the real carrier signal y wi th acarr ier frequency fc a nd sa mpling frequency fs , using one of t he options listedbelow for method . (Note tha t some methods a ccept a n option, opt .)

amdsb-scoram

Amplitude demodulation, double sideband, suppressedcarrier. Multiplies y by a sinusoid of frequency fc an d a pplies afifth-order B utt erworth lowpa ss fi l ter using filtfilt .

x = y.*cos(2*pi*fc*t);[b,a] = butter(5,fc*2/fs);x = filtfilt(b,a,x);

amdsb-tc Amplitude demodulation, double sideband, transmittedcarrier. Multiplies y by a sinusoid of frequency fc , an d a pplies afifth-order B utt erworth lowpa ss fi l ter using filtfilt .

x = y.*cos(2*pi*fc*t);[b,a] = butter(5,fc*2/fs);x = filtfilt(b,a,x);

If y ou specify opt , demod subtra cts scala r opt from x . The defa ultva lue for opt is 0.

amssb Amplitude demodulation, single sideband. Multiplies y by asinusoid of frequency fc a nd a pplies a f ifth-order B utt erworthlowpass filter using filtfilt .

x = y.*cos(2*pi*fc*t);[b,a] = butter(5,fc*2/fs);x = filtfilt(b,a,x);

demod

Page 426: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 426/798

7-143

The defa ult m ethod is 'am'. In a ll cases except 'ppm' a nd 'pwm', x i s thesa me size as y .

I f y i s a mat r ix, demod demodulat es its columns .

x = demod(y,fc,fs,' pwm',' centered ') finds the pulse widths a ssuming theya re cent ered at th e beginning of each period. x is lengt h length(y)*fc/fs .

See Also modulate , vco

fm Frequency demodulation. Demodulat es the FM w aveform bymodula ting t he Hilbert t ra nsform of y by a complex exponent ialof frequency -fc Hz a nd obta ins the instan ta neous frequency ofthe result .

pm Phase demodulation. Demodulat es the PM w aveform bymodula ting t he Hilbert t ra nsform of y by a complex exponent ialof frequency – fc Hz a nd obta ins the insta nta neous pha se of theresult .

ppm Pulse-position demodulation. Finds th e pulse positions of apulse-position m odulat ed sign a l y. For correct demodulat ion, t hepulses ca nnot overla p. x is lengt h length(t)*fc/fs .

pwm Pulse-width demodulation. Finds t he pulse widt hs of apulse-width modulated signal y. demod returns in x a vectorw hose elements specify th e widt h of each pulse in fra ctions of aperiod. The pulses in y should sta rt a t t he beginning of each

carr ier period, tha t is, th ey should be left justified.qam Quadrature amplitude demodulation.

[x1,x2] = demod(y,fc,fs,'qam') multiplies y by a cosine an d asine of frequency fc a nd a pplies a f ifth-order B utt erworthlowpass filter 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);

dftmtx

Page 427: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 427/798

7-144

7dftmtxPurpose Discrete Fourier tra nsform ma trix

Syntax A = dftmtx(n)

Description A di screte Fouri er t r ansform matr ix is a complex ma trix of va lues a round theunit circle, whose ma tr ix product wit h a vector comput es the discrete Fouriertr a nsform of the vector.

A = dftmtx(n) re turns the n-by-n complex mat rix A tha t , when multiplied intoa length n column vector x .

y = A*x

comput es the discrete Fourier t ra nsform of x .

The inverse discrete Fourier tr a nsform ma tr ix is

Ai = conj(dftmtx(n))/n

Example In pra ctice, the discrete Fourier tra nsform is computed more efficiently a nduses less memory with an FFT algorithm

x = 1:256;y1 = fft(x);

tha n by using the Fourier tra nsform ma trix.

n = length(x);y2 = x*dftmtx(n);norm(y1-y2)

ans =1.8297e-009

Algorithm dftmtx ta kes the FFT of the identi ty ma trix to generat e the tra nsform ma trix.

See Also convmtx , fft

diric

Page 428: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 428/798

7-145

7diricPurpose Compute t he D irichlet or periodic sinc function

Syntax y = diric(x,n)

Description y = diric(x,n) returns a vector or a rra y y the sa me size as x . The elemen t s ofy a re th e Dirichlet fun ction of the element s of x . n must be a positive integer.

The D irichlet fu nct ion, or periodic sinc function, is

for an y nonzero integer n . This fun ction h a s period 2 π for n odd an d period 4 π for n even. It s peak va lue is 1, a nd it s minimum va lue is -1 for n even. Thema gnitu de of this function is (1/n ) times t he ma gnitu de of th e discrete-time

Fourier t ra nsform of the n-point recta ngular window.

Diagnostics I f n is not a positive integer, diric gives the following error messa ge.

Requires n to be a positive integer.

See Also cos , gauspuls , pulstran , rectpuls , sawtooth , sin , sinc , square , tripuls

diric x n ,( )1–

x 2 π------- n 1–( ) x 0 2 π± 4 π± …, , ,=

n x 2 ⁄ ( )sinn x 2 ⁄ ( )sin---------------------------- else

=

downsample

Page 429: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 429/798

7-146

7downsamplePurpose Decrease the sa mpling ra te of the input signa l

Syntax y = downsample(x,n)y = downsample(x,n,phase)

Description y = downsample(x,n) decreases th e sam pling ra te of x by keeping every n t h sam ple sta rt ing wit h the first sa mple. x ca n be a vector or a ma trix. If x is ama tr ix, each column is considered a sepa ra te sequence.

y = downsample(x,n,phase) specifies th e number of samples by w hich tooffset th e down sa mpled sequence. phase must be a n integer from 0 to n-1.

Examples Decrease th e sampling ra te of a seq uence by 3.

x = [1 2 3 4 5 6 7 8 9 10];y = downsample(x,3)

y =1 4 7 10

Decrease th e sampling ra te of th e sequence by 3 a nd a dd a pha se offset of 2.

y = downsample(x,3,2)

y =3 6 9

Decrease the sa mpling ra te of a ma trix by 3.x = [1 2 3; 4 5 6; 7 8 9; 10 11 12];y = downsample(x,3);x,y

x =1 2 34 5 6

7 8 910 11 12

y =1 2 3

10 11 12

Page 430: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 430/798

dpss

Page 431: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 431/798

7-148

7dpssPurpose Discrete prolat 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,' int ')[e,v] = dpss(n,nw,' int ',Ni)[e,v] = dpss(...,' trace ')

Description [e,v] = dpss(n,nw) genera tes th e first 2*nw di scr ete pr olat e spher oid al sequences (DP SS ) of length n in t he columns of e , an d th eir correspondingconcentra tions in vector v . They a re a lso genera ted in th e DP SS MAT-filed a t a b a s e dpss.mat . nw must be less tha n n/2 .

[e,v] = dpss(n,nw,k) re turns the k most ba nd-limited discrete prolat espheroida l sequences. k must be an integer such tha t 1 ≤k ≤n .

[e,v] = dpss(n,nw,[k1 k2]) re turns the k1 s t through the k2 nd discreteprola te spheroidal sequences, w here 1 ≤k1 ≤k2 ≤n .

For a ll of th e above forms:

• The Slepian s equences a re calculat ed directly.• The sequences a re generat ed in the frequency ban d | ω| ≤ (2 π W) , where

W = nw/n is the ha lf-band width a nd ω is in r a d/sa mple.• e(:,1) is the length n signal most concentr at ed in the frequency ba nd

| ω| ≤ (2 π W) r ad ians , e(:,2) is the signal orthogona l to e(:,1) tha t i s mostconcentr a ted in th is band, e(:,3) is the signa l ort hogona l to both e(:,1) a nd e(:,2) tha t is most concentr a ted in this ban d, etc.

• For multit a per spectra l an a lysis, typica l choices for nw a re 2, 5/2, 3, 7/2, or 4.

[e,v] = dpss(n,nw,' int ') uses th e interpola tion meth od specified by thestring ' int ' to comput e e a nd v from th e sequences in dpss.mat with lengthclosest to n . The st ring ' int ' can be either:

• 'spline' : Use spline interpolat ion.• 'linear' : Use linear int erpolat ion. This is much fast er but less accura te

tha n spline interpolat ion.

dpss

Page 432: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 432/798

7-149

[e,v] = dpss(n,nw,' int ',Ni) interpolat es from existing lengt h Ni sequences.

The int erpolat ion meth od 'linear' requires Ni > n .

[e,v] = dpss(...,' trace ') uses the tra iling string ' trace ' to displa y w hichinterpolat ion method DP SS uses . If you don’t specify t he int erpolat ion m ethod,the display indica tes tha t you are using the di r ect method .

Examples Example 1: Using dpss, dpssave, and dpssdirCrea te a cata logue of 16 DPS S functions wit h nw = 4, and use spl ine

int erpola tion on 10 of th ese functions wh ile displaying t he interpolat ionmeth od you use. You can do this using dpss , dpsssave , and dpssdir .

% Create the catalogue of functions.[e,v] = dpss(16,4);

% Save e and v in a MAT-file.dpsssave(4,e,v);

% Find nw = 4. First create a structure called index.index = dpssdir;index.wlistsans =

NW: 4key: 1

% Use spline interpolation on 10 of the DPSS functions.[e1,v1] = dpss(10,4,'spline',size(e,1),'trace');

Exa mp le 2 : Using d pss a nd d pssloadCrea te a set of DP SS functions using dpss , an d use the spline meth od on asubset of these functions. U se dpssload to loa d t he MAT-file creat ed by dpss .

% Create the catalogue of functions.[e,v] = dpss(16,4);

% Load dpss.mat, where e and v are saved.[e1,v1] = dpssload(16,4);

% Use spline interpolation on 10 of the DPSS functions.[e1,v1] = dpss(10,4,'spline');

See Also dpssclear , dpssdir , dpssload , dpsssave , pmtm

dpss

Page 433: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 433/798

7-150

References [1] P ercival, D .B ., a nd A.T. Wa lden. Spectr al An al ysis for Ph ysical

Appl i cat ions: M ul t i taper and Convent i onal U ni var i a te Techni ques . Ca mbridge:Cambridge University Press, 1993.

dpssclear

Page 434: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 434/798

7-151

7dpssclearPurpose Remove discrete prolat e spheroidal sequences from dat a bas e

Syntax dpssclear(n,nw)

Description dpssclear(n,nw) removes sequences with length n and t ime-bandwidthproduct nw from the DP SS MAT-file da ta bas e dpss.mat .

See Also dpss , dpssdir , dpssload , dpsssave

dpssdir

Page 435: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 435/798

7-152

7dpssdirPurpose Discrete prolate spheroidal sequences database directory

Syntax dpssdirdpssdir(n)dpssdir(nw,' nw')dpssdir(n,nw)index = dpssdir

Description dpssdir mana ges the dat aba se directory that conta ins the generated DP SSsamples in the DPSS MAT-file database dpss.mat .

dpssdir lists t he directory of saved sequences in dpss.mat .

dpssdir(n) l ists t he sequences sa ved with length n .

dpssdir(nw,' nw') lists the sequences saved with time-bandwidth product nw.

dpssdir(n,nw) l ists t he sequences sa ved with length n and t ime-bandwidthproduct nw.

index = dpssdir i s a s t ructure arra y descr ibing the DPSS dat aba se. Pa ss na nd nw options a s for t he no out put ca se to get a filtered index .

Examples S ee “Exa mple 1: U sing dpss, dpssa ve, an d dpssdir” on pa ge 7-149 .

See Also dpss , dpssclear , dpssload , dpsssave

dpssload

Page 436: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 436/798

7-153

7dpssloadPurpose Load discrete prolat e spheroidal sequences from da ta base

Syntax [e,v] = dpssload(n,nw)

Description [e,v] = dpssload(n,nw) loa ds a ll sequences w ith length n a ndtime-bandwidth product nw in t he columns of e and their correspondingconcentra tions in vector v from the DP SS MAT-file da ta bas e dpss.mat .

Examples S ee “Exa mple 2: U sing dpss a nd d pssloa d” on page 7-149 .

See Also dpss , dpssclear , dpssdir , dpsssave

dpsssave

Page 437: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 437/798

7-154

7dpsssavePurpose Sa ve discrete prolat e spheroida l sequences in da ta base

Syntax dpsssave(nw,e,v)status = dpsssave(nw,e,v)

Description dpsssave(nw,e,v) sa ves the sequences in the columns of e and t heircorresponding concentr a tions in vector v in th e DP SS MAT-file dat a basedpss.mat .

It is not necessa ry t o specify sequence length, because th e lengt h of thesequence is determin ed by th e number of rows of e .• nw i s the t im e-bandw id th product tha t w as specified when the sequence wa s

crea ted using dpss .

status = dpsssave(nw,e,v) re turns 0 if the save wa s successful an d 1 if therewa s an error.

Examples S ee “Exa mple 1: U sing dpss, dpssa ve, an d dpssdir” on pa ge 7-149 .

See Also dpss , dpssclear , dpssdir , dpssload

ellip

Page 438: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 438/798

7-155

7ellipPurpose E lliptic (Cau er) filter d esign

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 lowpa ss, ba ndpass, highpass, and ban dstop digita l and a na logelliptic filters. Elliptic filters offer st eeper rolloff char a cteristics th a nB utt erworth or Chebyshev fil ters, but a re equiripple in both t he pass- a ndstopban ds. In genera l, elliptic filters meet given performan ce specifica tionswit h t he lowest order of any fi l ter type.

Digital Domain

[b,a] = ellip(n,Rp,Rs,Wn) designs an order n low pass digita l elliptic filterw ith cutoff frequency Wn , Rp dB of r ipple in the passban d, and a stopband Rs dBdown from the peak va lue in the passba nd. It returns t he filter coefficients in th elength n+1 row vectors b a nd a , w ith coefficient s in d escending powers of z .

The cutoff fr equency is the edge of the passband, a t w hich th e magnituderesponse of th e filt er is -Rp dB . For ellip , th e cutoff frequency Wn is a num berbetw een 0 an d 1, where 1 corresponds to ha lf the sa mpling frequency (Nyqu istfrequency). Sma ller va lues of passba nd ripple Rp a nd lar ger values of stopbandat tenuat ion Rs both lead to wider transition widths (shallower rolloffcharacteristics).

I f Wn is a tw o-element vector, Wn = [w1 w2] , ellip returns a n order 2*n bandpass f i lter wi th passban d w1 <

ω< w2.

H z ( ) B z ( )A z ( )----------- b 1( ) b 2( ) z 1– L b n 1+( ) z n –+ + +

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

ellip

Page 439: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 439/798

7-156

[b,a] = ellip(n,Rp,Rs,Wn,' ftype ') designs a highpass or ban dstop fil ter,

wh ere the str ing ' ftype ' is eith er:• 'high' for a highpass digital filter with cutoff frequency Wn• 'stop' for a n order 2*n bandst op digita l f i lter if Wn is a tw o-element vector,

Wn = [w1 w2] . The stopband is w1 < ω < w2.

With different numbers of output arguments, ellip directly obta ins otherrealizations of the filter. To obtain zero-pole-gain form, use three outputa rguments a s shown below.

[z,p,k] = ellip(n,Rp,Rs,Wn) or

[z,p,k] = ellip(n,Rp,Rs,Wn,' ftype ') retur ns t he zeros a nd poles in lengt hn column vectors z a nd p and the gain in the scala r k .

To obta in sta te-spa ce form, use four output a rgument s a s shown below.

[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 a re

a nd u is the input, x is the sta te vector, and y is the output.

Analog Domain

[b,a] = ellip(n,Rp,Rs,Wn,' s ') designs an order n lowpass analog ellipticfilter wit h cutoff frequency Wn a nd retu rns t he filter coefficient s in the lengthn+1 row vectors b a nd a , in descending powers of s , derived from the tra nsferfunction

The cutoff fr equency is the edge of the passband, a t w hich the ma gnituderesponse of the filter is -Rp dB . For ellip , th e cutoff frequency Wn must begreat er tha n 0 rad/s .

x n 1+[ ] A x n [ ] B u n [ ]+=

y n [ ] C x n [ ] D u n [ ]+=

H s ( ) B s ( )

A s ( )----------- b 1( ) s n b 2( ) s n 1– L b n 1+( )+ + +

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

ellip

Page 440: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 440/798

7-157

I f Wn is a tw o-element vector w ith w1 < w2, then ellip(n,Rp,Rs,Wn,' s ')

returns a n order 2*n bandpass a nalog fi lter wi th passband w1 < ω< w2.

[b,a] = ellip(n,Rp,Rs,Wn,' ftype ',' s ') designs a highpass or bandst opfilter.

With different numbers of output arguments, ellip directly obta ins oth errea lizat ions of t he a na log filter. To obta in zero-pole-ga in form, use t hree outputa rguments a s shown below.

[z,p,k] = ellip(n,Rp,Rs,Wn,' s ') or

[z,p,k] = ellip(n,Rp,Rs,Wn,' ftype ',' s ') retur ns t he zeros a nd poles inlength n or 2*n column vectors z a nd p and the gain in the scala r k .

To obta in sta te-space form, use four output a rgument s a s shown below.

[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

a nd u is the input, x is the sta te vector, and y is the output.

Examples Exa mple 1For dat a sam pled a t 1000 Hz, design a sixth-order lowpa ss ell iptic f il ter with acutoff frequency of 300 Hz, 3 dB of r ipple in the passband, a nd 50 dB ofat tenuat ion in the s topband.

[b,a] = ellip(6,3,50,300/500);

The filt er ’s frequen cy response is

freqz(b,a,512,1000)

title('n=6 Lowpass Elliptic Filter')

x · A x B u +=

y C x D u +=

ellip

Page 441: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 441/798

7-158

Exa mple 2Design a 20th-order bandpa ss elliptic filter wit h a pa ssba nd from 100 to 200 Hza nd plot its 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')

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

−400

−300

−200

−100

0

100

Frequency (Hz)

P h a s e

( d e g r e e s

)

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

−80

−60

−40

−20

0

Frequency (Hz)

M a g n

i t u d e

( d B )

n=6 Lowpass Elliptic Filter

ellip

Page 442: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 442/798

7-159

Limitations For high order filters, th e sta te-space form is the most num erica lly accurat e,followed by the zero-pole-gain form. The transfer function form is the leasta ccura te; numerical problems can a rise for filter orders as low a s 15.

Algorithm The design of elliptic filters is t he most difficult a nd computa tiona lly intensiveof the B utt erworth, Ch ebyshev Type I a nd I I , a nd ell iptic designs. ellip usesa five-step a lgorith m:

1 It f inds the lowpa ss a na log prototype poles, zeros, an d ga in using th eellipap function.

2 It converts t he poles, zeros, an d ga in into sta te-spa ce form.

3 It tra nsforms th e lowpa ss fil ter to a ba ndpass, highpass, or ban dstop fi l terwit h t he desired cutoff frequencies using a sta te-space tra nsforma tion.

4 For digital filter design, ellip uses bilinear to convert t he an a log filterinto a digita l f il ter through a bilinear t ra nsforma tion with frequencyprewar ping. Ca reful frequency ad justment gua ra ntees tha t th e a na logfilters a nd t he digital f i lters w ill have the sa me frequency responsemagni tude a t Wn or w1 a nd w2.

5 It converts th e sta te-spa ce filter ba ck to tr a nsfer fun ction or zero-pole-ga inform, as required.

0 10 20 30 40 50 60 70 80 90 100-0.2

-0.15

-0.1

-0.05

0

0.05

0.1

0.15

0.2

Impulse Response of n = 10 Elliptic Filter

ellip

Page 443: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 443/798

7-160

See Also besself , butter , cheby1 , cheby2 , ellipap , ellipord

ellipap

Page 444: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 444/798

7-161

7ellipapPurpose Elliptic analog lowpass filter prototype

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

Description [z,p,k] = ellipap(n,Rp,Rs) retur ns t he zeros, poles, a nd ga in of a n order n elliptic ana log lowpa ss filter prototype, wit h Rp dB of r ipple in the pa ssband,an d a s topband Rs dB down from t he pea k value in th e passban d. The zeros a ndpoles are retur ned in length n column vectors z a nd p and the gain in scala r k .I f n is odd, z is lengt h n - 1 . The tr a nsfer function is

Elliptic f i lters offer steeper r olloff chara cterist ics tha n B utt erworth a ndChebyshev fi l ters, but t hey ar e equiripple in both the pa ssband an d th estopban d. Of the four cla ssical filter ty pes, elliptic filters usua lly meet a givenset of filter performa nce specifica tions w ith th e lowest filter order.

ellip sets th e cutoff frequency of th e elliptic filter to 1 for a norma lizedresult. The cutoff fr equency is the frequency a t w hich the passba nd ends andth e filter ha s a ma gnit ude response of 10 -Rp/20 .

Algorithm ellipap uses t he a lgorith m outlined in [1]. It employs t he M-file ellipk t ocalculat e the complete elliptic integra l of th e first kind a nd t he M-file ellipj to calculat e J a cobi elliptic functions.

See Also besselap , buttap , cheb1ap , cheb2ap , ellip

References [1] P a rks, T.W., an d C .S. B urru s. Di gi ta l F i l ter D esign . New York: J ohn Wiley& Sons, 1987. Cha pter 7.

H s ( ) z s ( )p s ( )---------- k

s z 1( )–( ) s z 2( )–( )L s z n ( )–( )s p 1( )–( ) s p 2( )–( )L s p n ( )–( )--------------------------------------------------------------------------------= =

ω0

ellipord

Page 445: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 445/798

7-162

7ellipordPurpose Ca lcula te t he minimum order for elliptic filters

Syntax [n,Wn] = ellipord(Wp,Ws,Rp,Rs)[n,Wn] = ellipord(Wp,Ws,Rp,Rs,' s ')

Description ellipord calculat es the minimum order of a digit a l or a na log elliptic filterrequired t o meet a set of filter design specifica tions.

Digital Domain

[n,Wn] = ellipord(Wp,Ws,Rp,Rs) returns the lowest order n of the ellipticfi lter t ha t loses no more tha n Rp dB in the passband a nd has a t leas t Rs dB ofa tt enua tion in t he stopban d. The scala r (or vector) of corresponding cutofffrequencies Wn , is also returned. Use the output a rguments n a nd Wn in ellip .

Choose the input a rguments t o specify the stopban d a nd pa ssband a ccording toth e follow ing ta ble.

Table 7-7: Description of Stopband and Passband Filter Parameters

Wp Pa ssband corner frequency Wp , th e cut off frequency, is a scala ror a tw o-element vector with va lues betw een 0 and 1, with 1corresponding to t he norma lized Nyq uist fr equency, π r ad iansper sa mple.

Ws St opba nd corner frequency Ws , is a scala r or a t wo-element

vector w ith va lues betw een 0 a nd 1, with 1 corresponding t oth e norma lized Nyqu ist frequency.

Rp Pa ssba nd ripple, in decibels. Tw ice th is va lue specifies t hemaximum permissible passband width in decibels.

Rs St opba nd a tt enua tion, in decibels. This va lue is th e number ofdecibels the stopba nd is a t t enuat ed with respect t o thepassband response.

ellipord

Page 446: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 446/798

7-163

U se th e follow ing guide t o specify filters of different types.

If your fi l ter specifications ca ll for a bandpa ss or bandst op fi lter w ith u nequal

ripple in ea ch of the pa ssbands or st opbands, design sepa ra te lowpa ss a ndhighpass fi l ters a ccording t o the specifications in t his ta ble, a nd cascad e thetw o fil ters together.

Analog Domain

[n,Wn] = ellipord(Wp,Ws,Rp,Rs,' s ') finds th e minimum order n a nd cutofffrequencies Wn for a n a na log filter. You specify th e frequencies Wp a nd Ws

s imila r to Ta ble 7-7 , only in t his case you specify th e frequency in ra dia ns persecond, a nd t he passban d or the st opband ca n be infinite.

U se ellipord for lowpa ss, highpass, ban dpass, a nd ba ndstop fi l ters asdescribed in Ta ble 7-8 .

Table 7-8: Filter Type Stopband and Passband Specifications

Filter Type Stopband and Passband Conditions Stopband Passband

Lowpass Wp < Ws , both scala rs (Ws,1) (0,Wp)

Highpass Wp > Ws , both scala rs (0,Ws) (Wp,1)

B andpa ss The in t erva l specified by Ws contains

th e one specified by Wp ( Ws(1) < Wp(1) < Wp(2) < Ws(2) ).

(0,Ws(1))

a nd(Ws(2),1)

(Wp(1),Wp(2))

B andst op The in t erva l specified by Wp containsth e one specified by Ws ( Wp(1) < Ws(1) < Ws(2) < Wp(2) ).

(0,Wp(1)) a nd(Wp(2),1)

(Ws(1),Ws(2))

ellipord

Page 447: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 447/798

7-164

Examples Exa mple 1

For 1000 Hz da ta , design a lowpa ss fil ter with less tha n 3 dB of r ipple in thepassba nd defined from 0 to 40 Hz a nd a t least 60 dB of r ipple in the stopbanddefined from 150 Hz to th e Nyquist frequency (500 Hz).

Wp = 40/500; Ws = 150/500;Rp = 3; Rs = 60;[n,Wn] = ellipord(Wp,Ws,Rp,Rs)

n =

4

Wn =0.0800

[b,a] = ellip(n,Rp,Rs,Wn);freqz(b,a,512,1000);title('n=4 Elliptic Lowpass Filter')

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

−300

−200

−100

0

100

Frequency (Hz)

P h a s e

( d e g r e e s

)

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

−100

−80

−60

−40

−20

0

Frequency (Hz)

M a g n

i t u d e

( d B )

n=4 Elliptic Lowpass Filter

ellipord

Page 448: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 448/798

7-165

Exa mple 2

Now design a ba ndpass f il ter w i th a passband f rom 60 Hz t o 200 Hz, wi th lesstha n 3 dB of r ipple in the passband, and 40 dB a t tenuat ion in the s topbandstha t a re 50 Hz w ide on both sides of the pa ssband.

Wp = [60 200]/500; Ws = [50 250]/500;Rp = 3; Rs = 40;[n,Wn] = ellipord(Wp,Ws,Rp,Rs)

n =

5 Wn =

0.1200 0.4000

[b,a] = ellip(n,Rp,Rs,Wn);freqz(b,a,512,1000);title('n=5 Elliptic Bandpass Filter')

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

0

500

Frequency (Hz)

P h a s e

( d e g r e e s

)

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

−250

−200

−150

−100

−50

0

Frequency (Hz)

M a g n

i t u d e

( d B )

n=5 Elliptic Bandpass Filter

ellipord

Page 449: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 449/798

7-166

Algorithm ellipord uses t he elliptic lowpa ss filter order prediction formula described

in [1]. The function performs its calcula tions in th e ana log domain for both th ea na log a nd digita l cases. For t he digital case, i t converts th e frequencypara meters to the s -doma in before estima ting t he order a nd na tura lfrequencies, and then converts them back to the z -domain.

ellipord initially develops a lowpass filter prototype by transforming thepas sba nd frequencies of th e desired filter t o 1 rad /s (for low - a nd highpa ssfilters) a nd t o -1 and 1 rad /s (for ba ndpa ss a nd ba ndst op filters). It th encomput es the minimum order required for a lowpa ss filter to meet t he stopbandspecification.

See Also buttord , cheb1ord , cheb2ord , ellip

References [1] Ra biner, L.R., an d B . G old. Th eory and Appl i cat ion of Di gi ta l Si gnal Processing . Englew ood Cliffs, NJ : Pr entice-Ha ll, 1975. Pg . 241.

eqtflength

Page 450: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 450/798

7-167

7eqtflengthPurpose Make th e lengths of a tra nsfer function’s numerat or and denominat or equa l

Syntax [b,a] = eqtflength(num,den)[b,a,n,m] = eqtflength(num,den)

Description [b,a] = eqtflength(num,den) modifies th e vector num a nd /or th e vector den ,so tha t the result ing output vectors b a nd a ha ve the sa me lengt h. The inputvectors num a nd den ma y ha ve different lengths . The vector num represents thenumera tor polynomial of a given discrete-time t ra nsfer function, and th e vector

den represent s its denomina tor. The resulting numera tor b a nd denominat or a represent t he sa me discrete-time tr a nsfer function, but t hese vectors have th esa me length.

[b,a,n,m] = eqtflength(num,den) modifies the vectors a s a bove and a lsoreturns t he numerat or order n a nd the denomina tor m, not including anytrailing zeros.

U se eqtflength to obta in a numerat or a nd denomina tor of equal length beforea pplying t ra nsfer function conversion functions such a s tf2ss a nd tf2zp t odiscrete-time models.

Examples num = [1 0.5];den = [1 0.75 0.6 0];[b,a,n,m] = eqtflength(num,den)

b =

1.0000 0.5000 0

a =1.0000 0.7500 0.6000

n =1

m =2

Algorithm eqtflength(num,den) a ppends zeros t o either num or den a s necessary. If bothnum a nd den ha ve tra iling zeros in common, these a re removed.

See Also tf2ss , tf2zp

fdatool

Page 451: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 451/798

7-168

7fdatoolPurpose Open t he Filter D esign a nd Ana lysis Tool

Syntax fdatool

Description fdatool opens t he Filt er Design a nd Ana lysis Tool (FD ATool). U se th is tool to:

• Design filters• Ana lyze filters• Modify existing filter designs

S ee Cha pter 5, “Fil ter Design a nd Analysis Tool,” for more informa tion.

Remarks The Filter D esign a nd Ana lysis Tool provides more design m ethods t ha n t heSP Tool Filt er D esigner.

fdatool

Page 452: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 452/798

7-169

Note The F ilter D esign a nd Ana lysis Tool requir es a screen r esolutiongreat er tha n 640 x 480.

See Also sptool , fvtool

fft

7fftP C h di i l f F i f

Page 453: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 453/798

7-170

7fftPurpose Compute the one-dimensional fast Fourier transform

Syntax y = fft(x)y = fft(x,n)

Description fft computes t he discrete Fourier t ra nsform of a vector or ma tr ix. Thisfunction implements the transform given by

where W N = e - j (2π/N ) a nd N = length(x) . Note t ha t the series is indexed asn + 1 a nd k + 1 instead of the usua l n a nd k becaus e MATLAB vectors run from1 t o N instea d of from 0 to N -1.

y = fft(x) is th e discrete Fourier t ra nsform of vector x , computed with a fastFourier tr a nsform (FF T) a lgorith m. If x i s a mat r ix, y is t he FF T of ea ch column

of the ma trix.

y = fft(x,n) i s the n-point F FT. If t he lengt h of x is less tha n n , fft pads x wit h t ra il ing zeros to length n . If th e lengt h of x i s greater tha n n , fft t runcatesth e sequence x . I f x i s an a r ray, fft a djusts t he length of the columns in t hesame manner.

The fft function is pa rt of the sta nda rd MATLAB langua ge.

Examples A common us e of th e Fourier tr a nsform is t o find th e frequency components ofa t ime-domain signa l buried in noise. Consider da ta sam pled a t 1000 Hz. Forma signa l consist ing of 50 Hz a nd 120 Hz sinusoids and corrupt th e signa l withzero-mea n ra ndom n oise.

randn('state',0)t = 0:0.001:0.6;x = sin(2*pi*50*t) + sin(2*pi*120*t);

y = x + 2*randn(1,length(t));plot(y(1:50))

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

k n

n 0=

∑=

fft

Page 454: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 454/798

7-171

It is difficult to ident ify the frequency component s by study ing th e origina lsignal. Convert to the frequency domain by taking the discrete Fouriertra nsform of the noisy signa l y using a 512-point fa st Fourier t ra nsform (FFT).

Y = fft(y,512);

The pow er spectra l density, a m easu rement of the energy at va riousfrequencies, is

Pyy = Y.*conj(Y) / 512;

G ra ph t he first 256 points (th e oth er 256 points a re symmet ric) on ameaningful frequency axis.

f = 1000*(0:255)/512;plot(f,Pyy(1:256))

0 5 10 15 20 25 30 35 40 45 50−5

−4

−3

−2

−1

0

1

2

3

4

5

Page 455: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 455/798

fft2

7fft2Purpose Compute the t wo-dimensiona l fa st Fourier t ra nsform

Page 456: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 456/798

7-173

Purpose Compute the t wo dimensiona l fa st Fourier t ra nsform

Syntax Y = fft2(X)Y = fft2(X,m,n)

Description Y = fft2(X) performs a tw o-dimensional F FT, producing a result Y wi th thesa me size as X. I f X is a vector, Y has the same or ienta t ion as X.

Y = fft2(X,m,n) trunca tes or zero pads X, if necessa ry, t o crea te a n m-by-n a rra y before performing th e FFT. The result Y is also m-by-n .

The fft2 function is pa rt of the sta nda rd MATLAB langua ge.

Algorithm fft2(x) is simply

fft(fft(x).').'

This computes the one-dimensional fft of each column of x , th en of each row of the result . The t ime required t o compute fft2(x) depends on t he number ofprime factors in [m,n] = size(x) . fft2 is fast est when ma nd n are powers of 2.

See Also fft , fftshift , ifft , ifft2

fftfilt

7fftfiltPurpose FF T-ba sed FIR filtering using t he overlap-a dd met hod

Page 457: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 457/798

7-174

p g g p

Syntax y = fftfilt(b,x)y = fftfilt(b,x,n)

Description fftfilt filters da ta using t he efficient F FT-ba sed method of overlap-add , afrequency domain filtering technique that works only for FIR filters.

y = fftfilt(b,x) fi lters th e dat a in vector x wit h t he filter described bycoefficient vector b . I t returns the dat a vector y . The opera t ion performed byfftfilt is described in th e t im e domain by th e difference equa tion

An equivalent r epresenta tion is the z -tr a nsform or fr equency doma in description

By defaul t , fftfilt chooses an F FT length a nd da ta block length tha tgua ra nt ee efficient execution time.

y = fftfilt(b,x,n) uses a n F FT length of nfft = 2^nextpow2(n) a n d a d a t ablock lengt h of nfft - length(b) + 1 .

fftfilt w orks for both rea l an d complex inputs.

Examples Show th a t th e results from fftfilt a nd filter a re identical .

b = [1 2 3 4];x = [1 zeros(1,99)]';norm(fftfilt(b,x) - filter(b,1,x))

ans =9.5914e-15

Algorithm fftfilt uses fft to implement the over lap -add method [1], a technique t ha tcombines successive frequency doma in filtered blocks of a n in put sequence.fftfilt breaks a n input sequence x into 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

. . .

fftfilt

a nd convolves ea ch block with th e filter b by

Page 458: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 458/798

7-175

y = ifft(fft(x(i:i+L-1),nfft).*fft(b,nfft));

where nfft is the FF T length. fftfilt overlaps successive output sections byn-1 points, where n is the length of the fi lter, a nd sums t hem.

fftfilt chooses the key para meters L a nd nfft in different wa ys, dependingon whet her you supply an FF T length n a nd on the lengths of the fil ter an dsigna l. If you do not specify a va lue for n (w hich det ermines F FT length ),fftfilt chooses these key para meters a utomat ically:

• I f length(x) i s great er than length(b) , fftfilt chooses values th a tminimize the number of blocks times the number of flops per FFT.

• I f length(b) is great er tha n or equal to length(x) , fftfilt uses a singleFF T of lengt h

2^nextpow2(length(b) + length(x) - 1)

This essentia lly computesy = ifft(fft(B,nfft).*fft(X,nfft))

If you supply a va lue for n , fftfilt chooses a n F FT length, nfft , of2^nextpow2(n) a nd a da ta block length of nfft - length(b) + 1 . I f n is less tha nlength(b) , fftfilt sets n t o length(b) .

See Also conv , filter , filtfilt

References [1] Oppenheim, A.V., a nd R.W. Scha fer, D i scr ete-Ti m e Si gnal Pr ocessi ng ,Prentice-Hall, 1989.

nb–1L

nb–12L

nb–13L. . .

fftshift

7fftshiftPurpose Rearrange the outputs of the FFT functions

Page 459: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 459/798

7-176

Syntax y = fftshift(x)

Description y = fftshift(x) rearra nges the outputs of fft a nd fft2 by moving the zerofrequency component t o the cent er of th e spectra l density, w hich is sometimesa more convenient form.

For vectors, fftshift(x) returns a vector with t he left a nd right ha lvesswapped.

For ar ra ys , fftshift(x) swa ps quadra nts one and three wi th qua drant s twoa nd four.

The fftshift function is part of the st a nda rd MATLAB langua ge.

Examples For any a r ray X

Y = fft2(x)

ha s Y(1,1) = sum(sum(X)) ; th e DC component of the signa l is in th e upper-leftcorner of the two-dimensional FFT. For

Z = fftshift(Y)

the D C component is nea r t he center of the ma trix.

See Also fft , fft2

filter

7filterPurpose Filter da ta w ith a recursive (II R) or nonrecursive (FI R) filter

Page 460: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 460/798

7-177

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

Description y = filter(b,a,x) fi lters th e dat a in vector x wit h t he filter described bycoefficient vectors a a nd b to creat e the fi l tered da ta vector y . When x is a

ma tr ix, filter opera tes on th e columns of x . When x i s an N -dimensiona l a rra y,filter operat es on t he first nonsingleton dimension. a(1) cannot be 0 , and i fa(1) ≠ 1 , filter norma lizes t he filter coefficients by a(1) .

[y,zf] = filter(b,a,x) returns t he fina l values zf of the st a te vector. Whenx is a vector, t he size of the fina l condit ion vector zf ismax(length(b),length(a))-1 , the n umber of dela ys in t he filter. When x is amultidimensional array, zf i s an s -by-c ma trix, where:

• s is the num ber of delays in t he filter.• c is prod(size(x))/size(x,dim) , where dim is th e dimension int o which you

a re filtering (th e first nonsingleton dimension by default ).

[...] = filter(b,a,x,zi) specifies initia l sta te conditions in th e vector zi .The size of the init ia l cond ition vector zi must be the same asmax(length(b),length(a))-1 , the num ber of delays in t he filter.

[...] = filter(b,a,x,zi,dim) fi lters the input dat a loca ted along thedimension dim of x . Set zi to th e empty vector [] to use zero initia l condit ions.

The filter function is part of the st a nda rd MATLAB langua ge.

filter

Examples Find a nd gra ph th e 101-point u nit impulse response of a digita l filter.

Page 461: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 461/798

7-178

x = [1 zeros(1,100)];[b,a] = butter(12,400/1000);y = filter(b,a,x);stem(y)

Algorithm filter is implemented a s a tra nsposed direct form II structure [1], a s shownbelow

where n -1 is t he filt er order. The sta te vector z is a vector w hose component sa re derived from the values of th e input s to ea ch dela y in th e filter.

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 )

...

...

...

filter

The opera tion of filter at sa mple m is implemented using the transposeddirect form I I st ructur e This is calculat ed by the time doma in difference

Page 462: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 462/798

7-179

direct form I I st ructur e. This is calculat ed by the time doma in differenceequations for y and the s t a t e s z i.

Note th e division by a (1). For efficient comput a t ion, select t his coefficient t o bea power of 2.

You can u se filtic to genera te th e sta te vector z i(0) from past inputs a ndoutputs.

The input -output description of th is filtering opera tion in th e z -transformdomain is a ra tional tra nsfer function.

See Also fftfilt , filter2 , filtfilt , filtic

References [1] Oppenheim, A.V., a nd R.W. Scha fer, D i scr ete-Ti m e Si gnal Pr ocessi ng ,P rent ice-H a ll, 1989, pp. 311-312.

y m ( )b 1( ) x m ( ) z 1 m 1–( )+( )

a 1( )----------------------------------------------------------=

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

M M=

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

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

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

filter2

7filter2Purpose Tw o-dimensional digita l filtering

Page 463: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 463/798

7-180

Syntax Y = filter2(B,X)Y = filter2(B,X,' shape ')

Description Y = filter2(B,X) fi lters t he tw o-dimensiona l da ta in X wi th thetw o-dimensional FI R fi l ter in t he ma trix B. The resu lt, Y, is computed usingtw o-dimensional convolution a nd is th e same size as X.

Y = filter2(B,X,' shape ') re turns Y comput ed w ith size specified by' shape ' :

• 'same' returns t he centra l part of the convolution t ha t is t he same size as X (default).

• 'full' retur ns t he full tw o-dimensional convolution, when size(Y) exceedssize(X) .

• 'valid' retur ns only those par ts of the convolution th a t a re computed

w ithout t he zero-pad ded edges, w hen size(Y) is less tha n size(X) .The filter2 function is part of the st a nda rd MATLAB langua ge.

Algorithm The filter2 function uses conv2 to compute t he full tw o-dimensionalconvolution of the FIR fi l ter with the input ma trix. By d efa ult , filter2 extra cts and returns t he centra l part of the convolution th at is the same size asthe input mat rix. U se the ' shape ' para meter to specify an a lternat e pa rt of theconvolution for retur n.

See Also conv2 , filter

filternorm

7filternormPurpose Compute t he 2-norm or infinity -norm of a digita l filter

Page 464: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 464/798

7-181

Syntax filternorm(b,a)filternorm(b,a,pnorm)filternorm(b,a,2,tol)

Description A ty pica l use for filter norms is in digita l filter sca ling to reduce qua nt izat ioneffects. Sca ling often improves t he signa l-to-noise rat io of t he filter w ithoutresulting in da ta overflow. You, a lso, can us e the 2-norm t o compute the energyof the impulse response of a filter.

filternorm(b,a) computes t he 2-norm of the digit a l filter defined by th enum era tor coefficients in b a nd d enominat or coefficients in a .

filternorm(b,a,pnorm) comput es t he 2- or infin ity -norm (inf-norm) of thedigital f i l ter, where pnorm is either 2 or inf .

filternorm(b,a,2,tol) computes t he 2-norm of a n II R filter wit h t hespecified tolerance, tol . The t olera nce can be specified only for II R 2-normcomputations. pnorm in this case must be 2 . I f tol is not specified, it defa ults t o1e-8 .

Examples Compute t he 2-norm w ith a toleran ce of 1e-10 of an II R filter.

[b,a]=butter(5,.5);L2=filternorm(b,a,2,1e-10)

L2 =

0.7071

Compute t he inf-norm of a n FI R filter.

b=remez(30,[.1 .9],[1 1],'Hilbert');Linf=filternorm(b,1,inf)

Linf =

1.0028

filternorm

Algorithm G iven a filter H (z) wit h frequency reponse H(e jω), th e L p-norm is given by

Page 465: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 465/798

7-182

For th e case , th e norm simplifies to

For the case p = 2 , Pa rseval’s theorem stat es tha t

where h(n) is the impulse response of the filter. The energy of the impulse

response, th en, is .

See Also zp2sos , norm

Reference J a ckson, L.B., Di gi ta l Fi l ters and Signal Processin g , Third E dition, Kluw erAcademic Publishers, 1996, Chapter 11.

H p 1

2 π------ H e j ω( )

p ωd

π–

π

∫ 1p ---

p ∞= L ∞

H ∞m a x

π ω π≤ ≤–H e

j ω( )=

H 21

2 π------ H e j ω( )

2ωd

π–

π

∫ 12---

h n ( )2

n ∞–=

∑12---

= =

H 22

filtfilt

7filtfiltPurpose Zero-pha se digita l filtering

Page 466: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 466/798

7-183

Syntax y = filtfilt(b,a,x)

Description y = filtfilt(b,a,x) performs zero-pha se digita l filtering by processing t heinput da ta in both th e forw a rd a nd reverse directions (see problem 5.39 in [1]).After filtering in t he forw a rd direction, it r everses th e filtered sequence a ndrun s it back t hrough t he filter. The resulting sequence has precisely zero-pha sedistort ion a nd double th e filter order. filtfilt minimizes sta rt-up a nd endingtra nsients by ma tching init ial conditions, and w orks for both real a nd complexinputs.

Note tha t filtfilt should not be used w ith differentiat or a nd H ilbert FIRfilters, since th e operat ion of these filters depends h eavily on th eir phaseresponse.

Algorithm filtfilt is an M-file tha t uses th e filter function. In a ddit ion t o theforwa rd-reverse fil tering, it a t t empts t o minimize sta rtup t ra nsients bya djusting init ia l conditions to mat ch the DC component of the signa l a nd byprepending severa l filter length s of a flipped, reflected copy of th e input signa l.

See Also fftfilt , filter , filter2

References [1] Oppenheim, A.V., a nd R.W. Scha fer, D i scr ete-Ti m e Si gnal Pr ocessi ng ,P rent ice-H a ll, 1989, pp. 311-312.

[2] Mitra , S .K., Di gital Signa l Pr ocessin g , 2nd ed., McGr a w -H ill, 2001, Sections4.4.2 a nd 8.2.5.

[3] G usta fsson, F. , “Determining th e init ial st a tes in forwa rd-backwa rdfiltering,” I EE E T r ansacti ons on Si gnal Pr ocessin g , April 1996, Volume 44,Is sue 4, pp. 988--992,

filtic

7filticPurpose Find init ial condit ions for a tr a nsposed direct form II filter implement a tion

Page 467: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 467/798

7-184

Syntax z = filtic(b,a,y,x)z = filtic(b,a,y)

Description z = filtic(b,a,y,x) finds th e initia l conditions, z , for t he dela ys in thetr ansposed d ir ect form I I fi lter implementa tion given pa st outputs y a ndinputs x . The vect ors b a nd a represent t he numerat or a nd denomina torcoefficients, respectively, of t he filter ’s t ra nsfer function.

The vect ors x a nd y cont a in th e most recent input or output first , an d oldestinput or output la st .

where n is length(b)-1 (th e numera tor order) a nd m is length(a)-1 (thedenomina tor order). If length(x) is less tha n n , filtic pads i t w ith zeros to

length n ; if length(y) is less tha n m, filtic pads i t with zeros to length m.Element s of x beyond x(n-1) a nd element s of y beyond y(m-1) a re unnecessaryso filtic ignores th em.

Output z is a column vector of length equa l to th e larger of n a nd m . z describesthe sta te of the delays given past inputs x and pas t outputs y .

z = filtic(b,a,y) assumes tha t t he input x is 0 in t he past .

The tr a nsposed direct form II s tr ucture is

where n -1 is the filt er order.

filtic works for both rea l an d complex inputs.

x x 1–( ) x 2–( ) x 3–( ) … x n –( ) …, , , , , =

y y 1–( ) y 2–( ) y 3–( ) … y m –( ) …, , , , , =

Σ Σ Σ z-1 z-1

x(m)

y(m)

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

– a (3 ) – a (2 )

z1 ( m ) z2 ( m )Σ z -1

b ( n )

–a ( n )

zn - 1 ( m )

...

...

...

filtic

Algorithm filtic performs a reverse difference equation to obtain the delay states z .

Page 468: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 468/798

7-185

Diagnostics If an y of the input a rguments y , x , b , or a is not a vector (tha t is , if anyargument i s a scala r or ar ra y), filtic gives the following error messa ge.

Requires vector inputs.

See Also filter , filtfilt

References [1] Oppenheim, A.V., a nd R.W. Scha fer, D i scr ete-Ti m e Si gnal Pr ocessi ng ,

P rent ice-H a ll, 1989, pp. 296, 301-302.

fir1

7fir1Purpose Design a w indow-bas ed finite impulse response filter

S b fi 1( W )

Page 469: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 469/798

7-186

Syntax b = fir1(n,Wn)b = fir1(n,Wn,' ftype ')b = fir1(n,Wn,window)b = fir1(n,Wn,' ftype ',window)b = fir1(...,' normalization ')

Description fir1 implements the classical method of windowed linear-phase FIR digital

fi lter design [1]. I t designs fi l ters in sta nda rd lowpass, highpa ss, bandpa ss, an dbandst op configurat ions. B y default t he fil ter is norma lized so tha t t hema gnitu de response of the filter at th e center frequency of the pas sba nd is0 d B .

Note U se fir2 for w indowed fi l ters w ith a rbitra ry frequency response.

b = fir1(n,Wn) retur ns row vector b conta ining the n+1 coefficient s of a norder n lowpass FIR filter. This is a Hamming-window based, linear-phasefilter wit h norma lized cutoff frequency Wn . The out put filter coefficient s, b , a reordered in descending powers of z .

Wn is a n umber betw een 0 a nd 1, where 1 corresponds t o the Nyquist frequency.

I f Wn is a tw o-element vector, Wn = [w1 w2] , fir1 re turns a bandpass f i lter wi thpassband w1 < ω< w2.

I f Wn is a mult i-element vector, Wn = [w1 w2 w3 w4 w5 ... wn] , fir1 re turnsa n order n multiband fi lter with ba nds 0 < ω< w1, w1 < ω< w2, ..., wn < ω< 1 .

B y default , the fi lter is sca led so tha t t he center of the first passban d ha s ama gnitude of exactly 1 a fter windowing.

B z ( ) b 1( ) b 2( ) z 1– L b n 1+( ) z n –+ + +=

fir1

b = fir1(n,Wn,' ftype ') specifies a filter ty pe, w here ' ftype ' is :

'high' for a h ighpa ss filter w ith cutoff frequencyWn

Page 470: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 470/798

7-187

'high' for a h ighpa ss filter w ith cutoff frequency Wn .• 'stop' for a ban dst op filter, if Wn = [w1 w2] . The stopban d frequency ra nge

is specified by t his int erva l.• 'DC-1' to make the first ba nd of a mu ltiband fi l ter a passba nd.• 'DC-0' to make the first band of a multiba nd fi lter a stopban d.

fir1 a lwa ys uses an even fi l ter order for th e highpa ss an d ban dstopconfigura tions. This is beca use for odd orders, t he frequency response a t th eNyquist frequency is 0, which is ina ppropriat e for highpass a nd ban dstopfilters. If y ou specify a n odd-va lued n , fir1 increments i t by 1.

b = fir1(n,Wn,window) uses t he w indow specified in column vector window for th e design. The vector window must be n+1 element s long. If n o window isspecified, fir1 uses a H am ming window (see hamming ) of lengt h n+1 .

b = fir1(n,Wn,' ftype ',window) a ccepts both ' ftype ' a nd window

parameters .

b = fir1(...,' normalization ') specifies w heth er or not t he filterma gnitu de is norma lized. The string ' normalization ' can be:

• 'scale' (defau lt): Norma lize th e filter so tha t t he ma gnitu de response of thefi lter a t t he center frequency of the passba nd is 0 dB .

• 'noscale' : Do not n orma lize th e filter.

The group delay of the FI R filter designed by fir1 is n/2 .

Algorithm fir1 uses th e wind ow meth od of FIR filter design [1]. If w (n ) denotes a w indow,wh ere 1 ≤ n ≤ N , a nd t he impulse response of th e ideal filter is h (n ), w hereh (n ) is the inverse Fourier tra nsform of th e idea l frequency response, th en th ew indowed digita l filter coefficients a re given by

b n ( ) w n ( ) h n ( ) 1 n N ≤ ≤,=

fir1

Examples Exa mple 1Design a 48th-order FI R ba ndpass fi lter w ith pa ssband 0.35 ≤ ω ≤0.65.

Page 471: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 471/798

7-188

b = fir1(48,[0.35 0.65]);freqz(b,1,512)

Exa mple 2The chirp.mat fi le conta ins a signal, y , tha t h a s most of i ts power a bove fs/4 ,or half th e Nyquist frequ ency. Design a 34th -order FIR highpa ss filter toattenuate the components of the signal below fs/4 . Use a cutoff frequencyof 0.48 a nd a Chebyshev window w ith 30 dB of r ipple.

load chirp % Load y and fs.b = fir1(34,0.48,'high',chebwin(35,30));freqz(b,1,512)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−2500

−2000

−1500

−1000

−500

0

Normalized Frequency ( ×πrad/sample)

P h a s e

( d e g r e e s )

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−100

−80

−60

−40

−20

0

20

Normalized Frequency ( ×πrad/sample)

M a g n

i t u d e

( d B )

fir1

−20

0

20

( d B )

Page 472: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 472/798

7-189

See Also cremez , filter , fir2 , fircls , fircls1 , firls , freqz , kaiserord , remez ,window

References [1] Pr ogram s for Di gital Signal Processin g, IE E E P ress, New York, 1979.Algorith m 5.2.

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−2000

−1500

−1000

−500

0

500

Normalized Frequency ( ×πrad/sample)

P h a s e

( d e g r e e s

)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−120

−100

−80

−60

−40

Normalized Frequency ( ×πrad/sample)

M a g n

i t u d e(

fir2

7fir2Purpose Design a frequency sa mpling-ba sed finite impulse response filter

Syntax b = fir2(n,f,m)

Page 473: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 473/798

7-190

Syntax ( , , )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)

Descriptionfir2 designs frequency sa mpling-based digita l FIR fi lters w ith a rbitra ri lysha ped frequency response.

Note U se fir1 for w indows-based sta nda rd lowpass, bandpa ss, highpass,a nd ba ndstop configurat ions.

b = fir2(n,f,m) retur ns row vector b conta ining the n+1 coefficient s of a norder n FI R filter. The frequency-ma gnit ude chara cteristics of this filter ma tchth ose given by vectors f a nd m:

• f is a vector of frequency points in t he ra nge from 0 to 1, where 1 correspondsto th e Nyquist frequency. The first point of f must be 0 a nd the last point 1 .The frequency point s must be in increasing order.

• m is a vector conta ining the desired ma gnitude response a t the points

specified in f .• f a nd mmust be the sam e length.• Duplicat e frequency point s a re a llow ed, corresponding t o steps in th e

frequency response.

U se plot(f,m) to view t he filter sha pe.

The outpu t filt er coefficient s, b , a re ordered in descending pow ers of z .

fir2 a lwa ys uses a n even fi lter order for configurat ions wit h a pa ssband a t t heNyqu ist fr equency. This is because for odd orders, t he frequency response a t

b z ( ) b 1( ) b 2( ) z 1– L b n 1+( ) z n –+ + +=

fir2

th e Nyquist frequ ency is necessar ily 0. If you specify an odd-va lued n , fir2 increments i t by 1.

b f ( f d ) h i d ifi d i h l

Page 474: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 474/798

7-191

b = fir2(n,f,m,window) uses th e wind ow specified in t he column vectorwindow . The vector window must be n+1 elements long. I f no w indow is specified,fir2 uses a H a mming window (see hamming ) of lengt h n+1 .

b = fir2(n,f,m,npt) or

b = fir2(n,f,m,npt,window) specifies th e number of point s, npt , for t he grid

onto which fir2 interpolat es the frequency response, with out or wit h a window specification.

b = fir2(n,f,m,npt,lap) a nd

b = fir2(n,f,m,npt,lap,window) specify the size of the region, lap , t ha tfir2 inserts a round duplica te frequency points, w ith or w ithout a window specification.

See the “Algorithm” section for more on npt a nd lap .

Examples Design a 30th -order low pass filter a nd overplot th e desired frequency responsewit h t he a ctual frequency response.

f = [0 0.6 0.6 1]; m = [1 1 0 0];b = fir2(30,f,m);[h,w] = freqz(b,1,128);plot(f,m,w/pi,abs(h))legend('Ideal','fir2 Designed')title('Comparison of Frequency Response Magnitudes')

fir2

1.2

1.4Comparison of Frequency Response Magnitudes

Idealfir2 Designed

Page 475: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 475/798

7-192

Algorithm The desired frequency response is interpolat ed onto a dense, evenly spa ced gr idof lengt h npt . npt is 512 by defau lt. I f tw o successive values of f are the sa me,a region of lap points is set u p ar ound th is frequency to provide a smooth butsteep tra nsit ion in t he requested frequency r esponse. By default , lap is 25. Thefilter coefficients a re obta ined by applying an in verse fa st Fourier tr a nsform tothe grid and mult iplying by a w indow; by defau lt , this is a Ha mming window.

See Also butter , cheby1 , cheby2 , ellip , fir1 , maxflat , remez , yulewalk

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

0.2

0.4

0.6

0.8

1

1.2

fircls

7firclsPurpose Constra ined least squa re FIR fi l ter design for multiba nd fi l ters

Syntax b = fircls(n,f,amp,up,lo)

Page 476: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 476/798

7-193

fircls(n,f,amp,up,lo,' design_flag ')

Description b = fircls(n,f,amp,up,lo) genera tes a length n+1 l inea r pha se FIR fi l ter b .The frequency-ma gnit ude char a cteristics of this filter ma tch t hose given byvectors f a nd amp:

• f is a vector of tra nsition frequencies in t he ra nge from 0 to 1, where 1

corresponds to t he Nyq uist frequency. The first point of f must be 0 and thelast point 1 . The frequency point s must be in increasing order.

• amp is a vector describing th e piecewise consta nt desired am plitude of thefrequ ency response. The lengt h of amp is equa l to the number of bands in t heresponse an d should be equa l to length(f)-1 .

• up a nd lo ar e vectors with the sa me length a s amp. They define th e upper a ndlow er bounds for t he frequency response in ea ch ban d.

fircls a lwa ys uses an even fi lter order for configurat ions wit h a passba nd a tth e Nyquist frequency. This is because for odd orders, t he frequency responsea t the Nyq uist frequency is necessar i ly 0. If you specify an odd-valued n ,fircls increments i t by 1.

fircls(n,f,amp,up,lo,' design_flag ') ena bles you t o monitor t he filterdesign, w here ' design_flag ' can be:

'trace' , for a textua l display of the design error a t ea ch i tera tion step.• 'plots' , for a collection of plots showing th e filter ’s full-ba nd ma gnit ude

response a nd a zoomed view of the ma gnit ude response in ea ch sub-ban d. Allplots a re upda ted a t each i tera tion step.

• 'both' , for both t he textua l display a nd plots.

fircls

Examples Design a n order 50 band pass fi l ter.

n = 50;f = [0 0.4 0.8 1];

Page 477: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 477/798

7-194

amp = [0 1 0];up = [0.02 1.02 0.01];lo = [-0.02 0.98 -0.01];b = fircls(n,f,amp,up,lo,'plots'); % Plot magnitude response

Note Norma lly, the lower va lue in the st opba nd w ill be specified as nega tive.By se t t ing lo equal to 0 in the stopbands, a nonnegative frequency responsea mplitude can be obta ined. Such filters can be spectr a lly factored to obta inminimum phase filters.

Algorithm The algorithm is a m ultiple excha nge algorithm tha t uses La gra ngemult ipliers a nd K uhn -Tucker condit ions on ea ch itera tion.

See Also fircls1 , firls , remez

0 0.2 0.4 0.6 0.8 1 1.2 1.4-2

0

2

0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4

-0.02

0

0.02

B a n

d # 1

0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8

0.98

1

1.02

B a n d

# 2

0.8 0.85 0.9 0.95 1

-0.01

0

0.01

B a n

d # 3

Frequency

fircls

References [1] Selesnick, I.W., M. Lang, and C.S. Burrus, “Constrained Least SquareDesign of FIR Filters without Specified Transition Bands,” Pr oceedi ngs of t he

I E EE I nt . Conf . Acoust., Speech, Si gnal Pr ocessin g , Vol. 2 (Ma y 1995),pp 1260-1263

Page 478: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 478/798

7-195

pp. 1260-1263.

[2] Selesnick, I.W., M. Lang, and C.S. Burrus. “Constrained Least SquareDesign of FIR F ilters wit hout Specified Tra nsition Ba nds.” IE EE Tr ansact ions on Sign al Pr ocessi ng , Vol. 44, No. 8 (Augus t 1996).

fircls1

7fircls1Purpose Constra ined least sq ua re fil ter design for lowpa ss an d highpass l inear pha seFIR fi lters

Syntax b = fircls1(n,wo,dp,ds)

Page 479: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 479/798

7-196

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 tes a lowpass F IR fi l ter b , where n+1 i s thefilter length , wo is the normalized cutoff frequency in th e range between 0 a nd 1(w here 1 corresponds t o the Nyq uist frequency), dp is the ma ximum passba nddeviat ion from 1 (pas sba nd r ipple), a nd ds is the ma ximum stopband deviat ionfrom 0 (st opban d ripple).

b = fircls1(n,wo,dp,ds,' high ') genera tes a highpass FIR fi l ter b. fircls1 a lwa ys uses a n even filter order for th e highpass configurat ion. This is becausefor odd orders, th e frequency response a t t he Nyquist frequency isnecessa rily 0. If you specify an odd-va lued n , fircls1 increments i t by 1.

b = fircls1(n,wo,dp,ds,wt) a nd

b = fircls1(n,wo,dp,ds,wt,' high ') specifies a frequency wt a bove which(for wt > wo) or below which (for wt < wo) the fi l ter is gua ra nteed to meet t hegiven ba nd cri terion. This w ill help you design a fi lter t ha t meets a passba ndor stopband edge requirement. There a re four cases:

• Lowpass: - 0 < wt < wo < 1 : the a mplitude of the fi lter is w ithin dp of 1 over the

frequency ra nge 0 < ω < wt .- 0 < wo < wt < 1 : the a mplitude of the fi lter is w ithin ds of 0 over the

frequency ra nge wt < ω < 1 .

fircls1

• Highpass :- 0 < wt < wo < 1 : the a mplitude of the fi lter is w ithin ds of 0 over the

frequency ran ge 0 < ω < wt .0 < < t < 1 : the a mplitude of the filter is w ithin d of 1 over the

Page 480: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 480/798

7-197

- 0 < wo < wt < 1 : the a mplitude of the fi lter is w ithin dp of 1 over thefrequency ran ge wt < ω < 1 .

b = fircls1(n,wo,dp,ds,wp,ws,k) genera tes a lowpa ss FIR filter b wi th aweighted function, where n+1 is the filter length, wo is the norma lized cut offfrequency, dp is the ma ximum passba nd d evia tion from 1 (passba nd r ipple), a ndds is the ma ximum st opba nd devia tion from 0 (stopban d ripple). wp is thepassba nd edge of the L2 weight function a nd ws is the st opband edge of the L 2weight function, w here wp < wo < ws . k is t he ra tio (pa ssba nd L2 error)/(stopban dL2 error)

b = fircls1(n,wo,dp,ds,wp,ws,k,' high ') genera tes a h ighpass FIR fi l ter b wit h a weighted function, wh ere ws < wo < wp.

b = fircls1(n,wo,dp,ds,...,' design_flag ') ena bles you t o monitor th efilter design, where ' design_flag ' can be:

• 'trace' , for a t extua l displa y of th e design t a ble used in the design• 'plots' , for plots of th e filter ’s mag nitud e, group delay, a nd zeros a nd poles• 'both' , for both the t extua l display a nd plots

Note In t he design of very na rrow ban d fi lters wit h sma ll dp a nd ds , therema y not exist a f i lter of the given length tha t meets the specifica tions.

k

A ω( ) D ω( )– 2 ωd 0

w p

∫ A ω( ) D ω( )– 2 ωd

w

π

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

fircls1

Examples Design an order 55 lowpa ss fi lter w ith a cutoff frequency at 0.3.

n = 55; wo = 0.3;dp = 0.02; ds = 0.008;b = fircls1(n wo dp ds 'plots'); % Plot magnitude response

Page 481: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 481/798

7-198

b = fircls1(n,wo,dp,ds, plots ); % Plot magnitude response

Algorithm The algorithm is a m ultiple excha nge algorithm tha t uses La gra ngemult ipliers a nd K uhn -Tucker condit ions on ea ch itera tion.

See Also fircls , firls , remez

References [1] Selesnick, I .W., M. Lan g, a nd C .S. B urrus, “Constra ined Least Squa reDesign of FIR Filters without Specified Transition Bands,” Pr oceed i n gs of th e I EE E I nt . Conf . Acoust., Speech, Signa l Pr ocessing , Vol. 2 (Ma y 1995),pp. 1260-1263.

[2] Selesnick, I .W., M. Lan g, a nd C .S. B urrus, “Constra ined Least Squa reDesign of FI R Filters wit hout Specified Tra nsition B a nds,” IE EE Tr ansact ions on Sign al Pr ocessing , Vol. 44, No. 8 (August 1996).

0 0.2 0.4 0.6 0.8 1

0

0.5

1

0 0.05 0.1 0.15 0.2 0.25-0.04

-0.02

0

0.02

0.04

0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-0.01

0

0.01

firls

7firlsPurpose Least squa re l inear-phase FI R fi l ter design

Syntax b = firls(n,f,a)b = firls(n,f,a,w)

Page 482: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 482/798

7-199

b = firls(n,f,a,' ftype ')b = firls(n,f,a,w,' ftype ')

Description firls designs a l inea r-phase FI R fi l ter tha t minimizes the w eighted,integrat ed squa red error between a n ideal piecewise linear function a nd t hema gnitu de response of the filter over a set of desired frequency band s.

b = firls(n,f,a) retur ns row vector b containing th e n+1 coefficient s of th eorder n FIR filter whose frequency-amplitude characteristics approximatelyma tch t hose given by vectors f a nd a . The output filter coefficients, or “taps,”in b obey the symmetry relation.

These a re ty pe I ( n odd) a nd t ype II ( n even) linea r-pha se filters. Vectors f a nd a specify th e frequency-a mplitude cha ra cteristics of th e filter:

• f is a vector of pairs of frequency point s, specified in t he ra nge betw een 0a nd 1, w here 1 corresponds to the Nyq uist frequ ency. The frequencies mustbe in increasing order. Duplica te frequency points a re allowed a nd, in fact,can be used to design a fi lter exactly the sa me as those returned by t he fir1 a nd fir2 functions wit h a rectan gular ( rectwin ) win dow.

• a is a vector conta ining th e desired a mplitude a t t he points specified in f .

The desired am plitude function a t fr equencies betw een pairs of points(f (k ), f (k + 1)) for k odd is the line segment connecting t he points ( f (k ), a (k ))a n d (f (k + 1), a (k + 1)).

The desired am plitude function a t fr equencies betw een pairs of points(f (k ), f (k + 1)) for k even is unspecified. These a re t ra nsition or “don’t care”regions.

f a nd a a re the sa me length . This length must be an even num ber.firls a lwa ys uses an even fi lter order for configurat ions w ith a passba nd a tth e Nyquist frequency. This is because for odd orders, t he frequency response

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

firls

a t t he Nyquist frequ ency is necessar ily 0. If you specify an odd-va lued n , firls increments i t by 1.

The figure below illust ra tes th e rela tionship betw een the f a nd a vectors indefining a d esired amplitu de response.

Page 483: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 483/798

7-200

g p p

b = firls(n,f,a,w) uses th e weights in vector w to weight t he fit in ea chfrequency ba nd. The length of w is ha lf the length of f a nd a , so there is exactlyone weight per ba nd.

b = firls(n,f,a,' ftype ') a nd

b = firls(n,f,a,w,' ftype ') specify a filter t ype, where ' ftype ' is :

• 'hilbert' for linear -pha se filters w ith odd symmet ry (ty pe III a nd t ype IV).The out put coefficient s in b obey th e relat ion b (k ) = -b (n + 2-k ),k = 1, ... , n + 1. This cla ss of fi l ters includes the Hilbert tra nsformer, whichha s a desired a mplitude of 1 a cross th e entire ba nd.

• 'differentiator' for t ype III a nd t ype IV fi l ters, using a specia l weightingtechnique. For nonzero a mplitude ba nds, the int egrat ed squa red error ha s aw eight of (1/f )2 so tha t t he error a t low frequencies is much smaller th a n a thigh frequencies. For FIR differentia tors, which ha ve an a mplitudechar a cteristic proport iona l to frequency, the filters minimize th e rela tiveintegrat ed squa red error (the int egral of the squa re of the ra tio of the errorto th e desired a mplitude).

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)

firls

Examples Exa mple 1Design an order 255 lowpa ss fi lter w ith t ra nsit ion ba nd.

b = firls(255,[0 0.25 0.3 1],[1 1 0 0]);

Page 484: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 484/798

7-201

Exa mple 2Design a 31 coefficient different iat or.

b = firls(30,[0 0.9],[0 0.9],'differentiator');

Exa mple 3Design a 24th-order ant i-symmet ric filter wit h piecew ise linear pa ssba nds a ndplot t he desired a nd a ctua 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 on

end[H,f] = freqz(b,1,512,2);plot(f,abs(H)), grid on, hold offlegend('Ideal','firls Design')

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

1Idealfirls Design

firls

Algorithm Reference [1] describes the theoretical approach behind firls . The functionsolves a syst em of linea r equa tions involving a n inner product ma tr ix of size

roughly n/2 using MATLAB’s \ operator.This function designs ty pe I, II, II I, a nd I V linear -pha se filters. Type I a nd I I

Page 485: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 485/798

7-202

a re the defaults for n even a nd odd respectively, wh ile the 'hilbert' a nd'differentiator' flags produce ty pe III ( n even) and IV ( n odd) filters. Thevarious f il ter types ha ve different symmetries and constraint s on th eirfrequ ency r esponses (see [2] for det a ils).

Diagnostics An a ppropriat e diagnostic messa ge is displayed w hen incorrect ar guments 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 serious wa rning m essage is

Warning: Matrix is close to singular or badly scaled.

This tends t o happen w hen th e product of the f i l ter length an d t ra nsit ion w idthgrows la rge. In t his case, th e filter coefficients b might not represent t hedesired filter. You can check th e filter by looking a t its fr equency response.

See Also fir1 , fir2 , firrcos , remez

Linear PhaseFilter Type

FilterOrder

Symmetry of Coefficients Response H(f),f = 0

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

Type I E ven even: No rest r ict ion No rest r ict ion

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

Type I I I E ven odd: H (0) = 0 H (1) = 0

Type IV Odd H (0) = 0 No rest rict ion

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

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

firls

References [1] P a rks, T.W., an d C .S. B urru s, Di gi ta l F i l ter D esign , J ohn Wiley & Sons ,1987, pp. 54-83.

[2] Oppenheim, A.V., a nd R.W. Scha fer, D i scr ete-Ti m e Si gnal Pr ocessi ng ,P rent ice-H a ll, 1989, pp. 256-266.

Page 486: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 486/798

7-203

firrcos

7firrcosPurpose Ra ised cosine FI R filter design

Syntax b = firrcos(n,F0,df,fs)b = firrcos(n,F0,df,fs,' bandwidth ’)b = firrcos(n F0 df)

Page 487: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 487/798

7-204

b firrcos(n,F0,df)b = firrcos(n,F0,r,fs,' rolloff ')b = firrcos(...,' type ')b = firrcos(...,' type ',delay)b = firrcos(...,' type ',delay,window)[b,a] = firrcos(...)

Description b = firrcos(n,F0,df,fs) or, equivalently,

b = firrcos(n,F0,df,fs,' bandwidth ') returns a n order n lowpasslinear -phase FI R fi l ter wit h a ra ised cosine tra nsit ion ba nd. The fi lter ha scutoff frequency F0 , t ra ns i t ion ban dwidth df , a nd sa mpling frequency fs , a ll inhertz. df must be sma ll enough so tha t F0 ± df/2 is between 0 a nd fs/2 . Thecoefficient s in b are normal ized so that the nominal pa ssband gain is a lwaysequal to 1. Specify fs a s the empty vector [] to use the defa ult va lue fs = 2 .

b = firrcos(n,F0,df) uses a default sa mpling frequency of fs = 2 .

b = firrcos(n,F0,r,fs,' rolloff ') interprets the third a rgument, r , as therolloff factor instea d of the tra nsit ion ba ndw idth, df . r must be in the ra nge[0,1] .

b = firrcos(...,' type ') designs either a norma l ra ised cosine filter or asqua re root r a ised cosine filter a ccording to how you specify of th e string' type ' . S pecify ' type ' a s:

• 'normal' , for a regula r ra ised cosine filter. This is th e default , a nd is a lso ineffect w hen th e ' type ' a rgument is left empty, [] .

• 'sqrt' , for a squa re root r a ised cosine filter.

b = firrcos(...,' type ',delay) specifies a n int eger delay in th e ra nge[0,n+1] . The default is n/2 for even n a nd (n+1)/2 for odd n .

b = firrcos(...,' type ',delay,window) a pplies a length n+ 1 window t o thedesigned filter t o reduce th e ripple in t he frequency response. window must be

firrcos

a length n+ 1 column vector. If no w indow is specified, a r ecta ngula r ( rectwin )window is used. Care must be exercised wh en using a w indow w ith a dela y

other tha n t he defaul t .

[b,a] = firrcos(...) always re turns a = 1 .

Page 488: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 488/798

7-205

Examples Design a n order 20 raised cosine FI R filter w ith cutoff frequency 0.25 of th eNyquist frequency a nd a tra nsit ion ban dwidt h of 0.25.

h = firrcos(20,0.25,0.25);freqz(h,1)

See Also fir1 , fir2 , firls , remez

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−700

−600

−500

−400

−300

−200

−100

0

Normalized Frequency ( ×πrad/sample)

P h a s e

( d e g r e e s

)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−120

−100

−80

−60

−40

−20

0

20

Normalized Frequency ( ×πrad/sample)

M a g n

i t u d e

( d B )

freqs

7freqsPurpose Frequ ency response of ana log filters

Syntax h = freqs(b,a,w)[h,w] = freqs(b,a)[h,w] = freqs(b,a,l)

Page 489: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 489/798

7-206

q ( )freqs(b,a)

Description freqs retur ns t he complex frequency response H ( j ω) (La place tra nsform) of a na na log fi l ter

given the num era tor a nd denomina tor coefficient s in vectors b a nd a .

h = freqs(b,a,w) retur ns t he complex frequency response of the a na log filterspecified by coefficient vectors b a nd a . freqs evalua tes th e frequency responsea long t he ima gina ry a xis in the complex plan e at th e frequencies specified in

rea l vector w.[h,w] = freqs(b,a) a ut omat ica lly picks a set of 200 frequency points w onw hich to comput e the frequ ency response h .

[h,w] = freqs(b,a,l) picks l frequencies on w hich to comput e the frequ encyresponse h .

freqs with no output a rguments plots t he magnit ude and pha se responseversus frequency in the current figure window.

freqs w orks only for real input sy stems a nd positive frequencies.

Examples Find a nd gra ph th e frequency response of th e tra nsfer function given by

a = [1 0.4 1];b = [0.2 0.3 1];w = logspace(-1,1);freqs(b,a,w)

H s ( ) B s ( )A s ( )----------- b 1( ) s n b 2( ) s n 1– L b n 1+( )+ + +

a 1( ) s m a 2( ) s m 1– L a m 1+( )+ + +-------------------------------------------------------------------------------------------= =

H s ( ) 0.2 s 2 0.3 s 1+ +s 2 0.4 s 1+ +

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

freqs

100

101

g n

i t u d e

Page 490: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 490/798

7-207

You can also creat e the plot wit h

h = freqs(b,a,w);mag = abs(h);phase = angle(h);subplot(2,1,1), loglog(w,mag)subplot(2,1,2), semilogx(w,phase)

To convert to hertz, degrees, and decibels, use

f = w/(2*pi);mag = 20*log10(mag);phase = phase*180/pi;

Algorithm freqs evaluat es the polynomia ls a t each frequency point, t hen divides t henum era tor response by the denominat or response.

s = i*w;h = polyval(b,s)./polyval(a,s);

See Also abs , angle , freqz , invfreqs , logspace , polyval

10-1

100

101

10-1

Frequency

M a g

10-1

100

101

-150

-100

-50

0

Frequency

P h a s e

( d e g r e e s

)

freqspace

7freqspacePurpose Frequ ency spacing for frequency response

Syntax f = freqspace(n)f = freqspace(n,' whole ')[f1,f2] = freqspace(n)

Page 491: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 491/798

7-208

[f1,f2] = freqspace([m n])[x1,y1] = freqspace(n,' meshgrid ')[x1,y1] = freqspace([m n],' meshgrid ')

Description freqspace retur ns t he implied frequency ra nge for equa lly spaced frequencyresponses. This is useful w hen crea ting frequency vectors for use w ith freqz .

f = freqspace(n) retur ns t he frequency vector f assuming n evenly spa cedpoints a round t he unit circle. For n even or odd, f is (0:2/n:1) . For n even,freqspace re turns (n + 2)/2 points. For N odd, i t retur ns (n + 1)/2 points.

f = freqspace(n,' whole ') re turns n evenly spa ced points a round th e wholeunit circle. In t his case, f is 0:2/n:2*(n-1)/n .

[f1,f2] = freqspace(n) retur ns t he tw o-dimensional frequency vectors f1 a nd f2 for a n n-by-n ma trix. For n odd, both f1 a nd f2 a re[-1 + 1/n:2/n:1-1/n] . For n even, both f1 a nd f2 a re [-1:2/n:1-2/n] .

[f1,f2] = freqspace([m n]) retur ns t he tw o-dimensional frequency vectorsf1 a nd f2 for a n m-by-n matr ix .

[x1,y1] = freqspace(n,' meshgrid ') a nd[x1,y1] = freqspace([m n],' meshgrid ') a re equiva lent t o

[f1,f2] = freqspace(...);[x1,y1] = meshgrid(f1,f2);

See th e MATLAB documenta tion for deta ils on t he meshgrid function.

See Also freqz , invfreqz

freqz

7freqzPurpose Compute t he frequency response of digita l filters

Syntax [h,w]= freqz(b,a,l)h = freqz(b,a,w)[h,w] = freqz(b,a,l,' whole ')

f

Page 492: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 492/798

7-209

[h,w,s] = freqz(...)[h,f] = freqz(b,a,l,fs)h = freqz(b,a,f,fs)[h,f] = freqz(b,a,l,' whole ',fs)[h,f,s] = freqz(...)freqz(b,a,...)

Description [h,w] = freqz(b,a,l) retur ns t he frequency response vector h a n d t h ecorresponding frequency vector w for the digital filter whose transfer functionis determined by th e (rea l or complex) numera tor a nd denomina torpolynomials r epresent ed in t he vectors b a nd a , respectively. The v ectors h a nd w a re both of length l . The fr equen cy vector w ha s values ran ging from 0 to π ra dia ns per sa mple. When you don’t specify th e integer l , or you specify it a sth e empty vector [] , the frequency response is ca lcula ted using t he defaultva lue of 512 sa mples.

h = freqz(b,a,w) retur ns t he frequency response vector h calcula ted a t thefrequencies (in ra dia ns per sa mple) supplied by t he vector w. The vector w ca nha ve any length .

[h,w] = freqz(b,a,l,' whole ') uses n sam ple points a round t he entire unitcircle to calcula t e the freq uency response. The frequ ency vector w has length la nd ha s values ranging from 0 to 2 π ra dians per sample.

[h,w,s] = freqz(...) retur ns a str ucture of plotting informa tion to be usedwi th freqzplot .

[h,f] = freqz(b,a,l,fs) retur ns t he frequency response vector h a n d t h ecorresponding frequency vector f for the digital filter whose transfer function

is determined by t he (rea l or complex) numera tor a nd denomina torpolynomials represent ed in t he vectors b a nd a , respectively. The v ectors h a nd f a re both of length l . For this synt a x, the frequency response is ca lcula tedusing t he sa mpling frequency specified by th e sca lar fs (in hertz). The

freqz

frequency vector f is calculat ed in un its of hert z (Hz). The frequency vector f ha s values ranging from 0 t o fs/2 H z.

h = freqz(b,a,f,fs) retur ns t he frequency response vector h calculat ed a tt he frequ encies (in H z) supplied in t he vector f . The vector f ca n be a ny length.

Page 493: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 493/798

7-210

[h,f] = freqz(b,a,l,' whole ',fs) uses n points a round t he entire unit circleto ca lcula te t he frequency r esponse. The frequency vector f has length l a ndha s values ranging from 0 t o fs H z.

[h,f,units] = freqz(b,a,l,' whole ',fs) returns t he optiona l str ingargument units , specifying th e units for t he frequency vector f . The st ringreturned in units is 'Hz' , denoting hertz.

freqz(b,a,...) plots the ma gnitude an d unw ra pped pha se of the frequencyresponse of the filter. The plot is d isplayed in th e current figur e wind ow.

Remarks It is best t o choose a pow er of tw o for th e third input a rgument n , beca use freqz uses a n FF T a lgorith m t o ca lcula te t he frequency response. See the referencedescription of fft for more informa tion.

Examples P lot t he magnit ude and pha se response of an FIR fi l ter.

b = fir1(80,0.5,kaiser(81,8));freqz(b,1);

freqz

−100

−50

0

50

M a g n

i t u d e

( d B )

Page 494: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 494/798

7-211

Algorithm The frequency response [1] of a digit a l filter can be int erpreted a s t he tr a nsferfunction evaluat ed at z = e j ω. You can a lwa ys write a ra tional tra nsfer functionin t he followin g form.

freqz determines t he tr a nsfer function from the (rea l or complex) numera tora nd denomina tor polynomia ls you specify, a nd ret urn s th e complex frequencyresponse H (e j ω) of a digita l filter. The frequency response is evalua ted a tsa mple points determined by the synta x tha t you use.

freqz genera lly uses an F FT a lgorith m t o compute t he frequency responsew henever you don’t supply a vector of frequencies as a n input a rgument . Itcomputes th e frequency response as t he ra tio of the tr a nsformed numera tora nd denomina tor coefficient s, pa dded wit h zeros to the desired lengt h.

When you do supply a vector of frequencies a s a n input a rgument , th en freqz evalua tes th e polynomia ls at each frequency point us ing Horner ’s meth od ofnested polynomial evalua tion [1], dividing th e numera tor response by thedenomina tor response.

See Also abs , angle , fft , filter , freqs , freqzplot , impz , invfreqs , logspace

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−5000

−4000

−3000

−2000

−1000

0

Normalized Frequency ( ×πrad/sample)

P h a s e

( d e g r e e s )

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

Normalized Frequency ( ×πrad/sample)

H z ( ) B z ( )A z ( )----------- b 1( ) b 2( ) z 1– L b n 1+( ) z n –+ + +

a 1( ) a 2( ) z 1– L a m 1+( ) z m –+ + +----------------------------------------------------------------------------------------= =

freqz

References [1] Oppenheim, A.V., a nd R.W. S cha fer, D i scr ete-Ti m e Si gnal Pr ocessing ,P ren t ice-H a ll, 1989, pp. 203-205.

Page 495: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 495/798

7-212

freqzplot

7freqzplotPurpose Plot frequency response data

Syntax freqzplot(h,w)freqzplot(h,w,s)freqzplot(h,w,str)

Page 496: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 496/798

7-213

Description freqzplot(h,w) plots t he frequency response da ta cont a ined in h a t t h efrequ encies specified in t he vector w, where h can be either a vector or a m a trix.w must be a vector w hose length is the num ber of rows in h . The da ta in h isplott ed versus frequency w on tw o plots:

• The ma gnit ude of h is plott ed in dB .• The pha se of h is plott ed in d egrees.

The unit s for frequency on the plots a re in ra dia ns per sa mple. If h i s a mat r ix,th e frequency responses of each column of h is plott ed.

freqzplot(h,w,s) specifies a str ucture of plott ing options, s , wi th thefollowing fields:

• s.xunits —a str ing specifying t he frequency a xis units. The cont ents ofs.xunits can be one of the following:- 'rad/sample' (default)- 'Hz'- 'kHz'- 'MHz'- 'GHz'- A user-specified st rin g

• s.yunits —a str ing specifying th e vert ical a xis units. The cont ents ofs.yunits can be one of the following:- 'dB' (default)- 'linear'- 'squared'

freqzplot

• s.plot —a string specifying the type of plot to produce. The contents ofs.plot can be one of the following:-

'both' (default)- 'mag'- 'phase'

Page 497: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 497/798

7-214

Note that the s structure ca n be obta ined as a n output of freqz .

freqzplot(h,w,str) specifies a pa rt icula r st ring option from the s structure.This is a quick wa y t o select a single plotting option.

Examples nfft = 512; Fs = 44.1; % Fs is in kHz.[b1,a1] = cheby1(5,0.4,0.5);[b2,a2] = cheby1(5,0.5,0.5);[h1,f,s] = freqz(b1,a1,nfft,Fs);h2 = freqz(b2,a2,nfft,Fs);% Use the same nfft and Fs.h = [h1 h2];

U se the quick method to specify only t he s.yunits . The s.plot a nd s.xunits use the default va lues of ‘both’ and ‘rad/sample’ , respectively.

freqzplot(h,f,’squared’)

0 1 2 3 4 5 6 7−500

−400

−300

−200

−100

0

Normalized Frequency ( ×πrad/sample)

P h a s e

( d e g r e e s )

0 1 2 3 4 5 6 70

0.5

1

1.5

Normalized Frequency ( ×πrad/sample)

M a g n i t u

d e

S q u a r e

d

freqzplot

Define each of th e s str ucture unit s to cust omize th e plot.

s.plot = 'mag'; % Plot the magnitude only.

s.xunits = 'khz'; % Label the frequency units correctly.s.yunits = 'squared'; % Plot the magnitude squared.freqzplot(h,f,s); % Compare the two Chebyshev filters.

Page 498: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 498/798

7-215

See Also freqz , grpdelay , psdplot

0 5 10 15 200

0.2

0.4

0.6

0.8

1

1.2

1.4

Frequency (kHz)

M a g n

i t u d e s q u a r e

d

fvtool

7fvtoolPurpose Open th e Filter Visua lizat ion Tool

Syntax fvtool(b,a)fvtool(b 1,a 1 ,b 2 ,a 2 ,...b n,a n)

Description fvtool(b,a) opens t he Filt er Visua liza t ion Tool (FVTool) a nd comput es th e

Page 499: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 499/798

7-216

ma gnitude response of the fi lter defined w ith numerat or, b and denominator,a . U sing F VTool you ca n displa y t he pha se response, group delay, impulseresponse, st ep response, pole-zero plot, a nd coefficient s of th e filter.

fvtool(b1,a

1,b

2,a

2,...b

n,a

n) opens FVTool a nd computes th e ma gnitu de

responses of multiple filters defined wit h num era tors, b1.. .bn a nddenominators, a 1.. .a n .

Note In fdatool , selecting Full View Analysis from t he Analysis menulaunches FVTool.

fvtool

Zoom

Toggle

legend

Magnitude Phase Magnitude

and Phase

Group

Delay

Impulse

Response

Step

Response

Pole-Zero

Coefficients

Page 500: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 500/798

7-217

Note If you ha ve the Filt er Design Toolbox insta lled, you can use fvtool onqua nt ized filter objects by us ing fvtool(Hq,Hq1) .

Examples Exa mple 1Displa y th e magn itude response of an elliptic filter.

Print andpreview

Edit plot

Add text

Add arrow

Add line

Launch anewFVTool

fvtool

[b,a]=ellip(6,3,50,300/500);fvtool(b,a);

Page 501: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 501/798

7-218

Exa mple 2Displa y a nd a na lyze multiple FIR fi lters.

n = 20; % Filter orderf = [0 0.4 0.5 1]; % Frequency band edgesa = [1 1 0 0]; % Desired amplitudesb = remez(n,f,a);b2 = remez(n*2,f,a); % Double the filter orderfvtool(b,1,b2,1);

fvtool

Page 502: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 502/798

7-219

See Also fdatool , sptool

gauspuls

7gauspulsPurpose G enera te a G au ssian-modula ted sinusoidal pulse

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)

Page 503: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 503/798

7-220

tc gauspuls( cutoff ,fc,bw,bwr,tpe)

Description gauspuls genera tes G a ussian-modula ted sinusoidal pulses.

yi = gauspuls(t,fc,bw) returns a unity -a mplitude Ga ussian RF pulse a t thetimes indica ted in arra y t , with a center frequency fc in her tz a nd a f ract ionalbandwidth bw, wh ich must be grea ter t ha n 0. The defa ult va lue for fc is1000 Hz a nd for bw is 0.5.

yi = gauspuls(t,fc,bw,bwr) returns a un ity-a mplitude Ga ussian RF pulsewith a f ract ional bandw idth of bw a s measured a t a level of bwr dB wit h respectto th e norma lized signa l pea k. The fra ctiona l ban dw idth r eference level bwr

must be less tha n 0, beca use it indicat es a reference level less th a n th e peak(unity) envelope amplitude. The default value for bwr i s -6 dB.

[yi,yq] = gauspuls(...) returns both t he in-phase a nd qua dra ture pulses.

[yi,yq,ye] = gauspuls(...) retur ns t he RF signa l envelope.

tc = gauspuls(' cutoff ',fc,bw,bwr,tpe) returns t he cutoff t ime tc (greatertha n or equal t o 0) a t wh ich t he tra il ing pulse envelope falls below tpe d B w i t hrespect to the peak envelope amplitude. The trailing pulse envelope level tpemust be less tha n 0, because i t indica tes a reference level less tha n t he pea k(unity) envelope amplitude. The default value for tpe is -60 dB .

Remarks Default va lues ar e substi tut ed for empty or omitt ed tra il ing input a rguments.

Page 504: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 504/798

gausswin

7gausswinPurpose Compute a G auss ian w indow

Syntaxw = gausswin(n)w = gausswin(n, α)

Description w = gausswin(n) re turns an n-point G a ussia n w indow in th e column vector w.n is a positive integer. The coefficients of a G a ussia n w indow a re comput ed

Page 505: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 505/798

7-222

from the follow ing equa tion.

where an d .

w = gausswin(n, α) re turns an n-point G au ssian w indow w here α is thereciproca l of the st a nda rd devia tion. The widt h of the wind ow is inversely

related t o the value of α; a la rger value of α produces a na rrower window. If α is omitted, it defa ults t o 2.5.

Note If t he win dow a ppea rs t o be clipped, increase th e number of point s ( n)used for gausswin(n) .

Example N=64;w = gausswin(N);plot(w); axis([1 N 0 1]);title('64-point Gaussian window');

w k 1+ e

12---–

α

k N 2----–

N 2 ⁄ --------------

2

=

0 k N ≤ ≤ α 2≥

gausswin

0.6

0.7

0.8

0.9

164−point Gaussian window

Page 506: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 506/798

7-223

Note The sha pe of this w indow is similar in th e frequency doma in beca usethe Fourier tra nsform of a G a ussian is also a G a ussian.

See Also barthannwin , bartlett , blackman , blackmanharris , bohmanwin , chebwin ,hann , hamming , kaiser , nuttallwin , rectwin , triang , tukeywin , window

References [1] ha rris, f.j. “On th e Use of Windows for H a rmonic Ana lysis w ith th e DiscreteFourier Tra nsform.” Pr oceedi ngs of th e I EE E. Vol. 66, No. 1 (J a nua ry 1978).

[2] Roberts , Richa rd A., an d C .T. Mullis. Di gital Si gnal Pr ocessin g . Reading,MA: Add ison -Wesley , 1987, pp. 135-136.

10 20 30 40 50 600

0.1

0.2

0.3

0.4

0.5

gmonopuls

7gmonopulsPurpose G enerat e a G auss ian monopulse

Syntax y = gmonopuls(t,fc)tc = gmonopuls(' cutoff ',fc)

Description y = gmonopuls(t,fc) returns sa mples of the unity-a mplitude G a ussianmonopulse wit h center frequ ency fc (in hertz) a t t he t imes indica ted in a rra y t .B d f l f 000 H

Page 507: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 507/798

7-224

By defaul t , fc = 1000 H z.

tc = gmonopuls(' cutoff ',fc) returns th e t ime dura tion between thema ximum a nd minimum a mplitudes of the pulse.

Remarks Default va lues ar e substi tut ed for empty or omitt ed tra il ing input a rguments.

Examples Exa mple 1P lot a 2 G Hz G aussian monopulse sampled a t a ra t e of 100 G Hz.

fc = 2E9; fs=100E9;tc = gmonopuls('cutoff',fc);t = -2*tc : 1/fs : 2*tc;y = gmonopuls(t,fc); plot(t,y)

−4 −3 −2 −1 0 1 2 3 4

x 10−10

−1

−0.8

−0.6

−0.4

−0.2

0

0.2

0.4

0.6

0.8

1

gmonopuls

Exa mple 2Construct a pulse tra in from t he monopulse of Exa mple 1 using a spacing of

7.5 ns .fc = 2E9; fs=100E9; % center freq, sample freqD = [2.5 10 17.5]' * 1e-9; % pulse delay timestc = gmonopuls('cutoff',fc); % width of each pulset = 0 : 1/fs : 150*tc; % signal evaluation time

Page 508: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 508/798

7-225

yp = pulstran(t,D,@gmonopuls,fc);plot(t,yp)

See Also chirp , gauspuls , pulstran , rectpuls , tripuls

0 0.5 1 1.5 2 2.5

x 10−8

−1

−0.8

−0.6

−0.4

−0.2

0

0.2

0.4

0.6

0.8

1

goertzel

7goertzelPurpose Compute t he DF T using t he second-order G oert zel algorithm

Syntax y = goertzel(x,i)y = goertzel(x,i,dim)

Description goertzel comput es th e discrete Fourier t ra nsform (DF T) of specific indices ina vector or mat rix.

Page 509: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 509/798

7-226

y = goertzel(x,i) retur ns t he DF T of vector x a t t he indices in vector i, comput ed using t he second-order G oert zel algorithm . If x i s a ma tr ix , goertzel computes each column separately. The indices in vector i must be integerva lues from 1 to N, where N is the length of th e first ma tr ix dimension of x t h a tis great er tha n 1. The resulting y ha s the same dimensions a s x . I f i is omitt ed,it is a ssumed t o be [1:N], wh ich result s in a full DFT comput a tion.

y = goertzel(x,i,dim) retur ns t he discrete Fourier tr a nsform (DF T) ofmat r ix x a t t he indices in vector i, comput ed a long t he dimension dim of x .

Note fft computes a ll DFT va lues at a ll indices, while goertzel computesDF T va lues a t a specified subset of indices (i.e., a port ion of t he signa l’sfrequency ra nge). If less tha n log 2(N ) point s a re required, goertzel is moreefficient t ha n th e Fa st Fourier Tra nsform ( fft ).

Tw o exa mples wh ere goertzel can be useful a re spectral a na lysis of very largesigna ls a nd d ua l-tone multifrequency (DTMF) signa l detection.

Example G enera te a n 8-Hz sinusoid a nd use the G oertzel algori thm to detect i t using th efirst 20 indices.

Fs = 1024;Ts = 1/Fs;f = 8;N = 1024;

t = Ts*(0:N-1)';x = sin(2*pi*f*t); % Generate 8 Hz sinusoidfigure(1);plot(t,x);

goertzel

0.2

0.4

0.6

0.8

18 Hz Sinusoidal Signal

Page 510: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 510/798

7-227

figure(2);periodogram(x,[],[],Fs); % Use periodogram to obtain the PSD

% (computed with all N points of signal)

vec = 1:20;X = goertzel(x,vec); % Now use Goertzel to obtain the PSD

0 0.2 0.4 0.6 0.8 1−1

−0.8

−0.6

−0.4

−0.2

0

0 100 200 300 400 500−400

−350

−300

−250

−200

−150

−100

−50

0

Frequency (Hz)

P o w e r

S p e c t r a

l D e n s i t y

( d B / H z )

Using Periodogram to Detect the 8 Hz Signal

goertzel

figure(3); % only in the region of interestplot(vec-1,20*log10(abs(X)));

0

50

100Using Goertzel to Detect the 8 Hz Signal

Page 511: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 511/798

7-228

Algorithm goertzel implements this t ra nsfer function

where N is the length of the signal a nd k is th e index of the comput ed DF T. k is relat ed to t he indices in vector i above as k = i - 1.

The signa l flow gra ph for th is tra nsfer function is

0 5 10 15 20−250

−200

−150

−100

−50

0

H k z ( )1 W N

k z

1––

1 2 2πN ------ k z

1–z

2–+cos–

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

goertzel

Page 512: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 512/798

7-229

a nd i t is implemented a s

where and

To compute X[ k ] for a part icular k , th e G oertzel a lgorithm requires 4N real

mult iplicat ions a nd 4N real a dditions. Although t his is less efficient t ha ncomputin g t he DF T by t he direct meth od, Goertzel uses recursion t o compute

a nd

wh ich ar e evalua ted only at n = N . The direct D FT does not use recursion a ndmust compute each complex term sepa ra tely.

See Also fft , fft2

v k n [ ] x n [ ] 2 2 πk N

---------- v k n 1–[ ] v k n 2–[ ]–cos+=

0 n N ≤ ≤

X k [ ] y k N [ ] v k N [ ] W N k

v k N 1–[ ]–= =

W N k 2πk

N ---------- cos

goertzel

References [1] B urru s, C.S. a nd T.W. P a rks. D F T / F F T a n d C on v ol u t i o n A l gor i t h m s . J ohnWiley & S ons , 1985, pp. 32-26.

[2] Mitra , Sa njit K. Di gital Signa l Processin g: A Com put er -Based A ppr oach .New York, NY: McGraw-Hill, 1998, pp. 520-523.

Page 513: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 513/798

7-230

grpdelay

7grpdelayPurpose Compute th e avera ge filter delay (group delay)

Syntax [gd,w] = grpdelay(b,a,l)[gd,f] = grpdelay(b,a,l,fs)[gd,w] = grpdelay(b,a,l,' whole ')[gd,f] = grpdelay(b,a,l,' whole ',fs)gd = grpdelay(b,a,w)gd = grpdelay(b,a,f,fs)

Page 514: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 514/798

7-231

grpdelay(b,a)

Description The group delay of a f i lter is a measure of the a vera ge delay of the fi lter a s afunction of frequency. It is th e negat ive first deriva tive of the pha se responseof the filter. I f t he complex frequency r esponse of a filter is , then thegroup dela y is

where ω is frequency and θ is th e pha se a ngle of .

[gd,w] = grpdelay(b,a,l) re turns the i -point group dela y, , of th edigital f i lter

given the numera tor a nd denomina tor coefficients in vectors b a nd a . grpdelay

returns both gd , the group dela y, an d w, a vector conta ining the l frequencypoints in radia ns. grpdelay evaluat es the group delay a t l points equallyspa ced a round th e upper ha lf of the unit circle, so w contains l points bet w een0 and π.

[gd,f] = grpdelay(b,a,l,fs) specifies a positive sa mpling frequency fs inhertz. I t returns a length l vector f conta ining the a ctual frequency points a twh ich t he group delay is calcula ted, a lso in hertz. f contains l points betw een

0 and fs/2 .

H e j ω( )

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

H e j ω( )

τg ω( )

H z ( ) B z ( )A z ( )----------- b 1( ) b 2( ) z 1– L b n 1+( ) z n –+ + +

a 1( ) a 2( ) z 1– L a m 1+( ) z m –+ + +----------------------------------------------------------------------------------------= =

grpdelay

[gd,w] = grpdelay(b,a,l,' whole ') a nd

[gd,f] = grpdelay(b,a,l,' whole ',fs) use n points a round the w hole unit

circle (from 0 to 2 π, or from 0 to fs ).

gd = grpdelay(b,a,w) a nd

gd = grpdelay(b,a,f,fs) return t he group dela y evaluat ed at the points in w (in ra dia ns) or f (in hert z), respectively, w here fs is the sa mpling frequency in

Page 515: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 515/798

7-232

hertz.

grpdelay with no output a rguments plots the group dela y versus frequency inthe current f igure window.

grpdelay w orks for both rea l an d complex input sy stems.

Examples P lot t he group dela y of Butt erworth fi l ter b (z )/a (z ).

[b,a] = butter(6,0.2);grpdelay(b,a,128)

0 0.2 0.4 0.6 0.8 10

2

4

6

8

10

12

Normalized Frequency ( ×πrad/sample)

G r o u p

d e

l a y

( s a m p

l e s

)

grpdelay

P lot both th e group and phase dela ys of a syst em on th e same graph.

gd = grpdelay(b,a,512);

gd(1) = []; % Avoid NaNs[h,w] = freqz(b,a,512); h(1) = []; w(1) = [];pd = -unwrap(angle(h))./w;plot(w,gd,w,pd,':')xlabel('Frequency (rad/sec)'); grid;legend('Group Delay','Phase Delay');

Page 516: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 516/798

7-233

Algorithm grpdelay mult iplies the filter coefficient s by a unit ra mp. After F ouriertr a nsforma tion, this process corresponds t o different iat ion.

See Also cceps , fft , freqz , hilbert , icceps , rceps

0 0.5 1 1.5 2 2.5 3 3.5−6

−4

−2

0

2

4

6

8

10

12

Frequency (rad/sec)

Group DelayPhase Delay

hamming

7hammingPurpose Compute a H a mming window

Syntax w = hamming(n)w = hamming(n,' sflag ')

Description w = hamming(n) re turns an n-point symmetr ic Hamm ing window in thecolumn vector w. n should be a positive int eger. The coefficient s of a Ha mmingw indow a re computed from th e follow ing equa tion.

Page 517: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 517/798

7-234

w = hamming(n,' sflag ') re turns an n-point H a mming window using t hew indow sa mpling specified by ' sflag ' , wh ich can be either 'periodic' or'symmetric' (th e defa ult ). When 'periodic' is s pecified, hamming comput es alength n+1 window a nd returns the first n points.

Note If y ou specify a one-point w indow ( n=1 ), the va lue 1 is returned.

Examples N=64;w = hamming(N);plot(w); axis([1 N 0 1]);title('Hamming Window')

w k 1+[ ] 0.54 0.46 2 π k n 1–------------ -

cos– k 0= … n 1–, , ,=

hamming

0.5

0.6

0.7

0.8

0.9

1Hamming Window

Page 518: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 518/798

7-235

See Also barthannwin , bartlett , blackman , blackmanharris , bohmanwin , chebwin ,gausswin , hann , kaiser , nuttallwin , rectwin , triang , tukeywin , window

References [1] Oppenheim, A.V., a nd R.W. Scha fer, D i scr ete-Ti m e Si gnal Pr ocessi ng ,P ren t ice-H a ll, 1989, pp. 447-448.

10 20 30 40 50 600

0.1

0.2

0.3

0.4

hann

7hannPurpose Compute a H a nn (Ha nning) window

Syntax w = hann(n)w = hann(n,' sflag ')

Description w = hann(n) re turns an n-point sym metric Ha nn w indow in th e columnvector w. n must be a positive integer. The coefficients of a H a nn w indow a recomput ed from the followin g equa tion.

Page 519: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 519/798

7-236

w = hann(n,' sflag ') re turns an n-point H a nn w indow using the w indow sa mpling specified by ' sflag ' , wh ich can be either 'periodic' or'symmetric' (th e defa ult ). When 'periodic' is s pecified, hann computes alength n+1 window a nd returns the first n points.

Note If y ou specify a one-point w indow ( n=1 ), the va lue 1 is returned.

Examples N=64;w = hann(N);plot(w); axis([1 N 0 1]);title('Hann Window')

w k 1+[ ] 0.5 1 2 π k n 1–------------ -

cos– k 0= … n 1–, , ,=

hann

0 4

0.5

0.6

0.7

0.8

0.9

1Hann Window

Page 520: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 520/798

7-237

See Also barthannwin , bartlett , blackman , blackmanharris , bohmanwin , chebwin ,gausswin , hamming , kaiser , nuttallwin , rectwin , triang , tukeywin , window

References [1] Oppenheim, A.V., a nd R.W. Scha fer, D i scr ete-Ti m e Si gnal Pr ocessi ng ,P ren t ice-H a ll, 1989, pp. 447-448.

10 20 30 40 50 600

0.1

0.2

0.3

0.4

hilbert

7hilbertPurpose Compute the discrete-t ime a na lytic signa l using th e Hilbert tra nsform

Syntax x = hilbert(xr)x = hilbert(xr,n)

Description x = hilbert(xr) retur ns a complex helica l sequence, sometimes ca lled t heanalyt i c signal , from a real da ta sequence. The an a lytic signal x = xr + i*xi has a r ea l pa r t , xr , which is the or iginal dat a , a nd a n imaginary par t , xi , wh ichconta ins the H ilbert t ra nsform. The imagina ry pa rt is a version of the original

Page 521: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 521/798

7-238

rea l sequence with a 90° pha se shift. Sines ar e therefore tra nsformed to cosinesa nd vice versa . The Hilbert tra nsformed series ha s th e same a mplitude a ndfrequency content as the original real da ta a nd includes pha se informa tion tha tdepends on t he phase of the original da ta .

I f xr i s a ma tr ix , x = hilbert(xr) opera tes columnw ise on t he ma tr ix, findingth e Hilbert t ra nsform of each column.

x = hilbert(xr,n) uses a n n point F FT to compute th e Hilbert tr a nsform.The input da ta xr is zero-padd ed or t runca ted t o lengt h n , as a ppropriat e.

The Hilbert tra nsform is useful in calcula ting insta nta neous a t t r ibutes of atime series, especia lly the a mplitude an d frequency. The insta nt a neousa mplitude is the amplitud e of the complex Hilbert t ra nsform; theinsta nta neous frequency is the t ime ra te of change of the insta nta neous phasea ngle. For a pure sinusoid, the insta nta neous a mplitude a nd frequency a reconsta nt . The insta nta neous phase, however, is a saw tooth, reflecting the w a yin w hich the loca l phase a ngle varies linear ly over a single cycle. For mixtures

of sinusoids, th e at tr ibutes ar e short t erm, or local, avera ges spa nning n o moretha n tw o or th ree points.

Reference [1] describes the Kolmogorov method for minimum phasereconst ruction, which involves ta king the Hilbert t ra nsform of the loga rith m ofth e spectr a l density of a time series. The t oolbox function rceps performs th isreconstruction.

For a discrete-t ime a na lytic signa l x , the last ha lf of fft(x) is zero, a nd t he

first (DC ) a nd cent er (Nyqu ist) elements of fft(x) a re purely real .

Example xr = [1 2 3 4];x = hilbert(xr)

hilbert

x =1.0000+1.0000i 2.0000-1.0000i 3.0000-1.0000i 4.0000+1.0000i

You can see tha t t he imaginary par t , imag(x) = [1 -1 -1 1] , is the Hilberttra nsform of xr , and the real par t , real(x) = [1 2 3 4] , is simply xr itself.Note tha t t he las t ha l f of fft(x) = [10 -4+4i -2 0] is zero (in t his exa mple,the last ha lf is just th e last element), a nd tha t t he DC a nd Nyquist elements offft(x) , 10 and -2 respectively, a re purely rea l.

Page 522: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 522/798

7-239

hilbert

Algorithm The an a lytic signal for a sequence x has a one-sid ed Four ier tr ansfor m , tha t i s ,nega tive frequencies are 0. To a pproximat e the an a lytic signal, hilbert calculat es th e FFT of th e input sequence, replaces th ose FFT coefficients th a tcorrespond to negat ive frequencies wit h zeros, a nd calcula tes t he inverse FFTof th e result.

In detail , hilbert uses a four-step a lgorith m:

1 It calculat es the FF T of th e input sequence, storing t he result in a vector x .

2 It crea tes a vector h wh ose element s h(i) ha ve the values:

Page 523: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 523/798

7-240

- 1 for i = 1, (n/2)+1- 2 for i = 2, 3, . .. , (n/2)- 0 for i = (n/2)+2 , ... , n

3 It calculat es the element -wise product of x a nd h .

4 It calculat es the inverse FFT of th e sequence obta ined in step 3 a nd ret urnsthe first n element s of the result.

I f the input da ta xr i s a mat r ix, hilbert opera tes in a simila r ma nner,extending each step a bove to hand le the ma trix case.

See Also fft , ifft , rceps

hilbert

References [1] Cla erbout , J .F., Fu nd am enta ls of Geophysical D ata Pr ocessin g ,McG ra w -H ill, 1976, pp. 59-62.

[2] Ma rple, S.L., “Computing th e discrete-time a na lytic signa l via FFT,” I E E E T r ansacti ons on Signa l Pr ocessin g , Vol. 47, No. 9 (S eptem ber 1999),pp. 2600-2603.

[3] Oppenheim, A.V., a nd R.W. S cha fer, D i scr ete-Ti m e Si gnal Pr ocessing ,2nd ed., Prent ice-Ha ll, 1998.

Page 524: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 524/798

7-241

icceps

7iccepsPurpose Inverse complex cepstrum

Syntax x = icceps(xhat,nd)

Description x = icceps(xhat,nd) retur ns t he inverse complex cepstrum of the (a ssumedreal) sequence xhat , removing nd sa mples of delay. If xhat wa s obta ined wi thcceps(x) , then the amount of delay tha t w as a dded to x wa s th e element ofround(unwrap(angle(fft(x)))/pi) corresponding t o π r ad ians .

See Also cceps hilbert rceps unwrap

Page 525: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 525/798

7-242

See Also cceps , hilbert , rceps , unwrap

References [1] Oppenheim, A.V., a nd R.W. S cha fer, D i scr ete-Ti m e Si gnal Pr ocessing ,Prentice-Hall, 1989.

idct

7idctPurpose In verse discrete cosine tra nsform

Syntax x = idct(y)x = idct(y,n)

Description The inverse discrete cosine tr a nsform reconst ructs a sequence from its d iscretecosine t ra nsform (DC T) coefficient s. The idct function is the inverse of th e dct function.

x = idct(y) retur ns t he inverse discrete cosine tra nsform of y

Page 526: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 526/798

7-243

where

a nd N = length(x) , which is the same a s length(y) . The ser ies is in dexedfrom n = 1 and k = 1 instea d of the usual n = 0 an d k = 0 beca us e MATLABvectors run from 1 to N instea d of from 0 to N -1.

x = idct(y,n) a ppends zeros or tr unca tes t he vector y to length n beforetransforming.

I f y i s a mat r ix, idct tra nsforms i ts columns.

See Also dct , dct2 , idct2 , ifft

References [1] J a in, A.K., Fu nd am ent als of Di gital I m age Pr ocessin g , P rent ice-H a ll, 1989.

[2] P ennebaker, W.B ., an d J .L. Mitchell, J PEG St i l l I mage Data Compr ession S tandard , Va n Nostra nd Reinhold, 1993, Cha pter 4.

x n ( ) w k ( ) y k ( ) π 2 n 1–( ) k 1–( )2 N

-------------------------------------------cos

k 1=∑ n 1 … N , ,=,=

w k ( )

1N

--------- k 1=,

2N ---- 2 k N ≤ ≤,

=

ifft

7ifftPurpose One-dimensional inverse fast F ourier tr a nsform

Syntax y = ifft(x)

y = ifft(x,n)

Description ifft computes t he inverse Fourier t ra nsform of a vector or a rra y. This functionimplement s the inverse tra nsform given by

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

k n –

∑=

Page 527: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 527/798

7-244

where W N = e - j (2π/N ) a nd N = length(x) . Note t ha t t he series is indexed a sn + 1 a nd k + 1 instead of the usua l n a nd k becaus e MATLAB vectors run from1 t o N instea d of from 0 to N -1.

y = ifft(x) is the inverse Fourier tr a nsform of vector x . I f x i s an a r ray, y isth e inverse FFT of ea ch column of th e ma tr ix.

y = ifft(x,n) i s the n-point inver se FFT. If t he lengt h of x is less tha n n , ifft pads x with tra il ing zeros to length n . If th e lengt h of x i s great er than n , ifft t run cates th e sequence x . When x i s an a r ray, ifft a djusts t he length of thecolumns in the sa me man ner.

The ifft function is part of the st a nda rd MATLAB langua ge.

Algorithm The ifft function is an M-file. The algorithm for ifft i s the same a s tha t forfft , except for a sign cha nge a nd a scale factor of n = length(x) . The execut ion

time is fast est when n is a power of tw o and slowest wh en n is a large prime.

See Also fft , fft2 , fftshift , ifft2

k 0=

ifft2

7ifft2Purpose Tw o-dimensional inverse fa st Fourier tra nsform

Syntax Y = ifft2(X)

Y = ifft2(X,m,n)

Description Y = ifft2(X) returns the t wo-dimensiona l inverse fa st Fourier t ra nsform(FF T) of the a rra y X. I f X is a vector, Y has the same or ienta t ion as X.

Y = ifft2(X,m,n) trun cates or zero pads X, if necessa ry, to crea te a n m-by-n a rra y before performing th e inverse FFT. The result Y is also m-by-n .

Page 528: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 528/798

7-245

For any X, ifft2(fft2(X)) equals X to wit hin roundoff error. If X is real,ifft2(fft2(X)) may ha ve smal l imaginary par t s .

The ifft2 function is part of the st a nda rd MATLAB langua ge.

Algorithm The algorithm for ifft2 i s the same a s tha t for fft2 , except for a sign chan gea nd scale factors of [m n] = size(X) . The execution time is fa stest w hen m a nd n a re powers of two a nd slowest w hen they a re large primes.

See Also fft , fft2 , fftn , fftshift , ifft , ifftn

impinvar

7impinvarPurpose Impulse inva ria nce method for a na 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) creat es a digita l fi lter with n umerat or a nddenomina tor coefficients bz a nd az , respectively, whose impulse response isequa l to th e impulse response of the a na log filter w ith coefficient s b a nd a ,scaled by 1/fs . If you lea ve out the a rgument fs , or specify fs as t he empty

Page 529: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 529/798

7-246

vector [] , i t ta kes th e default value of 1 Hz.

[bz,az] = impinvar(b,a,fs,tol) uses t he t olera nce specified by tol t odetermine w heth er poles are repea ted. A la rger toleran ce increases th elikelihood t ha t impinvar interpret s closely loca ted poles a s mu ltiplicities(repea ted ones). The defa ult is 0.001, or 0.1%of a pole’s ma gnit ude. Note t ha tth e accuracy of th e pole values is still limited to th e accuracy obta ina ble by theroots function.

Examples Convert a n a na log lowpa ss f i lter to a digita l f il ter using impinvar wi th asam pling frequency of 10 Hz.

[b,a] = butter(4,0.3,'s');[bz,az] = impinvar(b,a,10)

bz =

1.0e-006 *

-0.0000 0.1324 0.5192 0.1273 0

az =

1.0000 -3.9216 5.7679 -3.7709 0.9246

impinvar

Algorithm impinvar performs t he impulse-inva ria nt m ethod of an a log-to-digita l tra nsferfun ction conversion discus sed in reference [1]:

1 It f inds the par tia l fraction expansion of the system represented by b a nd a .2 It replaces the poles p by the poles exp(p/fs) .

3 It finds th e tra nsfer function coefficients of the system from th e residuesfrom step 1 an d t he poles from step 2.

See Also bilinear , lp2bp , lp2bs , lp2hp , lp2lp

R f [ ] k d h l

Page 530: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 530/798

7-247

References [1] P a rks, T.W., an d C .S. B urru s, Di gi ta l F i l ter D esign , J ohn Wiley & Sons ,1987, pp. 206-209.

impz

7impzPurpose Compute t he impulse response of digita l filters

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 t he impulse response of the filter w ithnumera tor coefficients b a nd denomina tor coefficients a . impz chooses the

b f l d h i h l h d l

Page 531: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 531/798

7-248

number of sam ples a nd ret urns t he response in th e column vector h an d sampletimes in th e column vector t (where t = [0:n-1]' , and n = length(t) iscomputed automatically).

[h,t] = impz(b,a,n) computes n sa mples of th e impulse response when n isa n integer (t = [0:n-1]' ). I f n is a vector of integers, impz comput es theimpulse response at th ose int eger loca tions, sta rt ing th e response comput a tionfrom 0 (a nd t = n or t = [0 n] ). If, inst ead of n , you include th e empty vector [] for th e second a rgument , the number of sa mples is computed au toma tically bydefault .

[h,t] = impz(b,a,n,fs) computes n sa mples and produces a vector t oflength n so tha t t he samples are spaced 1/fs un it s a pa r t .

impz w ith no out put a rgument s plots t he impulse response in the currentfigure window using stem(t,h) .

impz w orks for both rea l an d complex input sy stems.

Examples P lot t he first 50 sa mples of th e impulse response of a fourt h-order low passelliptic filter w ith cutoff frequency of 0.4 times th e Nyquist frequency.

[b,a] = ellip(4,0.5,20,0.4);impz(b,a,50)

impz

0.1

0.2

0.3

0.4

0.5

Page 532: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 532/798

7-249

Algorithm impz fi lters a length n impulse sequence using

filter(b,a,[1 zeros(1,n-1)])

a nd plots t he results using stem .

To comput e n in the a uto-length ca se, impz either uses n = length(b) for t heFI R case or first finds th e poles using p = roots(a) , if length(a) is grea tert ha n 1 .

If t he fi lter is unst a ble, n is chosen to be the point a t wh ich t he term from thela rgest pole rea ches 10^6 times its original value.

If the filter is stable, n is chosen t o be the point a t wh ich t he term due t o thela rgest a mplitude pole is 5*10^-5 of its original a mplitude.

If the filter is oscillatory (poles on the unit circle only), impz computes fiveperiods of t he slowest oscillat ion.

If th e fil ter ha s both oscil lat ory a nd da mped terms, n is chosen t o equa l fiveperiods of th e slow est oscillat ion or the point a t w hich the t erm due to the

la rgest (nonunity) am plitude pole is 5*10^-5 of its original amplitude,wh ichever is great er.

0 5 10 15 20 25 30 35 40 45-0.2

-0.1

0

impz

impz a lso a llow s for delay s in th e numera tor polynomia l. The number of dela ysis incorporat ed into the comput a tion for the number of samples.

See Also impulse , stem

Page 533: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 533/798

7-250

interp

7interpPurpose Increase sa mpling ra te by a n int eger fa ctor ( interpolat ion)

Syntax y = interp(x,r)

y = interp(x,r,l,alpha)[y,b] = interp(x,r,l,alpha)

Description Int erpola tion increases th e original sa mpling ra te for a sequence to a higherra te . interp performs lowpa ss interpolat ion by insert ing zeros into th e origina lsequence an d t hen a pplying a special lowpass fi lter.

y = interp(x,r) increases the sa mpling ra te of x by a factor of r . The

Page 534: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 534/798

7-251

int erpola ted vector y is r t imes longer tha n t he original input x .

y = interp(x,r,l,alpha) specifies l (filter length ) a nd alpha (cut-offfrequency). The default value for l is 4 a nd t he defa ult va lue for alpha is 0.5.

[y,b] = interp(x,r,l,alpha) retur ns vector b containing the filtercoefficients used for t he int erpola tion.

Examples Int erpola te a signal 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');

interp

-2

-1.5

-1

-0.5

0

0.5

1

1.5

2Interpolated Signal

-2

-1.5

-1

-0.5

0

0.5

1

1.5

2Original Signal

Page 535: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 535/798

7-252

Algorithm interp uses th e low pas s int erpola tion Algorithm 8.1 described in [1]:

1 It expa nds t he input vector to the correct length by ins erting zeros betw eenthe original dat a va lues.

2 It d esigns a specia l symmetric FIR fi l ter tha t a l lows the original da ta to passthr ough unchanged a nd interpolat es between so tha t t he mea n-squa re

errors betw een t he interpolat ed points a nd t heir idea l values a re minimized.3 It a pplies the filter to the input vector to produce the interpolat ed out put

vector.

The length of the FI R low pass in terpolat ing filter is 2 *l*r+ 1. The n umber oforigina l sam ple va lues used for int erpolat ion is 2 *l . Ordinarily, l should beless tha n or equal t o 10. The original signal is a ssumed to be band l imited w ithnorma lized cutoff frequency 0 ≤ alpha ≤1, w here 1 is ha lf the origina l sam plingfrequency (th e Nyqu ist frequency). The defa ult va lue for l i s 4 and the defaul tva lue for alpha i s 0.5.

Diagnostics I f r is not a n integer, interp gives the following error messa ge.

Resampling rate R must be an integer.

See Also decimate , downsample , interp1 , resample , spline , upfirdn , upsample

References [1] Pr ogram s for Di gital Signal Pr ocessin g , IE EE P ress, New York, 1979,Algorith m 8.1.

0 20 40 60 80 100 1202

0 5 10 15 20 25 302

intfilt

7intfiltPurpose Interpolation FIR filter design

Syntax b = intfilt(r,l,alpha)

b = intfilt(r,n,' Lagrange ')

Description b = intfilt(r,l,alpha) designs a l inea r pha se FIR fi l ter tha t performs idealband limited interpolat ion using the n earest 2*l nonzero sa mples, w hen usedon a sequence interleaved with r-1 consecut ive zeros every r samples. Ita ssumes an original ba ndlimitedness of alpha t imes th e Nyquist frequency.The return ed filter is identical to tha t used by interp .

Page 536: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 536/798

7-253

b = intfilt(r,n,' Lagrange ') or

b = intfilt(r,n,' l ') designs a n FI R fi lter th a t performs n th-orderLa gra nge polynomial interpolat ion on a sequence interleaved w ith r-1 consecut ive zeros every r samples. b has length (n + 1)*r for n even, and length(n + 1)*r-1 for n odd.

B oth types of f i lters a re basica lly lowpa ss a nd a re intended for interpolat iona nd decimat ion.

Examples Design a digita l interpolat ion fi l ter to upsample a signa l by four, using theband limited m ethod.

alpha = 0.5; % "Bandlimitedness" factorh1 = intfilt(4,2,alpha); % Bandlimited interpolation

The filt er h1 works best w hen th e original signal is ba ndlimited t o alpha t imes

the Nyq uist frequency. Creat e a bandlimited noise signal.randn('state',0)x = filter(fir1(40,0.5),1,randn(200,1)); % Bandlimit

Now zero pad t he signa l wit h t hree zeros betw een every sa mple. The resultingsequence is four times th e lengt h of x .

xr = reshape([x zeros(length(x),3)]',4*length(x),1);

Int erpola te using the filter command.y = filter(h1,1,xr);

intfilt

y is an int erpola ted version of x , delay ed by seven sa mples (th e group-delay ofthe filter). Zoom in on a section to see this.

plot(100:200,y(100:200),7+(101:4:196),x(26:49),'o')

−0.2

0

0.2

0.4

0.6

0.8

Page 537: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 537/798

7-254

intfilt a lso performs La gra nge polynomial int erpolat ion of th e origina lsigna l. For example, first-order polynomial int erpola tion is just linea rinterpolat ion, w hich is a ccomplished w ith a tr ia ngular f i lter.

h2 = intfilt(4,1,'l') % Lagrange interpolation

h2 =0.2500 0.5000 0.7500 1.0000 0.7500 0.5000 0.2500

Algorithm The ba ndlimited m ethod usesfirls

to design a n int erpola tion FIR equiva lentto t ha t present ed in [1]. The polynomial m ethod uses La gra nge’s polynomialinterpolat ion formula on equa lly spa ced sa mples to construct t he appropria tefilter.

See Also decimate , downsample , interp , resample , upsample

References [1] Oetken, Pa rks, a nd S chüßler, “New R esults in th e Design of Digita l

Int erpolat ors,” IEEE T r ans. Acoust., Speech, Si gnal Pr ocessing , Vol. ASS P -23(J un e 1975), pp. 301-309.

100 110 120 130 140 150 160 170 180 190 200−1.2

−1

−0.8

−0.6

−0.4

invfreqs

7invfreqsPurpose Ident ify continuous-time filter para meters from frequency response da ta

Syntax [b,a] = invfreqs(h,w,n,m)

[b,a] = invfreqs(h,w,n,m,wt)[b,a] = invfreqs(h,w,n,m,wt,iter)[b,a] = invfreqs(h,w,n,m,wt,iter,tol)[b,a] = invfreqs(h,w,n,m,wt,iter,tol,' trace ')[b,a] = invfreqs(h,w,' complex ',n,m,...)

Description invfreqs is th e inverse operat ion of freqs . It finds a continuous-time tr a nsferfunction th a t corresponds to a given complex frequency response. From a

Page 538: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 538/798

7-255

laboratory analysis standpoint, invfreqs is useful in converting magnitudea nd phase dat a int o tra nsfer functions.

[b,a] = invfreqs(h,w,n,m) returns th e real numerat or an d denominat orcoefficient vectors b a nd a of the transfer function

w hose complex frequen cy response is given in vector h a t t he frequency pointsspecified in vector w. Scala rs n a nd m specify t he desired orders of th enumera tor a nd denominator polynomials.

Frequ ency is specified in ra dia ns betw een 0 a nd π, and t he length of h must bethe sa me as the length of w. invfreqs uses conj(h) a t -w to ensure t he properfrequency doma in symmetry for a real f i l ter.

[b,a] = invfreqs(h,w,n,m,wt) w eights t he fit-errors versus frequency,where wt is a vector of weighting fa ctors th e same length a s w.

[b,a] = invfreqs(h,w,n,m,wt,iter) a nd

[b,a] = invfreqs(h,w,n,m,wt,iter,tol) provide a superior a lgorithm tha tgua ra ntees sta bili ty of the result ing l inea r system a nd searches for t he best f i tusing a numerical, itera tive scheme. The iter para meter tells invfreqs to end

the i t erat ion w hen t he solution h a s converged, or a fter iter i terations,w hichever comes first . invfreqs defines convergence as occurring w hen t henorm of th e (modified) gra dient vector is less t ha n tol , where tol is an optionalpa ra meter t ha t defa ults t o 0.01. To obta in a weight vector of all ones, use

H s ( ) B s ( )A s ( )----------- b 1( ) s n b 2( ) s n 1– L b n 1+( )+ + +

a 1( ) s m a 2( ) s m 1– L a m 1+( )+ + +----------------------------------------------------------------------------------------- -= =

invfreqs

invfreqs(h,w,n,m,[],iter,tol)

[b,a] = invfreqs(h,w,n,m,wt,iter,tol,' trace ') displays a textua l

progress report of th e iterat ion.[b,a] = invfreqs(h,w,' complex ',n,m,...) creat es a complex filter. In th iscase no symmetry is enforced, a nd t he frequency is specified in ra dia nsbetween -π a nd π.

Remarks When building higher order models using high frequ encies, it is import a nt toscale the frequencies, dividing by a fa ctor such a s ha lf the highest frequencypresent in w, so as t o obta in w ell condit ioned va lues of a a nd b . This correspond s

Page 539: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 539/798

7-256

to a r esca ling of time.

Examples Exa mple 1Convert a simple tra nsfer function to frequency response dat a a nd t hen backto t he origina l filter coefficients.

a = [1 2 3 2 1 4]; b = [1 2 3 2 3];[h,w] = freqs(b,a,64);[bb,aa] = invfreqs(h,w,4,5)

bb =

1.0000 2.0000 3.0000 2.0000 3.0000

aa =

1.0000 2.0000 3.0000 2.0000 1.0000 4.0000

invfreqs

Notice tha t bb a nd aa ar e equivalent to b a nd a , respectively. However, aa ha spoles in t he left ha lf-plane a nd t hus t he system is unsta ble. Use invfreqs ’si terat ive a lgorithm t o find a sta ble a pproximat ion t o 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

Page 540: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 540/798

7-257

Exa mple 2Suppose you ha ve tw o vectors, mag a nd phase , tha t conta in magni tude andphase data gathered in a labora t ory, and a th i rd vector w of frequ encies. Youcan convert the data into a continuous-time transfer function using invfreqs .

[b,a] = invfreqs(mag.*exp(j*phase),w,2,3);

Algorithm B y defaul t , invfreqs uses an equ a tion error method to identify t he best modelfrom t he da ta . This f inds b a nd a in

by crea ting a syst em of linea r equa tions a nd solving th em wit h MATLAB’s \ operator. Here A (w (k )) a nd B (w (k )) a re the Fourier tra nsforms of th e

polynomials a a nd b , respectively, a t t he frequency w (k ), an d n is the numberof frequency points (the length of h a nd w). This a lgorith m is ba sed on L evi [1].Severa l varia nts h ave been suggested in the l i terat ure, wh ere the w eightingfunction wt gives less at tent ion t o high frequencies.

minb a ,

w t k ( ) h k ( ) A w k ( )( ) B w k ( )( )– 2

k 1=

n

invfreqs

The superior (“output -error”) a lgorit hm uses th e da mped G a uss-Newt on meth odfor itera tive sea rch [2], with the output of the first a lgorithm a s th e initialestima te. This solves th e direct problem of minimizing th e weight ed sum of the

squa red error betw een t he a ctual a nd t he desired frequency response points.

See Also freqs , freqz , invfreqz , prony

References [1] Levi E C “C omplex Cur ve Fit tin g ”IR E T ran s. on Au tomat ic Contr ol

minb a ,

w t k ( ) h k ( ) B w k ( )( )A w k ( )( )--------------------–

2

k 1=∑

Page 541: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 541/798

7-258

References [1] Levi, E .C., C omplex-Cur ve Fit tin g, ,Vol. AC-4 (1959), pp. 37-44.

[2] Dennis, J .E. , J r. , and R.B . Schnabel. N um eri cal M ethods for U nconstra in ed Opt imi za t ion and N onl i nea r Equa t ions . Englewood Cliffs, NJ : Prent ice-H a ll,1983.

invfreqz

7invfreqzPurpose Ident ify discrete-time filter para meters from frequency response da ta

Syntax [b,a] = invfreqz(h,w,n,m)

[b,a] = invfreqz(h,w,n,m,wt)[b,a] = invfreqz(h,w,n,m,wt,iter)[b,a] = invfreqz(h,w,n,m,wt,iter,tol)[b,a] = invfreqz(h,w,n,m,wt,iter,tol,' trace ')[b,a] = invfreqz(h,w,' complex ',n,m,...)

Description invfreqz is th e inverse operat ion of freqz ; it finds a discrete-time tr a nsferfunction th a t corresponds to a given complex frequency response. From alaboratory analysis standpoint invfreqz ca n be used to convert ma gnitude

Page 542: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 542/798

7-259

laboratory analysis standpoint, invfreqz ca n be used to convert ma gnitudea nd phase dat a int o tra nsfer functions.

[b,a] = invfreqz(h,w,n,m) returns th e real numerat or an d denominat orcoefficient s in vectors b a nd a of the transfer function

w hose complex frequen cy response is given in vector h a t t he frequency pointsspecified in vector w. Scala rs n a nd m specify t he desired orders of th enumera tor a nd denominator polynomials.

Frequ ency is specified in ra dia ns betw een 0 a nd π, and the length of h must bethe sa me as the length of w. invfreqz uses conj(h) a t -w to ensure t he properfrequency doma in symmetry for a real f i l ter.

[b,a] = invfreqz(h,w,n,m,wt) w eights t he fit-errors versus frequency,where wt is a vector of weighting fa ctors th e same length a s w.

[b,a] = invfreqz(h,w,n,m,wt,iter) a nd

[b,a] = invfreqz(h,w,n,m,wt,iter,tol) provide a superior a lgorithm tha tgua ra ntees sta bili ty of the result ing l inea r system a nd searches for t he best f i tusing a numerical, itera tive scheme. The iter para meter tells invfreqz to end

the i t erat ion w hen t he solution h a s converged, or a fter iter i terations,w hichever comes first . invfreqz defines convergence as occurring w hen t henorm of th e (modified) gra dient vector is less t ha n tol , where tol is an optionalpa ra meter t ha t defa ults t o 0.01. To obta in a weight vector of all ones, use

H z ( ) B z ( )A z ( )----------- b 1( ) b 2( ) z 1– L b n 1+( ) z n –+ + +

a 1( ) a 2( ) z 1– L a m 1+( ) z m –+ + +----------------------------------------------------------------------------------------= =

invfreqz

invfreqz(h,w,n,m,[],iter,tol)

[b,a] = invfreqz(h,w,n,m,wt,iter,tol,' trace ') displays a textua lprogress report of th e iterat ion.

[b,a] = invfreqz(h,w,' complex ',n,m,...) creat es a complex filter. In th iscase no symmetry is enforced, a nd t he frequency is specified in ra dia nsbetween -π a nd π.

Examples Convert a simple tra nsfer function to frequency response dat a a nd t hen backto t he origina l filter coefficients.

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

Page 543: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 543/798

7-260

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

Notice tha t bb a nd aa a re equivalent to b a nd a , r espectively. H owever, aa ha spoles outside the unit circle and thus the system is unst a ble. Use invfreqz ’si terat ive a lgorithm t o find a sta ble a pproximat ion t o the system.

[bbb,aaa] = invfreqz(h,w,4,5,[],30)

bbb =

0.2427 0.2788 0.0069 0.0971 0.1980

aaa =

1.0000 -0.8944 0.6954 0.9997 -0.8933 0.6949

invfreqz

Algorithm B y defaul t , invfreqz uses an equa tion error method to identify t he best modelfrom t he da ta . This f inds b a nd a in

by crea ting a syst em of linea r equa tions a nd solving th em wit h MATLAB’s \ operator. Here A (ω(k )) a nd B (ω(k )) a re th e Fourier tr a nsforms of th epolynomials a a nd b , respectively, a t t he frequency ω(k ), a nd n is the numberof frequency points (the lengt h of h a nd w). This a lgorith m is a ba sed on Levi [1].

The superior (“output -error”) a lgorith m us es th e da mped G a uss-Newt on

minb a ,

w t k ( ) h k ( ) A ω k ( )( ) B ω k ( )( )– 2

k 1=

n

Page 544: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 544/798

7-261

p ( p ) g pmethod for i tera tive search [2], wit h t he output of the f irst a lgori thm as theinitia l estima te. This solves th e direct problem of minimizing th e weight ed sumof the squa red error betw een t he a ctual a nd t he desired frequency responsepoints.

See Also freqs , freqz , invfreqz , prony

References [1] Levi, E .C., “C omplex-Cu rve Fit t ing,” I RE T ran s. on Au tomat ic Contr ol ,Vol. AC-4 (1959), pp. 37-44.

[2] Dennis, J .E. , J r. , and R.B . Schnabel, N um eri cal M ethods for U nconstra in ed

Opt imi za t ion and Nonl in ea r Equa t ions , P rent ice-H a ll, 1983.

minb a ,

w t k ( ) h k ( ) B ω k ( )( )

A ω k ( )( )

-------------------–2

k 1=

n

is2rc

7is2rcPurpose Convert inverse sine par a meters t o reflection coefficients

Syntax k = is2rc(isin)

Description k = is2rc(isin) returns a vector of reflection coefficients k from a vector ofinverse sine para meters isin .

Examples isin = [0.2000 0.8727 0.0020 0.0052 -0.0052];k = is2rc(isin)

k =

0.3090 0.9801 0.0031 0.0082 -0.0082

Page 545: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 545/798

7-262

See Also ac2rc , lar2rc , poly2rc , rc2is

References [1] Deller, J .R., J .G. P roakis, a nd J .H.L. Ha nsen, “D i scr ete-Ti m e Pr ocessi n g of Speech Si gnal s ,” P rent ice-H a ll, 1993.

kaiser

7kaiserPurpose Compute a Ka iser w indow

Syntax w = kaiser(n,beta)

Description w = kaiser(n,beta) re turns an n-point Ka iser ( I 0 – sinh) window in thecolumn vector w. beta is the Ka iser w indow β parameter tha t affects thesidelobe at tenua tion of th e Fourier tra nsform of th e window.

To obta in a Ka iser w indow tha t designs a n FI R fi lter w ith sidelobe height-α dB , use the follow ing β.

β 0.1102 α 8.7–( ), α 50>0 5842 α 21( )0 4 0 07886 α 21( )+ 50 α 21≥ ≥=

Page 546: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 546/798

7-263

Increasing beta widens th e main lobe and decreases the a mplitude of thesidelobes (increases t he a tt enua tion).

Example N=200;w = kaiser(N,0.5);plot(w);title('Kaiser Window, beta = .5')

β ( )0.5842 α 21–( )0.4 0.07886 α 21–( )+ , 50 α 21≥ ≥0, α 21<

0 20 40 60 80 100 120 140 160 180 2000.94

0.95

0.96

0.97

0.98

0.99

1Kaiser Window, beta = .5

kaiser

See Also barthannwin , bartlett , blackman , blackmanharris , bohmanwin , chebwin ,gausswin , hamming , hann , kaiserord , nuttallwin , rectwin , triang , tukeywin ,window

References [1] Ka iser, J .F., “Nonrecursive Digit a l Filter Design U sing th e - sinhWindow Function,” Proc. 1974 IE EE Symp. Cir cui ts and Systems , (Apr il 1974),pp. 20-23.

[2] Selected Paper s in Di gital Signal Pr ocessin g I I , IEE E P ress, New York,1975.

[3] Oppenheim, A.V., a nd R.W. S cha fer, D i scr ete-Ti m e Si gnal Pr ocessing ,

P rent ice-H a ll, 1989, p. 453.

I 0

Page 547: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 547/798

7-264

kaiserord

7kaiserordPurpose Est imat e para meters for a n FIR fi lter design with a Ka iser 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 returns a f i lter order n a nd beta para meter to specify a Ka iserwindow for use wit h the fir1 function. Given a set of specifica tions in th efrequency domain , kaiserord estimat es the minimum FIR fi l ter order tha t w illa pproximat ely meet t he specifica tions. kaiserord converts th e given filterspecifications into passband and stopband ripples and converts cutoff

frequencies int o the form n eeded for wind owed FI R filter design.

Page 548: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 548/798

7-265

[n,Wn,beta,ftype] = kaiserord(f,a,dev) finds the approximate order n ,normalized frequency band edges Wn , and w eights tha t meet inputspecifications f , a , and dev . f is a vector of band edges a nd a is a vectorspecifying th e desired a mplitude on the ba nds defined by f . The lengt h of f istw ice the lengt h of a , minu s 2. Together , f a nd a define a desired piecewiseconst a nt r esponse function. dev is a vector the sa me size a s a tha t specifies the

ma ximum a llowa ble error or deviat ion betw een t he frequency response of theoutput filter a nd it s desired am plitude, for each ba nd. The entries in dev specify the passband ripple and the stopband attenuation. You specify eachentry in dev a s a positive number, represent ing a bsolute filter ga in (not indecibels).

Note If, in t he vector dev , you specify unequa l devia tions a cross ban ds, the

minimum s pecified deviat ion is used, since th e Ka iser window m ethod isconst ra ined to produce filters wit h minimum d eviat ion in a ll of the ba nds.

fir1 can us e the resulting order n , frequen cy vector Wn , mul t iband magni tudetype ftype , and t he Kaiser w indow parameter beta . The ftype string isint ended for use with fir1 ; i t is equa l to 'high' for a highpass fi lter a nd 'stop' for a bandst op fi lter. For multiband fi lters, i t can be equa l to 'dc-0' when thefirst band is a stopba nd (sta rt ing a t f = 0) or 'dc-1' wh en the first ba nd is apassband.

kaiserord

To design a n F IR filter b th a t a pproximat ely meets the specifica tions given bykaiser parameters f , a , and dev , use the following comma nd.

b = fir1(n,Wn,kaiser(n+1,beta),ftype,'noscale')

[n,Wn,beta,ftype] = kaiserord(f,a,dev,fs) uses a sa mpling frequency fs in H z. If you don’t specify th e ar gument fs, or if you specify it a s t he emptyvector [] , it defaults t o 2 Hz, an d the Nyquist frequency is 1 Hz. You ca n usethis syn ta x to specify ban d edges sca led t o a part icular application’s sa mplingfrequency. The frequency ba nd edges in f must be from 0 to fs /2.

c = kaiserord(f,a,dev,fs,' cell ') is a cell-a rra y w hose elements a re the

parameters to fir1 .

Page 549: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 549/798

7-266

Note In some cases, kaiserord underestima tes or overestima tes the order n .If t he filter does not meet t he specifica tions, try a higher order such as n+1 , n+2 ,a nd so on, or a try lower order.

Results a re inaccurat e if the cutoff frequencies are near 0 or the Nyquistfrequ ency, or if dev is la rge (great er t ha n 10%).

Remarks B e careful to dist inguish betw een t he meanings of f i l ter length a nd fi l ter order.The filter length is th e number of impulse response samples in th e FIR filter.G enerally, t he impulse response is indexed from n = 0 t o n = L -1, w here L is thefilter length. The filter order is the highest power in a z -transformrepresenta tion of th e f il ter. For an FIR tra nsfer function, this representa tion is

a polynomial in z , where th e highest pow er is z L -1 a nd t he lowest power is z 0.The filter order is one less th a n t he length ( L -1) a nd is a lso equa l to th e numberof zeros of t he z polynomial.

Examples Exa mple 1Design a lowpass f i l ter with passban d defined from 0 to 1 kHz a nd st opba nddefined from 1500 Hz t o 4 kHz. S pecify a passba nd ripple of 5%a nd a stopbandat tenuat ion of 40 dB.

fsamp = 8000;fcuts = [1000 1500];mags = [1 0];

kaiserord

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 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−120

−100

−80

−60

−40

−20

0

20

Normalized Frequency ( ×πrad/sample)

M a g n

i t u d e

( d B )

Page 550: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 550/798

7-267

Exa mple 2Design a n odd-length bandpa ss fi l ter (note t ha t odd length means even order,so the input t o 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

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

Normalized Frequency ( ×πrad/sample)

P h a s e

( d e g r e e s

)

kaiserord

0

0.2

0.4

0.6

0.8

1

1.2

1.4

Page 551: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 551/798

7-268

Exa mple 3Design a lowpass fi l ter wit h a passban d cutoff of 1500 Hz, a stopban d cutoff of2000 Hz, passba nd ripple of 0.01, stopband ripple of 0.1, an d 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 t o

c = kaiserord([1500 2000],[1 0],[0.01 0.1],8000,'cell');b = fir1(c:);

Algorithm kaiserord uses empirically derived formula s for estima ting t he orders oflowpa ss fil ters, as well as differentiat ors and H ilbert tra nsformers. Estima tesfor mult iban d filters (such as ba ndpa ss filters) a re derived from the low passdesign formulas.

The design formula s tha t un derlie the Ka iser w indow a nd i ts a pplica tion toFIR fi l ter design a re

0 500 1000 1500 2000 2500 3000 3500 40000

kaiserord

where α = -20log10δ is the st opba nd a tt enua tion expressed in decibels (recallt h a t δp = δs is required).

The design formula is

where n is the filter order a nd ∆ωis the widt h of the smallest tra nsit 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 552: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 552/798

7-269

See Also fir1 , kaiser , remezord

References [1] Ka iser, J .F., “Nonrecursive Digita l Filter Design U sing th e - sinhWindow Funct ion,” P roc. 1974 I EE E Sym p. Cir cui ts and Systems , (April 1974),pp. 20-23.

[2] Selected Paper s in Di gital Signa l Processin g I I , IEE E P ress, New York,1975, pp. 123-126.

[3] Oppenh eim, A.V., a nd R.W. S cha fer, D i scr ete-Ti m e Si gnal Pr ocessi ng ,P ren t ice-H a ll, 1989, pp. 458-562.

I 0

lar2rc

7lar2rcPurpose Convert log area ra tio para meters t o reflection coefficient s

Syntax k = lar2rc(g)

Description k = lar2rc(g) returns a vector of reflection coefficients k from a vector of logarea ra t io parameters g .

Examples g = [0.6389 4.5989 0.0063 0.0163 -0.0163];k = lar2rc(g)

k =0.3090 0.9801 0.0031 0.0081 -0.0081

See Also ac2rc , is2rc , poly2rc , rc2lar

Page 553: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 553/798

7-270

See Also ac2rc , is2rc , poly2rc , rc2lar

References [1] Deller, J .R., J .G. P roakis, a nd J .H.L. Ha nsen, “D i scr ete-Ti m e Pr ocessi n g of Speech Si gnal s ,” P rent ice-H a ll, 1993.

latc2tf

7latc2tfPurpose Convert lat t ice fi l ter para meters to tra nsfer function form

Syntax [num,den] = latc2tf(k,v)

[num,den] = latc2tf(k,' iiroption ')num = latc2tf(k,' firoption ')num = latc2tf(k)

Description [num,den] = latc2tf(k,v) finds the tra nsfer function numerat or num a nddenominator den from th e IIR lat tice coefficients k a nd la dder coefficients v .

[num,den] = latc2tf(k,' iiroption ') produces a n II R fi l ter tra nsfer

function according t o the value of the string ' iiroption ' :• 'allpole' : P roduces a n a ll-pole filter tr a nsfer function from t he as socia ted

Page 554: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 554/798

7-271

p pall-pole IIR lattice filter coefficients k .

• 'allpass' : P roduces an a llpa ss fi lter t ra nsfer function from the a ssocia teda llpass II R la tt ice filter coefficients k .

num = latc2tf(k,' firoption ') produces an F IR filter a ccording to the va lueof the str ing ' firoption ' :

• 'min' : P roduces a minimum-phase FI R fi l ter numerat or from th e associat edminimum-pha se FIR lat tice filter coefficients k .

• 'max' : P roduces a ma ximum-phase FI R fi l ter numerat or from t he a ssocia tedma ximum-pha se FIR la tt ice filter coefficients k .

• 'FIR' : P roduces a genera l FIR fi lter numera tor from t he lat t ice fi ltercoefficients k (defau lt, if you lea ve off the st ring a ltogether).

See Also latcfilt , tf2latc

latcfilt

7latcfiltPurpose La tt ice a nd lat t ice-ladder f i l ter implementa tion

Syntax [f,g] = latcfilt(k,x)

[f,g] = latcfilt(k,v,x)[f,g] = latcfilt(k,1,x)[f,g,zf] = latcfilt(...,' ic ',zi)

Description When filtering da ta , lat tice coefficients ca n be used to represent :

• FIR fi lters• All-pole IIR filters• Allpass II R filters• G enera l IIR fi lters

Page 555: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 555/798

7-272

[f,g] = latcfilt(k,x) filters x wit h t he FIR lat t ice coefficients in th evector k . f is the forwa rd la tt ice fil ter result a nd g is the backwa rd fi l ter result .I f , f corresponds to the minimum -pha se output , an d g corresponds to t hemaximum-phase output.

I f k a nd x a re vectors, the result is a (signal) vector. Mat rix argument s a repermitt ed under t he followin g rules:

• I f x i s a ma tr ix and k is a vector, each column of x is processed thr ough th elat tice filter specified by k .

• I f x is a vector a nd k is a ma tr ix, each column of k is used t o filter x , and asignal ma trix is return ed.

• I f x a nd k ar e both ma trices w ith t he same num ber of columns, then th e i t h

column of k is used to filter t he i th column of x . A signal ma trix is returned.

[f,g] = latcfilt(k,v,x) filters x wit h th e IIR la tt ice coefficients k a ndladder coefficients v . k a nd v must be vectors, while x ca n be a signa l mat rix.

[f,g] = latcfilt(k,1,x) filters x wit h t he IIR lat t ice specified by k , where k a nd x can be vectors or ma tr ices. f is th e all-pole la tt ice filter result a nd g i s thea llpa ss fi l ter result .

[f,g,zf] = latcfilt(...,' ic ',zi) a ccepts a length- k vector zi specifyingthe init ia l condition of the la t t ice sta tes. Output zf is a length-k vectorspecifying the fina l condition of the lat tice sta tes.

k 1≤

latcfilt

See Also filter , latc2tf , tf2latc

Page 556: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 556/798

7-273

levinson

7levinsonPurpose Compute t he Levinson-Dur bin recursion

Syntax a = levinson(r,p)

Description The Levinson-Dur bin recursion is a n a lgorith m for finding a n a ll-pole IIR filterw ith a prescribed determin istic aut ocorrelat ion sequence. It ha s applica tions infilter design, coding, and spectra l estima tion. The filter tha t levinson producesis minimum phase.

a = levinson(r,p) finds t he coefficients of an p th -order au toregressive linearprocess which ha s r as its autocorrelation sequence. r is a rea l or complex

determinist ic aut ocorrelat ion sequence (a vector), a nd p is th e order ofdenominator polynomial A (z ); tha t is , a = [1 a(2) ... a(p+1)] . The filtercoefficients are ordered in descending powers of z .

Page 557: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 557/798

7-274

Algorithm levinson solves the sy mmetr ic Toeplitz syst em of linear equa tions

where r = [ r (1) ... r (p+ 1) ] is the input autocorrelation vector, and r (i )*

denot es th e complex conjuga t e of r (i ). The a lgorith m requ ires O (p 2

) flops an d isth us mu ch more efficient th a n t he MATLAB \ comma nd for large p . However,t he levinson function uses \ for low orders to provide th e fast est possibleexecution.

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+( )–

=

levinson

See Also lpc , prony , rlevinson , schurrc , stmcb

References [1] Ljung, L., System I dent ifi cati on: T heory for the U ser , P rent ice-H a ll, 1987,pp. 278-280.

Page 558: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 558/798

7-275

lp2bp

7lp2bpPurpose Tra nsform lowpass a na log fi lters t o ba ndpass

Syntax [bt,at] = lp2bp(b,a,Wo,Bw)[At,Bt,Ct,Dt] = lp2bp(A,B,C,D,Wo,Bw)

Description lp2bp tra nsforms a na log lowpa ss fi l ter prototypes with a cutoff frequency of1 ra d/s into ban dpass fi l ters wit h desired bandw idth a nd center frequency. Thetr a nsforma tion is one step in the digita l filter design process for th e butter ,cheby1 , cheby2 , and ellip functions.

lp2bp can perform t he tra nsforma tion on t wo different l inea r syst emrepresenta tions: tra nsfer function form a nd st a te-space form. In both cases, theinput system must be an a na log fi lter prototype.

Transfer Function Form (Polynomial)

Page 559: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 559/798

7-276

Transfer Function Form (Polynomial)

[bt,at] = lp2bp(b,a,Wo,Bw) tra nsforms a n a na log lowpa ss fi lter prototypegiven by polynomial coefficient s into a ban dpa ss filter w ith center frequ ency Wo and bandwid th Bw. Row vectors b a nd a specify t he coefficients of the n umera tora nd denomina tor of the prototype in descending powers of s .

Scalars Wo a nd Bwspecify the cent er frequency an d ba ndw idth in unit s of ra d/s.For a f i l ter with lower band edge w1 a nd upper ban d edge w2, use

Wo = sqrt(w1*w2) a nd Bw= w2-w1 .

lp2bp returns the frequency transformed filter in row vectors bt a nd at .

Sta te-Spa ce Form

[At,Bt,Ct,Dt] = lp2bp(A,B,C,D,Wo,Bw) convert s t he continuous-timesta te-spa ce low pass filter prototype in mat rices A , B, C, D shown below

b s ( )a s ( )---------- b 1( ) s n L b n ( ) s b n 1+( )+ + +

a 1( ) s m L a m ( ) s a m 1+( )+ + +---------------------------------------------------------------------------------=

x · A x B u +=

y C x D u +=

lp2bp

into a ba ndpass fi l ter with center frequency Wo and bandwid th Bw. For a filterwit h lower ban d edge w1 a nd upper ban d edge w2, use Wo = sqrt(w1*w2) a ndBw= w2-w1 .

The bandpass filter is returned in matrices At , Bt , Ct , Dt .

Algorithm lp2bp is a highly accurate state-space formulation of the classic analog filterfrequency tr a nsforma tion. Consider t he st a te-space system

where u is the input, x is the sta te vector, and y is th e output . The La placetr a nsform of th e first equa tion (a ssuming zero initia l conditions) is

x · A x B u +=

y C x D u +=

sX s( ) A X s( ) B U s( )+=

Page 560: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 560/798

7-277

Now if a band pass fi l ter is to ha ve center frequency ω0 and bandwid th B w, thes tandard s -doma in t ra nsforma tion is

where Q = ω0/B w a nd p = s /ω0. Substi tut ing this for s in the Laplacetransformed state-space equation, and considering the operator p a s d /d t results in

or

Now define

wh ich, when substi tuted, lea ds to

sX s ( ) A X s ( ) B U s ( )+=

s Q p 2 1+( ) p ⁄ =

Q x ·· Q x + A·

x B u ·+=

Q x ·· A·– x B – u · Q x –=

Q ω· Q x –=

Q x · A x Q ω B u + +=

lp2bp

The last tw o equa tions give equat ions of sta te. Write them in st a nda rd forma nd multiply the differentia l equat ions by ω0 to r ecover t he t ime/frequ encyscaling represented by p a nd find sta te ma trices for the ban dpass fi lter.

Q = Wo/Bw; [ma,m] = size(A); At = Wo*[A/Q eye(ma,m);-eye(ma,m) zeros(ma,m)];

Bt = Wo*[B/Q; zeros(ma,n)];Ct = [C zeros(mc,ma)];Dt = d;

If the input to lp2bp is in tra nsfer function form, th e function tra nsforms i t intosta te-spa ce form before applying t his a lgorith m.

See Also bilinear , impinvar , lp2bs , lp2hp , lp2lp

Page 561: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 561/798

7-278

lp2bs

7lp2bsPurpose Tra nsform lowpass a na log fi l ters to bandst op

Syntax [bt,at] = lp2bs(b,a,Wo,Bw)[At,Bt,Ct,Dt] = lp2bs(A,B,C,D,Wo,Bw)

Description lp2bs tra nsforms a na log lowpa ss fi l ter prototypes with a cutoff frequency of1 ra d/s into ban dstop fil ters with desired bandw idth a nd center frequency. Thetr a nsforma tion is one step in the digita l filter design process for th e butter ,cheby1 , cheby2 , and ellip functions.

lp2bs can perform t he tra nsforma tion on t wo different l inear systemrepresenta tions: tra nsfer function form a nd sta te-space form. In both cases, theinput system must be an a na log fi l ter prototype.

Transfer Function Form (Polynomial)

Page 562: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 562/798

7-279

[bt,at] = lp2bs(b,a,Wo,Bw) tra nsforms a n a na log lowpa ss fi lter prototypegiven by polynomial coefficients int o a ba ndst op filter w ith cent er frequency Wo and bandwid th Bw. Row vectors b a nd a specify t he coefficients of the n umera tora nd d enomina tor of the prototype in descending powers of s .

Scalars Wo a nd Bwspecify th e center frequency an d ba ndw idth in units ofra dia ns/second. For a filter w ith lower ba nd edge w1 a nd upper ban d edge w2,use Wo = sqrt(w1*w2) a nd Bw= w2-w1 .

lp2bs returns the frequency transformed filter in row vectors bt a nd at .

Sta te-Spa ce Form

[At,Bt,Ct,Dt] = lp2bs(A,B,C,D,Wo,Bw) converts th e cont inuous-timesta te-space low pas s filter prototype in mat rices A , B, C, D shown below

b s ( )a s ( )---------- b 1( ) s n L b n ( ) s b n 1+( )+ + +

a 1( ) s m L a m ( ) s a m 1+( )+ + +---------------------------------------------------------------------------------=

x · A x B u +=

y C x D u +=

lp2bs

into a bandst op fi l ter with center frequency Wo and bandwid th Bw. For a filterwit h lower ban d edge w1 an d upper ban d edge w2, use Wo = sqrt(w1*w2) a ndBw= w2-w1 .

The ban dst op filter is return ed in ma tr ices At , Bt , Ct , Dt .

Algorithm lp2bs is a highly accurate state-space formulation of the classic analog filterfrequency tra nsforma tion. If a bandst op fi l ter is to ha ve center frequency ω0 and bandwid th B w, the s ta ndard s -doma in t ra nsforma tion is

where Q = ω0/B w a nd p = s /ω0. The sta te-space version of this t ra nsforma tion is

Q = Wo/Bw;At = [Wo/Q*inv(A) Wo*eye(ma); Wo*eye(ma) zeros(ma)];

s p

Q p 2 1+( )------------------------=

Page 563: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 563/798

7-280

At = [Wo/Q*inv(A) Wo*eye(ma);-Wo*eye(ma) zeros(ma)];Bt = -[Wo/Q*(A B); zeros(ma,n)];Ct = [C/A zeros(mc,ma)];Dt = D - C/A*B;

S ee lp2bp for a derivat ion of the ban dpass version of this t ra nsforma tion.

See Also bilinear , impinvar , lp2bp , lp2hp , lp2lp

lp2hp

7lp2hpPurpose Tra nsform lowpass a na log fi l ters to highpass

Syntax [bt,at] = lp2hp(b,a,Wo)[At,Bt,Ct,Dt] = lp2hp(A,B,C,D,Wo)

Description lp2hp tra nsforms a na log lowpass fi l ter prototypes with a cutoff frequency of1 ra d/s into highpa ss filters w ith desired cutoff frequency. The tra nsforma tionis one step in t he digita l filter d esign process for the butter , cheby1 , cheby2 ,a nd ellip functions.

The lp2hp function can perform t he tr an sforma tion on t wo different l inearsystem representa tions: tra nsfer function form a nd sta te-space form. In bothcases, the input system must be an a na log fi lter prototype.

Transfer Function Form (Polynomial)

Page 564: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 564/798

7-281

[bt,at] = lp2hp(b,a,Wo) tra nsforms a n a na log lowpa ss fil ter prototypegiven by polynomial coefficients int o a h ighpa ss filter w ith cutoff frequency Wo .Row vectors b a nd a specify the coefficients of the nu mera tor a nd denomina torof the prototype in d escending powers of s .

Scalar Wo specifies t he cut off frequency in u nit s of ra dia ns/second . Thefrequency tra nsformed filter is return ed in row vectors bt a nd at .

Sta te-Spa ce Form

[At,Bt,Ct,Dt] = lp2hp(A,B,C,D,Wo) converts th e cont inuous-timesta te-space low pas s filter prototype in mat rices A , B, C, D below

into a highpass fi l ter w ith cutoff frequency Wo . The highpa ss filter is retur nedin ma trices At , Bt , Ct , Dt .

b s ( )a s ( )---------- b 1( ) s n L b n ( ) s b n 1+( )+ + +

a 1( ) s m L a m ( ) s a m 1+( )+ + +---------------------------------------------------------------------------------=

x · A x B u +=

y C x D u +=

lp2hp

Algorithm lp2hp is a highly accurate state-space formulation of the classic analog filterfrequency tra nsforma tion. If a h ighpa ss filter is to ha ve cutoff frequency ω0, thes tandard s -doma in t ra nsforma tion is

The sta te-spa ce version of this t ra nsforma tion is

At = Wo*inv(A);Bt = -Wo*(A\B);Ct = C/A;Dt = D - C/A*B;

S ee lp2bp for a derivat ion of the ban dpass version of this t ra nsforma tion.

See Also bilinear impinvar lp2bp lp2bs lp2lp

s ω0p

-------=

Page 565: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 565/798

7-282

See Also bilinear , impinvar , lp2bp , lp2bs , lp2lp

lp2lp

7lp2lpPurpose Ch a nge the cut-off frequency for a lowpa ss a na log filter

Syntax [bt,at] = lp2lp(b,a,Wo)[At,Bt,Ct,Dt] = lp2lp(A,B,C,D,Wo)

Description lp2lp tra nsforms a n a na log lowpa ss fi lter prototype with a cutoff frequency of1 ra d/s int o a lowpa ss filter w ith a ny specified cutoff frequency. Thetr a nsforma tion is one step in the digita l filter design process for th e butter ,cheby1 , cheby2 , and ellip functions.

The lp2lp function can perform t he tr an sforma tion on t wo different l inearsystem representa tions: tra nsfer function form a nd sta te-space form. In both

cases, the input system must be an a na log fi lter prototype.

Transfer Function Form (Polynomial)

Page 566: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 566/798

7-283

[bt,at] = lp2lp(b,a,Wo) tra nsforms a n a na log lowpa ss fil ter prototypegiven by polynomial coefficients into a low pas s filter w ith cutoff frequency Wo .Row vectors b a nd a specify the coefficients of the nu mera tor a nd denomina torof the prototype in d escending powers of s .

Scalar Wo specifies th e cut off frequ ency in unit s of ra dia ns/second . lp2lp returns the frequency transformed filter in row vectors bt a nd at .

Sta te-Spa ce Form

[At,Bt,Ct,Dt] = lp2lp(A,B,C,D,Wo) converts th e cont inuous-timesta te-space low pas s filter prototype in mat rices A , B, C, D below

int o a lowpa ss filter w ith cutoff frequency Wo . lp2lp returns t he lowpa ss fi lterin ma trices At , Bt , Ct , Dt .

b s ( )a s ( )---------- b 1( ) s n L b n ( ) s b n 1+( )+ + +

a 1( ) s m L a m ( ) s a m 1+( )+ + +---------------------------------------------------------------------------------=

x · A x B u +=

y C x D u +=

lp2lp

Algorithm lp2lp is a highly accurate state-space formulation of the classic analog filterfrequency tra nsforma tion. If a lowpa ss filter is to ha ve cut off frequency ω0, thes tandard s -doma in t ra nsforma tion is

The sta te-spa ce version of this t ra nsforma tion is

At = Wo*A;Bt = Wo*B;Ct = C;Dt = D;

S ee lp2bp for a derivat ion of the ban dpass version of this t ra nsforma tion.

See Also bilinear , impinvar , lp2bp , lp2bs , lp2hp

s p ω0 ⁄ =

Page 567: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 567/798

7-284

lpc

7lpcPurpose Compute linear prediction filter coefficients

Syntax [a,g] = lpc(x,p)

Description lpc determines t he coefficients of a forw a rd linea r predictor by minimizing t heprediction error in th e least squa res sense. It h a s a pplicat ions in filter designa nd speech coding.

[a,g] = lpc(x,p) finds th e coefficient s of a p th -order linear predictor (FIRfilter) th a t predicts th e current va lue of the rea l-va lued time series x ba sed onpast sa mples.

p is th e order of the prediction filter polynomial, a = [1 a(2) ... a(p+1)] . I fp is uns pecified, lpc uses a s a default p = length(x)-1 . I f x i s a ma tr ix

x ˆ n ( ) a – 2( ) x n 1–( ) a – 3( ) x n 2–( ) L– a p 1+( ) x n p –( )–=

Page 568: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 568/798

7-285

conta ining a separa te signal in each column, lpc returns a model estimat e foreach column in t he rows of mat rix a a nd a row vector of prediction errorvariances g .

Examples Est imat e a da ta series using a third-order forw ar d predictor, and compare tothe origina l signal.

First , crea te th e signa l dat a a s th e output of a n a utoregressive process drivenby w hite n oise. Use t he la st 4096 sa mples of th e AR process output to a voidstart-up transients.

randn('state',0);noise = randn(50000,1); % Normalized white Gaussian noise

x = filter(1,[1 1/2 1/3 1/4],noise);x = x(45904:50000);

Compute t he predictor coefficient s, estima ted signa l, prediction error, an da ut ocorrelat ion sequ ence of th e prediction error.

a = lpc(x,3);

est_x = filter([0 -a(2:end)],1,x); % Estimated signal

e = x - est_x; % Prediction error[acs,lags] = xcorr(e,'coeff'); % ACS of prediction error

lpc

The pred iction err or, e (n ), can be view ed a s t he output of the prediction errorfilter A (z ) shown below , wh ere H (z ) is th e optima l linear predictor, x (n ) is th einput signal, a nd is the predicted signal.

Compare th e predicted signa l to th e original signa l.

plot(1:97,x(4001:4097),1:97,est_x(4001:4097),'--');title('Original Signal vs. LPC Estimate');

x ˆ n ( )

H z ( ) a – 2( )z 1–

a – 3( )z 2– L– a – n 1+( )z

p –= Σ

x ˆ n ( )x n ( ) –

+e n ( )

Prediction Error

A z ( )

Page 569: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 569/798

7-286

xlabel('Sample Number'); ylabel('Amplitude'); grid;legend('Original Signal','LPC Estimate')

Look a t t he a utocorrela tion of the prediction error.

plot(lags,acs);title('Autocorrelation of the Prediction Error');xlabel('Lags'); ylabel('Normalized Value'); grid;

0 10 20 30 40 50 60 70 80 90 100−3

−2

−1

0

1

2

3

4

5Original Signal vs. LPC Estimate

Sample Number

A m p

l i t u d e

Original SignalLPC Estimate

lpc

The prediction error is approximat ely wh ite G a ussia n noise, as expected for athird-order AR input process.

−0.2

0

0.2

0.4

0.6

0.8

1

1.2Autocorrelation of the Prediction Error

N o r m a

l i z e d V a

l u e

Page 570: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 570/798

7-287

Algorithm lpc uses t he a utocorrela tion met hod of au toregressive (AR) modeling to findth e filter coefficients. The genera ted filter might not m odel th e process exactlyeven if t he da ta sequence is t ruly a n AR process of the correct order. This isbeca use the a utocorrelation method implicit ly windows t he da ta , tha t is , ita ssumes tha t signa l samples beyond the length of x ar e 0.

lpc computes the least squa res solution t o

where

−5000 −4000 −3000 −2000 −1000 0 1000 2000 3000 4000 50000.2

Lags

X a b ≈

X

x 1( ) 0 L 0x 2( ) x 1( ) O M

M x 2( ) O 0x m ( ) M O x 1( )

0 x m ( ) O x 2( )M O O M

0 L 0 x m ( )

= a

1a 2( )

M

a p 1+( )

= b

10M

0

=, ,

lpc

a nd m is the length of x . Solving the least squa res problem via the norma lequations

leads to t he Yule-Wa lker equ a tions

where r = [ r (1) r (2) ... r (p+ 1)] is a n a utocorrelation estimat e for x computedusing xcorr . The Yule-Wa lker equa tions a re solved in O (p 2) flops by th eLevinson-Dur bin a lgorith m (see levinson ).

S Al

X H X a X H b =

r 1( ) r 2( ) * L r p ( ) *r 2( ) r 1( ) O M

M O O r 2( ) *r p ( ) L r 2( ) r 1( )

a 2( )a 3( )

M

a p 1+( )

r 2( )–

r 3( )–M

r p 1+( )–

=

Page 571: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 571/798

7-288

See Also aryule , levinson , prony , pyulear , stmcb

References [1] J a ckson, L.B ., Di gi ta l Fi l ters and Signal Processin g , Second E dition,Klu w er Acad emic Pu blishers, 1989. pp. 255-257.

lsf2poly

7lsf2polyPurpose Convert line spectr a l frequencies t o prediction filter coefficient s

Syntax a = lsf2poly(lsf)

Description a = lsf2poly(lsf) returns a vector a cont a ining th e prediction filtercoefficient s from a vector lsf of line spectr a l frequencies (a lso know n a s linespectr um pa irs).

Examples lsf = [0.7842 1.5605 1.8776 1.8984 2.3593];a = lsf2poly(lsf)

a =

1.0000 0.6148 0.9899 0.0001 0.0031 -0.0081

See Also ac2poly , poly2lsf , rc2poly

R f

Page 572: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 572/798

7-289

References [1] Deller, J .R., J .G. P roakis, a nd J .H.L. Ha nsen, “ D i scr ete-Ti m e Pr ocessi ng of Speech Si gnal s ,” P rent ice-H a ll, 1993.

[2] Ra biner, L.R., a nd R.W. Scha fer, “ D i git al P r ocessi ng of Speech Si gnal s ,”

Prentice-Hall, 1978.

maxflat

7maxflatPurpose G enera lized digita l But terworth fi l ter design

Syntax [b,a,] = maxflat(n,m,Wn)b = maxflat(n,' sym ',Wn)[b,a,b1,b2] = maxflat(n,m,Wn)[...] = maxflat(n,m,Wn,' design_flag ')

Description [b,a,] = maxflat(n,m,Wn) is a lowpass B utt erworth fil ter with numerat ora nd denomina tor coefficients b a nd a of order s n a nd m respectively. Wn i s thenorma lized cutoff frequency at wh ich th e magn itude response of the filter isequa l to (a pprox. -3 dB ). Wn must be betw een 0 a nd 1, wh ere 1 correspondsto th e Nyquist frequency.

b = maxflat(n,' sym ',Wn) is a symmetric FIR B utt erworth fi lter. n must beeven, a nd Wn is restr icted to a subint erval of [0,1]. The function ra ises a n errorif Wn is specified outside of th is subint erva l.

1 2 ⁄

Page 573: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 573/798

7-290

[b,a,b1,b2] = maxflat(n,m,Wn) returns tw o polynomials b1 a nd b2 whoseproduct is equal to the numerator polynomial b (tha t is , b = conv(b1,b2) ).b1 conta ins all th e zeros at z = -1 , and b2 cont a ins a ll the oth er zeros.

[...] = maxflat(n,m,Wn,' design_flag ') ena bles you t o monitor t he filterdesign, w here ' design_flag ' is :

• 'trace' , for a textua l display of the design ta ble used in the design• 'plots' , for plots of th e filter ’s magn itude, group dela y, a nd zeros a nd poles• 'both' , for both the t extua l display a nd plots

Examples n = 10; na = 2; Wn = 0.2;[b,a,b1,b2] = maxflat(n,m,Wn,'plots')

maxflat

0 0.2 0.4 0.6 0.8 1

0

0.5

1

ω / π

M a g n

i t u d e

Frequency response

−0.5

0

0.5

1

I m a g

i n a r y

Pole−zero plot

<− deg 10

5

6

7

8

S a m p

l e s

Group delay

Page 574: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 574/798

7-291

Algorithm The met hod consist s of th e use of formula e, polynomial r oot finding, a nd atransformation of polynomial roots.

See Also butter , filter , freqz

References [1] Selesnick, I.W., and C.S. Burrus, “Generalized Digital Butterworth Filter

Design,” Pr oceedi ngs of t he IE EE I nt . Conf. Acoust., Speech, Sign al Pr ocessi ng ,Vol. 3 (Ma y 1996).

−1 0 1

−1

Real0 0.5 1

4

5

ω / π

medfilt1

7medfilt1Purpose One-dimensional m edian filtering

Syntax y = medfilt1(x,n)y = medfilt1(x,n,blksz)y = medfilt1(x,n,blksz,dim)

Description y = medfilt1(x,n) a pplies an order n one-dimensional m edian filter tovector x ; th e function considers t he signa l to be 0 beyond t he end point s.Output y has t he same length a s x .

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 t his ca se, medfilt1 sorts t he numbers, then t a kes the a vera ge of the(n-1)/2 a nd ((n-1)/2)+1 elements.

The defa ult for n is 3.

Page 575: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 575/798

7-292

y = medfilt1(x,n,blksz) uses a for -loop to comput e blksz (block siz e)output sa mples at a t ime. Use blksz << length(x) if you are low on memory,since medfilt1 uses a working mat rix of size n-by-blksz . By defaul t ,

blksz = length(x) ; th is provides th e fast est execut ion if you ha ve sufficientmemory.

I f x i s a mat r ix, medfilt1 median filters its columns using

y(:,i) = medfilt1(x(:,i),n,blksz)

in a loop over t he column s of x .

y = medfilt1(x,n,blksz,dim) specifies the dimension, dim , along which th efilter operat es.

See Also filter , medfilt2 , median

References [1] P ra tt , W.K., Di gital I m age Processin g , J ohn Wiley & S ons, 1978,pp. 330-333.

modulate

7modulatePurpose Modulat ion for communicat ions simula tion

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 ') a nd

y = modulate(x,fc,fs,' method ',opt) modula te the real message signal x wit h a carrier frequency fc a nd sa mpling frequency fs , using one of the optionslisted below for ' method ' . Note th a t some methods accept a n option, opt .

amdsb-scor

am

Amplitude modulation, double sideband, suppressed carrier. Multiplies x by a sinusoid of frequency fc .

y = x.*cos(2*pi*fc*t)

amdsb-tc Amplitude modulation, double sideband, transmitted carrier.

Page 576: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 576/798

7-293

Subtracts scala r opt from x an d multiplies the result by a sinusoidof frequency fc .

y = (x-opt).*cos(2*pi*fc*t)

I f the opt para meter is not present, modulate uses a default ofmin(min(x)) so tha t th e message signa l (x-opt) is entirelynonnega tive and ha s a minimum value of 0.

amssb Amplitude modulation, single sideband. Multiplies x by asinu soid of frequen cy fc an d a dds the result t o the Hilbert t ra nsformof x multiplied by a pha se shifted sinusoid of frequency fc .

y =x.*cos(2*pi*fc*t)+imag(hilbert(x)).*sin(2*pi*fc*t)

This effectively removes the upper sideband.

modulate

fm Frequency modulation. Creates a sinusoid with instantaneousfrequency tha t va ries with t he message signa l x .

y = cos(2*pi*fc*t + opt*cumsum(x))

cumsum is a rectan gular a pproximation to the integral of x .modulate uses opt a s th e consta nt of frequency modulation. If opt is not present, modulate uses a default of

opt = (fc/fs)*2*pi/(max(max(x)))

so the ma ximum frequency excursion from fc is fc H z.

pm Phase modulation. Crea tes a s inusoid of frequency fc whosephase varies with t he message signal x .

y = cos(2*pi*fc*t + opt*x)

modulate uses opt a s the consta nt of phase modula tion. If opt isnot present, modulate uses a default of

opt = pi/(max(max(x)))

Page 577: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 577/798

7-294

so the ma ximum pha se excursion is π radians .

pwm Pulse-width modulation. Creat es a pulse-widt h modulat ed

signal from the pulse widths in x . The element s of x must bebetw een 0 a nd 1, specifying t he w idth of ea ch pulse in fra ctions ofa period. The pulses sta rt a t t he beginning of each period, th a t is,th ey are left just ified.

modulate(x,fc,fs,'pwm','centered')

yields pulses centered a t t he beginning of ea ch period. y is lengt h length(x)*fs/fc .

ppm Pulse-position modulation. Crea tes a pulse-position modulat edsigna l from th e pulse positions in x . The element s of x must bebetw een 0 and 1, specifying t he left edge of each pulse in fra ctionsof a period. opt is a scala r between 0 and 1 th a t specifies thelength of ea ch pulse in fra ctions of a period. The defa ult for opt is0.1 . y is lengt h length(x)*fs/fc .

qam Quadrature amplitude modulation. Crea tes a qua dra tu rea mplitude modulated signa l from signa ls x a nd opt .

y = x.*cos(2*pi*fc*t) + opt.*sin(2*pi*fc*t)

opt must be the sa me size as x .

modulate

If y ou do not specify ' method ' , then modulate assumes am. Except for th e pwm a nd ptm cases, y is the sa me size as x .

I f x i s an a r ray, modulate modulates its columns.

[y,t] = modulate(x,fc,fs) returns t he interna l t ime vector t t h a t modulate uses in its computations.

See Also demod , vco

Page 578: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 578/798

7-295

nuttallwin

7nuttal lwinPurpose Compute a minimum 4-term B lackman-Ha rris window, a s defined by Nutta ll

Syntax w = nuttallwin(n)

Description w = nuttallwin(n) returns a minimum, n-point, 4-term B lackma n-ha rrisw indow in t he column vector w. The window is minimum in the sense tha t i tsma ximum sidelobes a re minimized. The coefficients for t his w indow d iffer fromth e B la ckma n-ha rris win dow coefficients computed w ith blackmanharris a ndproduce slightly lower sidelobes.

Example Compar e 64-point B lackman-Ha rris a nd Nut ta l l’s B lackman-Ha rris w indowsand plot the difference between the windows.

N = 64;w = blackmanharris(N);y = nuttallwin(N);plot(1:N,w,1:N,y,'r--');axis([1 N 0 1]);titl ('C i f 64 t i d ')

Page 579: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 579/798

7-296

title('Comparison of 64-pt windows');legend('Blackman-harris', 'Nuttall');plot(y-w);

title('Difference between Blackman-harris and Nuttall windows')

10 20 30 40 50 60

0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1Comparison of 64−pt windows

Blackman−harrisNuttall

nuttallwin

Th i d iff i ( b ( )) i 0 0099

0 10 20 30 40 50 60 700

0.001

0.002

0.003

0.004

0.005

0.006

0.007

0.008

0.009

0.01Difference between Blackman−harris and Nuttall windows

Page 580: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 580/798

7-297

The m a ximum d ifference, using max(abs(y-w)) , is 0.0099 .

Algorithm The equation for computing the coefficients of a minimum 4-term

B lackman-ha rris window, a ccording to Nutt a ll , is

where .

The coefficients for t his w indow a re

See Also blackmanharris , barthannwin , bartlett , blackman , bohmanwin , chebwin ,gausswin , hann , hamming , kaiser , rectwin , triang , tukeywin , window

a 0 = 0.3635819a 1 = 0.4891775

a 2 = 0.1365995

a 3 = 0.0106411

w k 1+[ ] a 0 a 1 2 π k n 1–------------ -

a 2 4π k n 1–------------ -

cos a 3 6π k n 1–------------ -

cos–+cos–=

0 k n 1–( )≤ ≤

nuttallwin

References [1] Nut ta ll, Albert H. “Some Windows wit h Very G ood S idelobe B eha voir.”I EE E T r an sacti ons on Acousti cs, Speech, an d Si gnal Pr ocessi ng. Vol. ASS P -29(February 1981). pp. 84-91.

Page 581: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 581/798

7-298

Page 582: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 582/798

pburg

[Pxx,w] = pburg(x,p,nfft) uses the B urg method to estimat e the PSD wh ilespecifying th e lengt h of the FFT w ith t he integer nfft . If y ou specify nfft a sth e empty vector [] , it ta kes the default va lue of 256.

The lengt h of Pxx a nd t he frequency ran ge for wdepend on nfft and the valuesof the input x . The follow ing t a ble indica tes t he length of Pxx a nd t he frequencyrange for w in th is syntax.

[Pxx f] = pburg(x p nfft fs) uses the sampling frequency fs specified as

Table 7-10: PSD and Frequency Vector Characteristics

Real/ ComplexInput Data

nfft Even/ Odd Length of Pxx Range of w

Rea l-va lued E ven (nfft/2 + 1) [0, π]

Rea l-va lued Odd (nfft + 1)/2 [0, π)

C om plex-va lued E ven or odd nfft [0, 2 π)

Page 583: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 583/798

7-300

[Pxx,f] = pburg(x,p,nfft,fs) uses the sampling frequency fs specified asa n int eger in hert z (Hz) to compute the P SD vector ( Pxx ) a nd t he correspondingvector of frequen cies ( f ). In t his case, th e units for the frequency vector a re

in Hz. The spectral density produced is ca lculat ed in units of power per Hz. Ifyou s pecify fs a s the empty vector [] , the sampling frequency defa ults to 1 Hz.

The frequency range for f depends on nfft , fs , an d th e values of the input x .The lengt h of Pxx is the sa me as in t he ta ble a bove. The follow ing ta bleindicates the frequency range for f for this synt a x.

Table 7-11: PSD and Frequency Vector Characteristics with fs Specified

Real/ Complex Input Data nfft Even/ Odd Range of f

Rea l-va lued E ven [0,fs/2]

Rea l-va lued Odd [0,fs/2)

Complex-va lued E ven or odd [0,fs)

pburg

[Pxx,f] = pburg(x,p,nfft,fs,' range ') or

[Pxx,w] = pburg(x,p,nfft,' range ') specifies t he ra nge of frequency valuest o include in f or w. This synt a x is useful wh en x is real . ' range ' can be eith er:

• 'twosided' : Compute the tw o-sided PS D over th e frequency ra nge [0,fs) .This is t he defau lt for determ ining t he frequency ra nge for complex-va luedx.- If y ou specify fs a s t he empty vector, [] , the frequency ran ge is [0,1) .- If y ou don’t specify fs , the frequency ran ge is [0, 2 π).

• 'onesided' : Compute t he one-sided P SD over th e frequency ra nges specifiedfor rea l x . This is the defa ult for determining t he frequency ra nge for

real-valued x .

Note You can put the str ing ar gument ' range ' a nyw here in the inputargument l i s t a f ter p.

Page 584: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 584/798

7-301

pburg(...) wit h n o outputs plots the power spectral density in t he current

figure window . The frequency ran ge on th e plot is th e same a s the ra nge ofoutput w (or f ) for a given set of para meters.

Remarks The pow er spectr a l density is computed a s th e distribut ion of pow er per unitfrequency.

This a lgorith m depends on your selecting a n a ppropriat e model order for yoursignal.

Examples B eca use the Burg meth od estimat es the spectral density by fi t t ing a n ARprediction model of a given order t o th e signal, first genera te a signa l from a nAR (a ll-pole) model of a given ord er. You ca n u se freqz to check the ma gnitudeof the frequency response of your AR filter. This w ill give you an idea of w ha tto expect when you estimat e the P SD using pburg .

a = [1 -2.2137 2.9403 -2.1697 0.9606]; % AR filter coefficientsfreqz(1,a) % AR filter frequency responsetitle('AR System Frequency Response')

pburg

Now generat e the input signa l x by filtering wh ite noise th rough th e AR filter.Est imat e the P SD of x bas ed on a fourt h-order AR prediction model since in t his

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−200

−150

−100

−50

0

50

100

Normalized Frequency ( ×πrad/sample)

P h a s e

( d e g r e e s

)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−20

−10

0

10

20

30

40

Normalized Frequency ( ×πrad/sample)

M a g n

i t u d e

( d B )

AR System Frequency Response

Page 585: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 585/798

7-302

pcase we know t ha t the origina l AR system model a has o rder 4.

randn('state',1);x = filter(1,a,randn(256,1)); % AR system outputpburg(x,4) % Fourth-order estimate

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−30

−20

−10

0

10

20

30

Normalized Frequency ( ×πrad/sample)

P o w e r

S p e c

t r a l D e n s

i t y ( d B / r a

d / s a m

p l e )

Burg PSD Estimate

pburg

Algorithm Linea r prediction filters can be used to model the second-order sta tist ica lchar a cteristics of a signa l. The prediction filter output ca n be used to model th esignal w hen the input is w hite noise.

The B urg m ethod fits a n AR linear prediction filter model of th e specified orderto th e input signal by minimizing (using lea st sq ua res) the a ri thmetic mean ofthe forwa rd a nd ba ckwa rd prediction errors. The spectral density is thencomputed from the frequency response of the prediction filter. The AR filterparameters are constrained to satisfy the Levinson-Durbin recursion.

See Also arburg , lpc , pcov , peig , periodogram , pmcov , pmtm, pmusic , pwelch , psdplot ,pyulear

References [1] Ma rple, S.L . Di gi ta l Spectr a l An alysis , Englew ood Cliffs, NJ , Pr entice-Ha ll,1987, Chapt er 7.

[2] St oica, P ., a nd R .L. Moses, In t r oduct ion to Spectr a l Anal ysis , Pr entice-Ha ll,1997.

Page 586: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 586/798

7-303

pcov

7pcovPurpose Est imat e the power spectra l density using th e covaria nce method

Syntax Pxx = pcov(x,p)[Pxx,w] = pcov(x,p)

[Pxx,w] = pcov(x,p,nfft)[Pxx,f] = pcov(x,p,nfft,fs)[Pxx,f] = pcov(x,p,nfft,fs,' range ')[Pxx,w] = pcov(x,p,nfft,' range ')pcov(...)

Description Pxx = pcov(x,p) implements the covaria nce algorithm, a para metric spectra lestimat ion method, a nd returns Pxx , an estimat e of the power spectral density(PSD) of the vector x . The en tr ies of x represent sa mples of a discrete-timesignal , a nd w here p is th e integer specifying t he order of a n a utoregressive (AR)prediction m odel for t he signal, used in estima ting t he P SD .

The power spectra l density is calculat ed in units of power per ra dia ns persa mple. Real-va lued input s produce full pow er one-sided (in frequ ency) P SD s

Page 587: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 587/798

7-304

(by defa ult), wh ile complex-va lued input s produce tw o-sided P SD s.

In genera l , the length of the FF T a nd t he values of the input x determine thelength of Pxx a nd t he ra nge of th e corresponding norma lized frequencies. Forth is synt a x, the (default ) FF T length is 256. The follow ing t a ble indicat es thelength of Pxx a nd t he ra nge of the corresponding norma lized frequencies forth is syntax.

[Pxx,w] = pcov(x,p) a lso returns w, a vector of frequencies at wh ich t he P SDis estima ted. Pxx a nd w ha ve the sam e length . The units for frequency are

ra d/sa mple.

Table 7-12: PSD Vector Characteristics for an FFT Length of 256 (Default)

Real/ ComplexInput Data

Length of Pxx Range of the CorrespondingNormalized Frequencies

Rea l-va lued 129 [0, π]

Complex-va lued 256 [0, 2 π)

pcov

[Pxx,w] = pcov(x,p,nfft) uses the covaria nce method to estima te the P SDw hile specifying th e lengt h of the FFT w ith t he integer nfft . If y ou specify nfft a s th e empty vector [] , it ta kes the default va lue of 256.

The lengt h of Pxx an d th e frequency ra nge for w depend on nfft and the valuesof the input x . The follow ing t a ble indica tes t he length of Pxx a nd t he frequencyra nge for w in th is syntax.

[Pxx,f] = pcov(x,p,nfft,fs) uses the sa mpling frequency fs specified a s a nh ( ) h ( ) d h d

Table 7-13: PSD and Frequency Vector Characteristics

Real/ ComplexInput Data

nfft Even/ Odd Length of Pxx Range of w

Rea l-va lued E ven (nfft/2 + 1) [0, π]

Rea l-va lued Odd (nfft + 1)/2 [0, π)

C om plex-va lued E ven or od d nfft [0, 2 π)

Page 588: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 588/798

7-305

int eger in hertz (Hz) to comput e the P SD vector ( Pxx ) a nd t he correspondingvector of frequencies ( f ). In t his case, the unit s for t he frequency vector are

in Hz. The spectral density produced is ca lculat ed in units of power per Hz. Ifyou s pecify fs a s the empty vector [] , the sampling frequency defaults to 1 Hz.

The frequency r a nge for f depends on nfft , fs , an d th e values of the input x .The leng th of Pxx is the sa me as in t he ta ble a bove. The follow ing ta bleindicates the frequency range for f for this synt a x.

Table 7-14: PSD and Frequency Vector Characteristics with fs Specified

Real/ Complex Input Data nfft Even/ Odd Range of f

Rea l-va lued E ven [0,fs/2]

Rea l-va lued Odd [0,fs/2)

Complex-va lued E ven or odd [0,fs)

pcov

[Pxx,f] = pcov(x,p,nfft,fs,' range ') or

[Pxx,w] = pcov(x,p,nfft,' range ') specifies t he ra nge of frequency valuest o include in f or w. This synt a x is useful w hen x is real. ' range ' can be either:

• 'twosided' : Compute the tw o-sided PS D over th e frequency ra nge [0,fs) .This is the defa ult for determining t he frequency ra nge forcomplex-valued x.- If y ou specify fs a s t he empty vector, [] , the frequency ra nge is [0,1) .- If y ou don’t specify fs , the frequency ran ge is [0, 2 π).

• 'onesided' : Compute t he one-sided P SD over t he frequency ra nges specifiedfor rea l x . This is th e default for det ermining t he frequency ra nge for

real-valued x .

Note You can put the str ing ar gument ' range ' an ywh ere in the inputargument l i s t af ter p .

Page 589: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 589/798

7-306

pcov(...) wit h n o outputs plots the power spectra l density in t he current

figure window. The frequency ran ge on t he plot is the sam e as th e ran ge ofoutput w (or f ) for a given set of para meters.

Remarks The power spectra l density is comput ed a s th e distribut ion of pow er per unitfrequency.

This a lgorith m depends on your selecting a n a ppropriat e model order for yoursignal.

Examples B ecau se the covaria nce method estimat es the spectra l density by fi t t ing a n ARprediction model of a given order t o th e signal, first genera te a signa l from a nAR (all-pole) model of a given order . You can use freqz to check the magn itudeof the frequency response of your AR filter. This w ill give you a n idea of wha tto expect wh en you estimat e the P SD using pcov .

a = [1 -2.2137 2.9403 -2.1697 0.9606]; % AR filter coefficientsfreqz(1,a) % AR filter frequency responsetitle('AR System Frequency Response')

pcov

Now genera te the input signal x by filtering wh ite noise th rough th e AR filter.Est imat e the PSD of x ba sed on a fourth-order AR prediction model since in t hiscase we know t ha t t he original AR system model a ha s order 4

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−200

−150

−100

−50

0

50

100

Normalized Frequency ( ×πrad/sample)

P h a s e

( d e g r e e s

)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−20

−10

0

10

20

30

40

Normalized Frequency ( ×πrad/sample)

M a g n

i t u d e

( d B )

AR System Frequency Response

Page 590: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 590/798

7-307

case we know t ha t t he original AR system model a ha s order 4.

randn('state',1);x = filter(1,a,randn(256,1)); % Signal generated from AR filterpcov(x,4) % Fourth-order estimate

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−30

−20

−10

0

10

20

30

Normalized Frequency ( ×πrad/sample)

P o w e r

S p e c

t r a l D e n s i t y

( d B / r a

d / s a m p

l e )

Covariance PSD Estimate

pcov

Algorithm Linea r prediction filters ca n be used to model th e second-order sta tist ica lchar a cteristics of a signa l. The prediction filter output ca n be used to model th esignal w hen the input is w hite noise.

The covaria nce method estimat es the P SD of a signa l using the covaria ncemeth od. The cova ria nce (or nonwin dowed) meth od fits a n AR linear predictionfilter model to th e signal by minimizing t he forw a rd prediction error (ba sed oncausa l observat ions of your input signa l) in th e lea st sq ua res sense. Thespectral estima te returned by pcov is the squa red ma gnitude of the frequencyresponse of this AR model.

See Also arcov , lpc , pburg , peig , periodogram , pmcov , pmtm, pmusic , pwelch , psdplot ,pyulear

References [1] Ma rple, S.L . Di gi ta l Spectr a l An alysis , Englewood Cliffs, NJ , Pr entice-Ha ll,1987, Chapter 7.

[2] St oica, P ., an d R.L. Moses, In t r oduct ion to Spectr a l Anal ysis , Pr entice-Ha ll,1997.

Page 591: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 591/798

7-308

peig

7peigPurpose E stima te th e pseudospectr um using t he eigenvector method

Syntax [S,w] = peig(x,p)[S,w] = peig(...,nfft)

[S,f] = peig(x,p,nfft,fs)[S,f] = peig(...,' corr ')[S,f] = peig(x,p,nfft,fs,nwin,noverlap)[...] = peig(...,' range ')[...,v,e] = peig(...)peig(...)

Description [S,w] = peig(x,p) implement s th e eigenvector spectr a l estima tion methodan d returns S, the pseudospectrum estimate of the input signal x , and w, avector of norma lized fr equencies (in ra d/sa mple) a t w hich t he pseudospectrumis evalua ted. The pseudospectr um is calculat ed using estima tes of theeigenvectors of a correlation ma trix a ssociat ed with the input da ta x , where x is specified a s either:

• A row or column vector r epresent ing one observa tion of th e signa l

Page 592: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 592/798

7-309

A row or column vector r epresent ing one observa tion of th e signa l• A recta ngular a rra y for w hich each row of x represents a separa te

observat ion of the signa l (for exam ple, each row is one output of a n a rra y ofsensors, a s in a rra y processing), such tha t x'*x is an estima te of thecorrelation ma trix

Note You ca n use t he output of corrmtx to generate such a n a rray x .

You can specify th e second input a rgument p a s either:

• A scala r integer. In t his case, the signa l subspace dimension is p .• A tw o-element vector. I n t his ca se, p(2) , th e second element of p , represent s

a thr eshold tha t is multiplied by λmin , th e smallest est ima ted eigenva lue ofthe signal’s correlation matrix. Eigenvalues below the threshold λmin *p(2) a re assign ed to the noise subspa ce. In th is ca se, p(1) specifies t he ma ximumdimension of th e signa l subspace.

peig

The extr a t hreshold para meter in th e second ent ry in p provides you moreflexibility a nd cont rol in a ssigning t he noise and sign a l subspaces.

S a nd w ha ve the same length. In general , the length of the FFT a nd t he valuesof the input x determine t he length of the computed S and the ran ge of thecorresponding norma lized frequ encies. The following t a ble indica tes t he lengthof S (and w) a nd t he ra nge of th e corresponding n ormalized frequencies for t hissyntax.

[S,w] = peig(...,nfft) specifies th e lengt h of the FF T used to estima te t hepseudospectrum with the integer nfft . The defau lt va lue for nfft (entered a sa n empty vector [] ) is 256

Table 7-15: S Characteristics for an FFT Length of 256 (Default)

Real/ ComplexInput Data

Length of S and w Range of the CorrespondingNormalized Frequencies

Rea l-va lued 129 [0, π]

Complex-va lued 256 [0, 2 π)

Page 593: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 593/798

7-310

a n empty vector [] ) is 256.

The follow ing t a ble indicat es th e lengt h of S a nd w, and t he frequency rangefor w for this synta x.

[S,f] = peig(x,p,nfft,fs)) retur ns t he pseudospectr um in t he vector S evalua ted a t t he corresponding vector of frequencies f (in H z). You supply t hesampling frequency fs in H z. If y ou specify fs wit h t he empty vector [] , thesam pling frequency defaults to 1 Hz.

Table 7-16: S and Frequency Vector Characteristics

Real/ ComplexInput Data

nfft Even/ Odd Length of Sand w

Range of w

Rea l-va lued E ven (nfft/2 + 1) [0, π]

Rea l-va lued Odd (nfft + 1)/2 [0, π)

C om plex-va lued E ven or odd nfft [0, 2 π)

peig

The frequency range for f depends on nfft , fs , an d th e values of the input x .The leng th of S (and f ) is the sa me as in Ta ble 7-16 . The follow ing t a bleindicates the frequency range for f for this synt a x.

[S,f] = peig(...,' corr ') forces th e input a rgument x to be interpreted a s acorre la t ion ma tr ix ra ther th an mat r ix of s ignal da ta . For th is synta x x must bea squa re mat rix, and a ll of i ts eigenvalues must be nonnegat ive.

[S,f] = peig(x,p,nfft,fs,nwin,noverlap) allows you to specify nwin , ascalar integer indica ting a recta ngular window length, or a real-valued vectorspecifying w indow coefficient s Use t he scala r int eger noverlap in conjunction

Table 7-17: S and Frequency Vector Characteristics with fs SpecifiedReal/ Complex Input Data nfft Even/ Odd Range of f

Rea l-va lued E ven [0,fs/2]

Rea l-va lued Odd [0,fs/2)

Complex-va lued E ven or odd [0,fs)

Page 594: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 594/798

7-311

specifying w indow coefficient s. Use t he scala r int eger noverlap in conjunctionwi th nwin to specify th e number of input s a mple points by w hich successivewindows overla p. noverlap is not used if x is a m a tr ix. The default va lue fornwin is 2*p(1) a nd noverlap is nwin-1 .

With this synta x, the input dat a x is segmented a nd w indowed before th ema tr ix used to estima te th e correlat ion ma tr ix eigenvalues is formula ted. Thesegmenta tion of the da ta depends on nwin , noverlap , an d th e form of x .Comment s on t he resulting w indowed segments a re described in the follow ingtable.

Table 7-18: Windowed Data Depending on x and nwin

Input data x Form of nwin Windowed Data

D a t a vect or S ca la r Length is nwin

D a ta vect or Vect or of coefficien ts Length is length(nwin)

peig

S ee Ta ble 7-19 for relat ed informa tion on t his synta x.

Note The arguments nwin a nd noverlap a re ignored wh en you include th estring ' corr ' in the syntax.

[...] = peig(...,' range ') specifies t he ra nge of frequency va lues to includein f or w. This syn ta x is useful when x is real . ' range ' can be eith er:

• 'whole' : Compute th e pseudospectrum over the frequency ra nge [0,fs) .

Da t a ma t rix Sca la r Da t a is not w indow ed.

D a ta m a t rix Vect or of coefficien ts length(nwin) must be thesam e as t he column length of x ,a nd noverlap is not used.

Table 7-18: Window ed Data Depending on x and nwin (Continued)

Input data x Form of nwin Windowed Data

Page 595: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 595/798

7-312

whole : Co pute t e pseudospect u ove t e eque cy a ge [0,fs) .This is t he defa ult for d etermining th e frequency ra nge for complex-va lued x . - If y ou specify fs a s t he empty vector, [] , the frequency ra nge is [0,1) .- If y ou don’t specify fs , the frequency ran ge is [0, 2 π).

• 'half' : Compute t he pseudospectr um over th e frequency ra nges specifiedfor rea l x . This is th e default for det ermining t he frequency ra nge forreal-valued x .

Note You can put the str ing ar guments ' range ' or ' corr ' anyw here in theinput argument l ist after p.

[...,v,e] = peig(...) re turns the matr ix v of noise eigenvectors, a long w ithth e associa ted eigenvalues in t he vector e . The colum ns of v span t he noisesubspace of dimension size(v,2) . The dimension of the sign a l subspa ce issize(v,1)-size(v,2) . For this synta x, e is a vector of estima ted eigenvaluesof the correlation matrix.

peig

peig(...) wit h no output a rguments plots the pseudospectrum in t he currentfigure window.

Remarks In t he process of estima tin g th e pseudospectrum, peig comput es the noise and

signa l subspaces from the estima ted eigenvectors v j a nd eigenva lues λ j of th esigna l’s correla tion ma tr ix. The sma llest of these eigenva lues is used inconjunction wit h t he th reshold para meter p(2) to affect th e dimension of thenoise subspace in some cases.

The lengt h n of the eigenvectors comput ed by peig is th e sum of the dimensionsof the signa l a nd noise subspa ces. This eigenvector lengt h d epends on yourinput (signal da ta or correlat ion mat rix) an d th e synta x you use.

The following t a ble summa rizes th e dependency of th e eigenvector lengt h onthe input a rgument.

Table 7-19: Eigenvector Length Depending on Input Data and Syntax

Form of Input Data x Comments on the Syntax Length n of Eigenvectors

Page 596: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 596/798

7-313

You should specify nwin > p(1) or length(nwin) > p(1) i f you wa nt p(2) > 1 t oha ve any effect .

Row or column vector nwin is specified as a scala r

integer.

nwin

Row or column vector nwin is specified a s avector.

length(nwin)

Row or column vector nwin is not specified. 2*p(1)

l -by- m ma t rix I f nwin is specified a s ascala r, it is not used. If

nwin is specified a s avector, length(nwin) mustequal m .

m

m -by- m nonnegativedefinite mat rix

The string ' corr ' isspecified and nwin is notused.

m

peig

Examples Implement t he eigenvector met hod to find th e pseudospectrum of th e sum ofth ree sinusoids in n oise, using t he defau lt F FT length of 256. U se th e modifiedcovariance method for the correlation matrix estimate.

randn('state',1); n=0:99;s=exp(i*pi/2*n)+2*exp(i*pi/4*n)+exp(i*pi/3*n)+randn(1,100);X=corrmtx(s,12,'mod');peig(X,3,'whole') % Uses the default NFFT of 256.

−5

0

5

10

15

20

25

30

d B

Eigenvector Method Pseudospectrum

Page 597: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 597/798

7-314

Algorithm The eigenvector method estima tes t he pseudospectr um from a signa l or acorrelation ma trix using a weighted version of the MU SIC a lgorithm derivedfrom Schmidt’s eigenspace analysis method [1][2]. The algorithm performseigenspace analysis of the signal’s correlation matrix in order to estimate thesigna l’s frequency cont ent. The eigenvalues a nd eigenvectors of the signa l’scorrelat ion ma trix a re est ima ted using svd if you don’t supply the correlationma trix. This algorithm is part icularly suita ble for signa ls tha t a re the sum ofsinusoids with a ddit ive whit e Ga ussian noise.

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8−15

−10

Normalized Frequency ( ×πrad/sample)

peig

The eigenvector m ethod produces a pseudospectr um estima te g iven by

where N is th e dimension of the eigenvectors an d v k is the k th eigenvector ofth e correlat ion ma tr ix of the input signa l. The integer p is th e dimension of thesigna l subspace, so the eigenvectors v k used in th e sum correspond to thesma llest eigenva lues of th e correla tion ma tr ix. The eigenvectors used in th eP SD estima te spa n t he noise subspa ce. The vector e (f ) consists of complexexponentia ls, so the inner product

a mounts t o a Fourier t ra nsform. This is used for computa tion of th e P SDestimate. The FFT is computed for each v k and then the squared ma gni tudesa re summed a nd scaled.

See Also corrmtx pburg periodogram pmtm pmusic prony pwelch psdplot rooteig

P ev f ( ) 1

v k H

e f ( )2

N

λk ⁄

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

λk

v k H e f ( )

Page 598: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 598/798

7-315

See Also corrmtx , pburg , periodogram , pmtm, pmusic , prony , pwelch , psdplot , rooteig ,

rootmusic

References [1] Ma rple, S.L . Di gi ta l Spectr a l An alysis , Englew ood Cliffs, NJ , Pr entice-Ha ll,1987, pp. 373-378.

[2] Schmidt, R.O, “Multiple Emitter Loca tion a nd S ignal P a ra meterEstimation,” I EE E T ran s. Antennas Propagat ion, Vol. AP-34 (Ma rch 1986),pp. 276-280.

[3] St oica, P ., a nd R .L. Moses, In t r oduct ion to Spectr a l Anal ysis , Pr entice-Ha ll,1997.

periodogram

7periodogramPurpose Est imat e the power spectra l density (P SD ) of a signa l using a periodogra m

Syntax [Pxx,w] = periodogram(x)[Pxx,w] = periodogram(x,window)

[Pxx,w] = periodogram(x,window,nfft)[Pxx,f] = periodogram(x,window,nfft,fs)[Pxx,...] = periodogram(x,...,' range ')periodogram(...)

Description [Pxx,w] = periodogram(x) returns t he power spectra l density (PSD )est imate Pxx of the sequence x using a periodogra m. The power spectr a ldensity is ca lcula ted in un its of power per rad ia ns per sa mple. The

corr esponding vector of frequ encies w is computed in ra dians per sa mple, an dhas t he same length a s Pxx .

A rea l-va lued input vector x produces a fu ll pow er one-sided (in frequency) PS D(by default), while a complex-valued x produces a tw o-sided PS D.

In general , the length N of th e FFT a nd t he values of the input x determine thelength of Pxx a nd t he ra nge of th e corresponding norma lized frequencies. For

Page 599: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 599/798

7-316

this syn ta x, the (default) length N of the FF T is th e larg er of 256 a nd t he nextpower of two grea ter tha n th e length of x . The follow ing t a ble indicat es th elength of Pxx a nd t he ra nge of the corresponding norma lized frequencies forth is syntax.

[Pxx,w] = periodogram(x,window) re turns the P SD es t imate Pxx computedusing the modified periodogram method. The vector window specifies thecoefficients of the w indow u sed in computin g a modified periodogra m of theinput signa l. Both input a rguments must be vectors of the sa me length. Whenyou don’t supply t he second a rgument window , or set it t o the empty vector [] ,

Table 7-20: PSD Vector Characteristics for an FFT Length of N (Default)

Real/ ComplexInput Data

Length of Pxx Range of the CorrespondingNormalized Frequencies

Rea l-va lued ( N /2) + 1 [0, π]

Complex-valued N [0, 2 π)

periodogram

a recta ngular window (rectwin ) is used by defa ult . In t his ca se the sta nda rdperiodogram is calcula ted.

[Pxx,w] = periodogram(x,window,nfft) uses th e modified periodogra m t oestimat e the P SD wh ile specifying the length of the FFT wit h t he integer nfft .If you set nfft to th e empty vector [] , i t ta kes th e default value for N listed inthe previous synt a x.

The lengt h of Pxx an d th e frequency ra nge for w depend on nfft and the valuesof the input x . The follow ing t a ble indica tes t he length of Pxx a nd t he frequencyra nge for w for this synta x.

Table 7-21: PSD and Frequency Vector Characteristics

Real/ ComplexInput Data

nfft Even/ Odd Length of Pxx Range of w

Rea l-va lued E ven (nfft/2 + 1) [0, π]

Rea l-va lued Odd (nfft + 1)/2 [0, π)

C om plex-va lued E ven or od d nfft [0, 2 π)

Page 600: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 600/798

7-317

Note periodogram uses a n nfft -point F FT of th e wind owed da ta(x.*window ) to compute th e periodogram . If t he va lue you specify for nfft isless tha n th e length of x , then x.*window is w ra pped modulo nfft . If the valueyou specify for nfft is grea ter tha n the length of x , then x.*window iszero-pa dded t o comput e th e FF T.

[Pxx,f] = periodogram(x,window,nfft,fs) uses the sa mpling frequency fs specified a s a n int eger in hertz (Hz) to compute the P SD vector ( Pxx ) and thecorrespond ing vector of frequen cies ( f ). In t his case, th e units for th e frequencyvector a re in Hz. The spectr a l density produced is ca lcula ted in un its of powerper Hz. If you specify fs a s the empty vector [] , the sa mpling frequencydefaul ts to 1 Hz.

periodogram

The frequency range for f depends on nfft , fs , an d th e values of the input x .The lengt h of Pxx is the sa me as in t he ta ble a bove. The follow ing ta bleindicates the frequency range for f for this synt a x.

[Pxx,f] = periodogram(x,window,nfft,fs,' range ') or

[Pxx,w] = periodogram(x,window,nfft,' range ') specifies t he ra nge offrequency va lues to include in f or w. This synt a x is useful wh en x is real.' range ' can be eith er:

• 'twosided' : Compute the tw o-sided PS D over th e frequency ra nge [0,fs) .This is the defa ult for determining t he frequency ra nge for

Table 7-22: PSD and Frequency Vector Characteristics with fs SpecifiedReal/ Complex Input Data nfft Even/ Odd Range of f

Rea l-va lued E ven [0,fs/2]

Rea l-va lued Odd [0,fs/2)

Complex-va lued E ven or odd [0,fs)

Page 601: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 601/798

7-318

complex-valued x.- If y ou specify fs a s t he empty vector, [] , the frequency ra nge is [0,1) .- If y ou don’t specify fs , the frequency ran ge is [0, 2 π).

• 'onesided' : Compute t he one-sided P SD over t he frequency ra nges specifiedfor rea l x . This is th e default for det ermining t he frequency ra nge forreal-valued x .

Note You can put the str ing ar gument ' range ' an ywh ere in the inputargument l i s t af ter window .

periodogram(...) with no outputs plots the power spectral density in dB perunit frequency in the current figure window . The frequency ran ge on t he plotis the same a s the ra nge of output w (or f ) for t he synt a x you use.

periodogram

Examples Compute t he periodogra m of a 200 Hz signa l embedded in a ddit ive noise usingthe defa ult window.

randn('state',0);Fs = 1000;

t = 0:1/Fs:.3;x = cos(2*pi*t*200)+0.1*randn(size(t));periodogram(x,[],'twosided',512,Fs)

−50

−40

−30

−20

−10

P o w e r

S p e c

t r a l D e n s

i t y ( d B / H z

)

Periodogram PSD Estimate

Page 602: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 602/798

7-319

Algorithm The periodogram for a sequence [ x 1, ... , x n ] is given by t he follow ing formula .

This expression forms a n est ima te of the power spectrum of the signa l definedby th e sequence [ x 1, ... , x n ].

0 100 200 300 400 500 600 700 800 900−70

−60

Frequency (Hz)

S e

j ω

( )1n --- x l e

j ωl –

l 1=

n

∑=

periodogram

If you weight your signal sequence by a window [w 1, ... , w n ], then th e weightedor modified periodogra m is d efined a s

In either case, periodogram uses a n nfft -point F FT t o comput e th e pow er

spectral density as , wh ere F is :

• 2π w hen you do not su pply the sa mpling frequency• fs wh en you supply the sa mpling frequency

See Also pburg , pcov , peig , pmcov , pmtm, pmusic , pwelch , psdplot , pyulear

References [1] St oica, P ., an d R.L. Moses, In t r oduct ion to Spectr a l Anal ysis , Pr entice-Ha ll,

S e j ω( )

1n --- w

l x

l e

j ωl –

l 1=

n

2

1n --- w l

2

l 1=

n

∑---------------------------------------------=

S e j ω( ) F ⁄

Page 603: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 603/798

7-320

1997, pp. 24-26.[2] Welch, P .D, “The U se of Fa st Fourier Tra nsform for th e Est ima tion of P owerSpectr a : A Meth od Ba sed on Time Averag ing Over Sh ort, ModifiedPeriodograms,” I EE E Tr ans. Au di o El ectr oacousti cs , Vol. AU-15 (J un e 1967),pp. 70-73.

[3] Oppenheim, A.V., a nd R.W. S cha fer, D i scr ete-Ti m e Si gnal Pr ocessing ,P rent ice-H a ll, 1989, pp. 730-742.

pmcov

7pmcovPurpose Estimate the power spectral density using the modified covariance method

Syntax Pxx = pmcov(x,p)[Pxx,w] = pmcov(x,p)

[Pxx,w] = pmcov(x,p,nfft)[Pxx,f] = pmcov(x,p,nfft,fs)[Pxx,f] = pmcov(x,p,nfft,fs,' range ')[Pxx,w] = pmcov(x,p,nfft,' range ')pmcov(...)

Description Pxx = pmcov(x,p) implement s th e modified cova ria nce a lgorith m, apara metric spectral estima tion method, and retur ns Pxx , an estima te of the

pow er spectr a l density (P SD ) of the vector x . The ent ries of x represent sa mplesof a discrete-time signa l, an d p is the int eger specifying t he order of a na ut oregressive (AR) prediction model for t he signa l, used in estima ting th eP S D .

The pow er spectra l density is calculat ed in units of pow er per ra dia ns persa mple. Real-va lued input s produce full power one-sided (in frequ ency) P SD s(by defa ult), wh ile complex-va lued input s produce tw o-sided P SD s.

Page 604: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 604/798

7-321

In genera l , the length of the F FT an d t he values of the input x determine thelength of Pxx a nd t he ra nge of the corresponding norma lized frequencies. Forth is synt a x, the (defau lt) FFT length is 256. The follow ing t a ble indicat es thelength of Pxx a nd t he ra nge of the corresponding norma lized frequencies forth is syntax.

[Pxx,w] = pmcov(x,p) a lso returns w, a vector of frequencies a t w hich theP SD is es t imat ed. Pxx a nd w ha ve the sam e length . The units for frequency a rera d/sa mple.

Table 7-23: PSD Vector Characteristics for an FFT Length of 256 (Default)

Real/ ComplexInput Data Length of Pxx Range of the CorrespondingNormalized Frequencies

Rea l-va lued 129 [0, π]

Complex-va lued 256 [0, 2 π)

pmcov

[Pxx,w] = pmcov(x,p,nfft) uses the covaria nce method to estima te th e PS Dw hile specifying th e lengt h of the FFT wit h t he integer nfft . If y ou specify nfft a s the empty vector [] , it ta kes the default va lue of 256.

The lengt h of Pxx a nd t he frequency ran ge for wdepend on nfft and the values

of the input x . The follow ing t a ble indica tes t he length of Pxx a nd t he frequencyrange for w for this synta x.

[Pxx,f] = pmcov(x,p,nfft,fs) uses the sampling frequency fs specified asa n int eger in hert z (Hz) to compute the P SD vector ( Pxx ) a nd t he correspondingvector of frequen cies ( f ). In t his case, th e units for the frequency vector a re

Table 7-24: PSD and Frequency Vector Characteristics

Real/ ComplexInput Data

nfft Even/ Odd Length of Pxx Range of w

Rea l-va lued E ven (nfft/2 + 1) [0, π]

Rea l-va lued Odd (nfft + 1)/2 [0, π)

C om plex-va lued E ven or odd nfft [0, 2 π)

Page 605: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 605/798

7-322

in Hz. The spectral density produced is ca lculat ed in units of power per Hz. Ifyou s pecify fs a s the empty vector [] , the sampling frequency defa ults to 1 Hz.

The frequency range for f depends on nfft , fs , an d th e values of the input x .The lengt h of Pxx is the same as in Ta ble 7-24 . The follow ing t a ble indicat es thefrequency ra nge for f in th is syntax.

Table 7-25: PSD and Frequency Vector Characteristics with fs Specified

Real/ Complex Input Data nfft Even/ Odd Range of f Rea l-va lued E ven [0,fs/2]

Rea l-va lued Odd [0,fs/2)

Complex-va lued E ven or odd [0,fs)

pmcov

[Pxx,f] = pmcov(x,p,nfft,fs,' range ') or

[Pxx,w] = pmcov(x,p,nfft,' range ') specifies t he ra nge of frequency valuest o include in f or w. This synt a x is useful wh en x is real . ' range ' can be eith er:

'twosided' : Compute the tw o-sided PS D over th e frequency ra nge [0,fs) .This is the defa ult for determining t he frequency ra nge forcomplex-valued x.- If y ou specify fs a s t he empty vector, [] , the frequency ran ge is [0,1) .- If y ou don’t specify fs , the frequency ran ge is [0, 2 π).

• 'onesided' : Compute t he one-sided P SD over th e frequency ra nges specifiedfor rea l x . This is the defa ult for determining t he frequency ra nge forreal-valued x .

Note You can put the str ing ar gument ' range ' a nyw here in the inputargument l i s t a f ter p.

pmcov(...) wit h n o outputs plots the power spectral density in t he current

Page 606: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 606/798

7-323

figure window . The frequency ran ge on th e plot is th e same a s the ra nge ofoutput w (or f ) for a given set of para meters.

Remarks The pow er spectr a l density is computed a s th e distribut ion of pow er per unitfrequency.

This a lgorith m depends on your selecting a n a ppropriat e model order for yoursignal.

Examples Because the modified covariance method estimates the spectral density byfitt ing a n AR prediction model of a given order t o th e signal, first genera te asign a l from a n AR (a ll-pole) model of a given order. You can use freqz t o checkth e ma gnitu de of the frequency response of your AR filter. This w ill give you anidea of wh a t t o expect when you estima te the P SD using pmcov .

a = [1 -2.2137 2.9403 -2.1697 0.9606]; % AR filter coefficientsfreqz(1,a) % AR filter frequency response

title('AR System Frequency Response')

pmcov

Now generat e the input signa l x by filtering wh ite noise th rough th e AR filter.Est imat e the P SD of x bas ed on a fourt h-order AR prediction model since in t hiscase we know t ha t the origina l AR system model a has o rder 4.

randn('state',1);

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−200

−150

−100

−50

0

50

100

Normalized Frequency ( ×πrad/sample)

P h a s e

( d e g r e e s

)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−20

−10

0

10

20

30

40

Normalized Frequency ( ×πrad/sample)

M

a g n

i t u d e

( d B )

AR System Frequency Response

Page 607: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 607/798

7-324

x = filter(1,a,randn(256,1)); % AR filter outputpmcov(x,4) % Fourth-order estimate

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−30

−20

−10

0

10

20

30

Normalized Frequency ( ×πrad/sample)

P o w e r

S p e c

t r a l D e n s

i t y ( d B / r a d

/ s a m p

l e )

Modified Covariance PSD Estimate

pmcov

Algorithm Linea r prediction filters can be used to model the second-order sta tist ica lchar a cteristics of a signa l. The prediction filter output ca n be used to model th esignal w hen the input is w hite noise.

pmcov estimat es the P SD of th e signal vector using t he modified covaria nce

meth od. This m ethod fits a n a ut oregressive (AR) linear prediction filter modelto the signal by simultaneously minimizing the forw a rd a nd ba ckwa rdprediction errors (ba sed on ca usa l observat ions of your input signa l) in th eleast sq ua res sense. The spectra l estima te return ed by pmcov i s the magni tudesqua red frequency response of th is AR model.

See Also armcov , lpc , pburg , pcov , peig , periodogram , pmtm, pmusic , pwelch , prony ,psdplot , pyulear

References [1] Ma rple, S.L . Di gi ta l Spectr a l An alysis , Englew ood Cliffs, NJ , Pr entice-Ha ll,1987, Chapt er 7.

[2] St oica, P ., a nd R .L. Moses, In t r oduct ion to Spectr a l Anal ysis , Pr entice-Ha ll,1997.

Page 608: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 608/798

7-325

pmtm

7pmtmPurpose Est imat e the power spectral density using t he multi ta per meth od (MTM)

Syntax [Pxx,w] = pmtm(x,nw)[Pxx,w] = pmtm(x,nw,nfft)

[Pxx,f] = pmtm(x,nw,nfft,fs)[Pxx,Pxxc,f] = pmtm(x,nw,nfft,fs)[Pxx,Pxxc,f] = pmtm(x,nw,nfft,fs,p)[Pxx,Pxxc,f] = pmtm(x,e,v,nfft,fs,p)[Pxx,Pxxc,f] = pmtm(x,dpss_params,nfft,fs,p)[...] = pmtm(...,' method ')[...] = pmtm(...,' range ')pmtm(...)

Description pmtm estima tes th e pow er spectra l density (P SD ) of th e time series x using themult ita per meth od (MTM) described in [1]. This m ethod u ses linear ornonlinear combinat ions of modified periodogram s to estima te th e PS D. Theseperiodogra ms a re computed using a sequence of orthogonal t a pers (w indows inth e frequency domain ) specified from t he discrete prolat e spheroida l sequences(see dpss ).

Page 609: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 609/798

7-326

[Pxx,w] = pmtm(x,nw) est imat es the P SD Pxx for t he input signal x , using2*nw-1 discrete prolat e spheroida l sequences as da ta ta pers for the multi t a perestimat ion method. nw is the time-ba ndw idth product for the discrete prola tespheroidal sequences. If you specify nw a s the empty vector [] , a defaul t valueof 4 is used . Ot her t ypica l choices a re 2, 5/2, 3, or 7/2. pmtm also return s w, avector of frequencies a t wh ich t he P SD is estimated. Pxx a nd w ha ve the samelength. The un its for fr equency a re ra d/sa mple.

The pow er spectr a l density is calculat ed in units of power per ra dia ns persample. Real-valued inputs produce (by default) full power one-sided (infrequency) P SD s, wh ile complex-va lued inputs produce tw o-sided P SD s.

In general , the length N of th e FFT a nd t he values of the input x determine thelength of Pxx a nd t he ra nge of th e corresponding norma lized frequencies. Forthis syn ta x, the (default) length N of the FF T is th e larg er of 256 a nd t he nextpower of tw o grea ter t ha n th e lengt h of th e segment . The follow ing ta ble

pmtm

indica tes th e length of Pxx a nd t he ra nge of the corresponding norma lizedfrequencies for this syntax.

[Pxx,w] = pmtm(x,nw,nfft) uses the multi ta per method to estimat e the PS Dw hile specifying th e lengt h of the FFT w ith t he integer nfft . If y ou specify nfft a s th e empty vector [] , i t a dopts th e defau lt va lue for N described in th eprevious syntax.

The lengt h of Pxx an d th e frequency ra nge for w depend on nfft and the valuesof the input x . The follow ing t a ble indica tes t he length of Pxx a nd t he frequencyra nge for w for this synta x.

Table 7-26: PSD Vector Characteristics for an FFT Length of N (Default)

Real/ ComplexInput Data

Length of Pxx Range of the CorrespondingNormalized Frequencies

Rea l-va lued ( N /2) + 1 [0, π]

Complex-valued N [0, 2 π)

Table 7-27: PSD and Frequency Vector Characteristics

Page 610: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 610/798

7-327

[Pxx,f] = pmtm(x,nw,nfft,fs) uses the sampling frequency fs specified asa n int eger in hertz (Hz) to compute the P SD vector ( Pxx ) a nd t he correspondingvector of frequencies ( f ). In t his case, th e units for t he frequency vector f a rein Hz. The spectral density produced is ca lculat ed in units of power per Hz. Ifyou s pecify fs a s the empty vector [] , the sampling frequency defaults to 1 Hz.

Real/ ComplexInput Data

nfft Even/ Odd Length of Pxx Range of w

Rea l-va lued E ven ( nfft /2 + 1) [0, π]

Rea l-va lued Odd ( nfft + 1)/2 [0, π)

C om plex-va lued E ven or od d nfft [0, 2 π)

pmtm

The frequency range for f depends on nfft , fs , an d th e values of the input x .The lengt h of Pxx is the same as in Ta ble 7-27 . The follow ing t a ble indicat es thefrequency ra nge for f for this synt a x.

[Pxx,Pxxc,f] = pmtm(x,nw,nfft,fs) re turns Pxxc , th e 95%confidenceinterval for Pxx . Confidence int erva ls ar e computed using a chi-squa redapproach. Pxxc is a t wo-column ma trix wit h t he same number of rows a s Pxx .Pxxc(:,1) is th e low er bound of th e confidence int erval a nd Pxxc(:,2) is theupper bound of the confidence int erval.

[Pxx,Pxxc,f] = pmtm(x,nw,nfft,fs,p) returns Pxxc , the p*100% confidenceinterval for Pxx , where p is a scala r between 0 a nd 1. If y ou don’t specify p , or

if you specify p a s the empty vector [] th e default 95%confidence int erval is

Table 7-28: PSD and Frequency Vector Characteristics with fs Specified

Real/ Complex Input Data nfft Even/ Odd Range of f

Rea l-va lued E ven [0 , fs/2 ]

Rea l-va lued Odd [0 , fs/2)

Complex-va lued E ven or odd [0, fs )

Page 611: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 611/798

7-328

if you specify p a s the empty vector [] , th e default 95%confidence int erval isused.

[Pxx,Pxxc,f] = pmtm(x,e,v,nfft,fs,p) re turns the P SD es t imate Pxx , theconfidence interva l Pxxc , an d th e frequency vector f f rom the dat a ta persconta ined in the columns of the ma trix e , an d th eir concentr at ions in th evector v . The lengt h of v is the sa me as t he number of columns in e . You ca nobta in the da ta to supply a s these arguments from the outputs of dpss .

[Pxx,Pxxc,f] = pmtm(x,dpss_params,nfft,fs,p) uses the cell arra ydpss_params conta ining the input a rguments to dpss (listed in order, butexcluding the first argument) to compute the data tapers. For example,pmtm(x,3.5,'trace',512,1000) calculates the prolate spheroidalsequen ces for nw = 3.5 , using nfft = 512, a n d fs = 1000, and displays themethod tha t dpss uses for t his calculat ion. See dpss for other options.

pmtm

[...] = pmtm(...,' method ') specifies t he a lgorith m used for combining t heindividua l spectr a l estima tes. The string ' method ' can be one of th e following :

• 'adapt' : Thomson’s a da ptive nonlinear combina tion (defau lt)• 'unity' : A linear combina tion of the weight ed periodogra ms w ith un ity

weights• 'eigen' : A linear combinat ion of the weight ed periodogra ms w ith

eigenvalue w eights

[...] = pmtm(...,' range ') specifies t he ra nge of frequency va lues to includein f or w. This syn ta x is useful when x is real . ' range ' can be either:

• 'twosided' : Compute the tw o-sided PS D over th e frequency ra nge [0,fs) .

This is t he defau lt for determ ining t he frequency ra nge for complex-va luedx.- If y ou specify fs a s t he empty vector, [] , the frequency ran ge is [0,1) .- If y ou don’t specify fs , the frequency ran ge is [0, 2 π).

• 'onesided' : Compute t he one-sided P SD over th e frequency ra nges specifiedfor rea l x . This is the defa ult for determining t he frequency ra nge forreal-valued x .

Page 612: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 612/798

7-329

Note You can put the str ing argum ents ' range ' or ' method ' anyw here af terthe input argument nw or v.

pmtm(...) with no output a rguments p lots the P SD est imat e and t heconfidence interva ls in the current figure w indow. I f you don’t specify fs , the

95%confidence inter va l is plot ted . If you do specify fs , th e confidence int erva lsplott ed depend on t he va lue of p .

pmtm

Examples This example an a lyzes a sinusoid in w hite noise.

randn('state',0);fs = 1000; t = 0:1/fs:0.3;x = cos(2*pi*t*200) + 0.1*randn(size(t));

[Pxx,Pxxc,f] = pmtm(x,3.5,512,fs,0.99);psdplot([Pxx Pxxc],f,'hz','db')title('PMTM PSD Estimate with 99% Confidence Intervals')

−60

−50

−40

−30

−20

−10

P o w e r

S p e c t r a

l D e n s i t y

( d B / H z )

PMTM PSD Estimate with 99% Confidence Intervals

Page 613: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 613/798

7-330

See Also dpss , pburg , pcov , peig , periodogram , pmcov , pmusic , pwelch , psdplot ,pyulear

References [1] P ercival, D .B ., a nd A.T. Wa lden, Spectr al An al ysis for Ph ysical Appl i cat ions: M ul t i t aper and Convent i onal U ni var i a te Techni ques , CambridgeU niversity P ress, 1993.

[2] Thomson, D.J ., “Spectrum estima tion a nd ha rmonic a na lysis,” Proceedings of the IEE E , Vol. 70 (1982), pp. 1055-1096.

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

Frequency (Hz)

pmusic

7pmusicPurpose Est imat e the pseudospectrum using the MUS IC a lgorithm

Syntax [S,w] = pmusic(x,p)[S,w] = pmusic(...,nfft)[S,f] = pmusic(x,p,nfft,fs))[S,f] = pmusic(..., ' corr ')[S,f] = pmusic(x,p,nfft,fs,nwin,noverlap)[...] = pmusic(..., ' range ')[...,v,e] = pmusic(...)pmusic(...)

Description [S,w] = pmusic(x,p) implements the MUS IC (Multiple Signal Cla ssifica tion)

algor i thm a nd re turns S, the pseudospectrum estimate of the input signal x ,a nd a vector w of norma lized frequencies (in ra d/sa mple) a t wh ich t hepseudospectr um is eva lua ted. The pseudospectr um is ca lcula ted u singestimat es of th e eigenvectors of a correlation ma trix a ssocia ted w ith the inputd a t a x , where x is specified a s eith er:

• A row or column vector r epresent ing one observa tion of th e signa l• A recta ngular a rra y for w hich each row of x represents a separa te

observat ion of the signa l (for exam ple, each row is one output of a n a rra y off

Page 614: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 614/798

7-331

g ( p , p ysensors, a s in a rra y processing), such tha t x'*x is an estima te of thecorrelation ma trix

Note You ca n use t he output of corrmtx to generate such a n a rray x .

You can specify th e second input a rgument p a s either:• A scala r integer. In t his case, the signa l subspace dimension is p .• A tw o-element vector. I n t his ca se, p(2) , th e second element of p , represent s

a thr eshold tha t is multiplied by λmin , th e smallest est ima ted eigenva lue ofthe signal’s correlation matrix. Eigenvalues below the threshold λmin *p(2) a re assign ed to the noise subspa ce. In th is ca se, p(1) specifies t he ma ximumdimension of th e signa l subspace.

pmusic

The extr a t hreshold para meter in th e second ent ry in p provides you moreflexibility a nd cont rol in a ssigning t he noise and sign a l subspaces.

S a nd w ha ve the same length. In general , the length of the FFT a nd t he valuesof the input x determine t he length of the computed S and the ran ge of the

corresponding norma lized frequ encies. The following t a ble indica tes t he lengthof S (and w) a nd t he ra nge of the corresponding norma lized frequencies for t hissyntax.

[S,w] = pmusic(...,nfft) specifies th e lengt h of the FF T used to estima teth e pseudospectr um wit h th e integer nfft . The defa ult va lue for nfft (entereda s a n empty vector [] ) is 256.

The follow ing t a ble indica tes t he length of S a nd w, an d t he frequency ran ge forw in th is syntax.

Table 7-29: S Characteristics for an FFT Length of 256 (Default)

Real/ ComplexInput Data

Length of S and w Range of the CorrespondingNormalized Frequencies

Rea l-va lued 129 [0, π]Complex-va lued 256 [0, 2 π)

Page 615: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 615/798

7-332

y

[S,f] = pmusic(x,p,nfft,fs) retur ns t he pseudospectr um in t he vector S evalua ted a t t he corresponding vector of frequencies f (in Hz). You supply thesampling frequency fs in Hz. If you specify fs wit h t he empty vector [] , thesam pling frequency defaults to 1 Hz.

Table 7-30: S and Frequency Vector Characteristics

Real/ ComplexInput Data

nfft Even/ Odd Length of Sand w

Range of w

Rea l-va lued E ven (nfft/2 + 1) [0, π]

Rea l-va lued Odd (nfft + 1)/2 [0, π)

C om plex-va lued E ven or odd nfft [0, 2 π)

pmusic

The frequency range for f depends on nfft , fs , an d th e values of the input x .The leng th of S (and f ) is the sa me as in Ta ble 7-30 . The follow ing t a bleindicates the frequency range for f for this synt a x.

[S,f] = pmusic(..., ' corr ') forces th e input a rgument x to be interpreted a sa corre la t ion ma tr ix ra ther tha n ma tr ix of s ignal da ta . For th is synta x x mustbe a squa re mat rix, a nd a ll of i ts eigenvalues must be nonnegat ive.

[S,f] = pmusic(x,p,nfft,fs,nwin,noverlap) allows you to specify nwin , ascalar integer indica ting a recta ngular window length, or a real-valued vectorspecifying w indow coefficient s. Use t he scala r int eger noverlap in conjunctionwi th nwin to specify th e number of input s a mple points by w hich successive

windows overla p. noverlap is not used if x is a m a tr ix. The default va lue forn in is 2*p(1) a nd no erlap is n in 1

Table 7-31: S and Frequency Vector Characteristics with fs Specified

Real/ Complex Input Data nfft Even/ Odd Range of f

Rea l-va lued E ven [0,fs/2]

Rea l-va lued Odd [0,fs/2)

Complex-va lued E ven or odd [0,fs)

Page 616: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 616/798

7-333

nwin is 2*p(1) a nd noverlap is nwin-1 .

With this synta x, the input dat a x is segmented a nd w indowed before th ema tr ix used to estima te th e correlat ion ma tr ix eigenvalues is formula ted. Thesegmenta tion of the da ta depends on nwin , noverlap , an d th e form of x .Comment s on t he resulting w indowed segments a re described in the follow ingtable.

Table 7-32: Windowed Data Depending on x and nwin

Input data x Form of nwin Windowed Data

D a t a vect or S ca la r Length is nwin

D a ta vect or Vect or of coefficien ts Length is length(nwin)

pmusic

S ee Ta ble 7-33 for relat ed informa tion on t his synta x.

Note The arguments nwin a nd noverlap a re ignored wh en you include th e

string ' corr ' in the syntax.

[...] = pmusic(..., ' range ') specifies th e ra nge of frequency va lues toinclude in f or w. This syn ta x is useful when x is real . ' range ' can be either:

• 'whole' : Compute th e pseudospectrum over the frequency ra nge [0,fs) .This is t he defa ult for d etermining th e frequency ra nge for complex-va lued x . -

If y ou specify fs a s t he empty vector, [] , the frequency ra nge is [0,1) .If d ’t if f th f i [0 2 π)

Da t a ma t rix Sca la r Da t a is not w indow ed.

D a ta m a t rix Vect or of coefficien ts length(nwin) must be thesam e as t he column length of x ,a nd noverlap is not used.

Table 7-32: Window ed Data Depending on x and nwin (Continued)

Input data x Form of nwin Windowed Data

Page 617: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 617/798

7-334

- If y ou don’t specify fs , the frequency ran ge is [0, 2 π).• 'half' : Compute t he pseudospectr um over th e frequency ra nges specified

for rea l x . This is th e default for det ermining t he frequency ra nge forreal-valued x .

Note You can put the str ing ar guments ' range ' or ' corr ' anyw here in theinput argument l ist after p.

[...,v,e] = pmusic(...) re turns the matr ix v of noise eigenvectors, a longwit h t he a ssocia ted eigenva lues in t he vector e . The colum ns of v span t he noisesubspace of dimension size(v,2) . The dimension of the sign a l subspa ce issize(v,1)-size(v,2) . For this synta x, e is a vector of estima ted eigenvalues

of the correlation matrix.

pmusic

pmusic(...) with no output a rguments plots t he pseudospectrum in thecurrent f igure w indow.

Remarks In t he process of estima ting t he pseudospectr um, pmusic comput es th e noiseand signal subspaces from the estimated eigenvectors v j a nd eigenvalues λ j ofth e signa l’s correla tion ma tr ix. The sma llest of th ese eigenvalues is used inconjunction wit h t he th reshold para meter p(2) to affect th e dimension of thenoise subspace in some cases.

The leng th n of the eigenvectors computed by pmusic is the sum of thedimensions of the signa l a nd noise subspa ces. This eigenvector lengt h d ependson your input (signal da ta or correlat ion ma trix) a nd t he synta x you use.

The following t a ble summa rizes th e dependency of th e eigenvector lengt h onthe input a rgument.

Table 7-33: Eigenvector Length Depending on Input Data and Syntax

Form of Input Data x Comments on the Syntax Length n of Eigenvectors

Row or column vector nwin is specified as a scala rinteger.

nwin

Row or column vector nwin is specified a s a length(nwin)

Page 618: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 618/798

7-335

You should specify nwin > p(1) or length(nwin) > p(1) i f you wa nt p(2) > 1 t oha ve any effect .

Row or column vector nwin is specified a s avector.

length(nwin)

Row or column vector nwin is not specified. 2*p(1)

l -by- m ma t rix I f nwin is specified a s ascala r, it is not used. Ifnwin is specified a s avector, length(nwin) mustequal m .

m

m -by- m nonnegativedefinite mat rix

The string ' corr ' isspecified and nwin is notused.

m

pmusic

Examples Example 1: pmusic with no Sampling SpecifiedThis example an a lyzes a signa l vector x , assuming tha t tw o real sinusoidalcomponents a re present in th e signal subspa ce. In t his case, th e dimension ofth e signa l subspace is 4 beca use each rea l sinusoid is the sum of tw o complexexponentials.

randn('state',0);n = 0:199;x = cos(0.257*pi*n) + sin(0.2*pi*n) + 0.01*randn(size(n));pmusic(x,4)

0

10

20

30

40

50

60

d B

MUSIC Pseudospectrum

Page 619: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 619/798

7-336

Example 2: Specifying Sampling Frequency and Subspace DimensionsThis example ana lyzes the sam e signa l vector x w ith a n eigenva lue cut off of10%above the minimum. Setting p(1) = Inf forces th e signa l/noise subspa ce

decision t o be ba sed on t he thr eshold par a meter p(2) . Specify the eigenvectorsof length 7 using t he nwin a rgument, a nd set th e sampling frequency fs t o8 kH z.

randn('state',0);n = 0:199;x = cos(0.257*pi*n) + sin(0.2*pi*n) + 0.01*randn(size(n));[P,f] = pmusic(x,[Inf,1.1],[],8000,7); % Window length = 7

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−10

Normalized Frequency ( ×πrad/sample)

pmusic

Exa mp le 3: Entering a Correla t ion M a trixSu pply a positive definite correlat ion ma tr ix R for estimat ing the spectraldensity . Use th e defa ult 256 samples.

R = toeplitz(cos(0.1*pi*[0:6])) + 0.1*eye(7);

[P,f] = pmusic(R,4,'corr');

Exa mp le 4: Entering a Signal Da ta M a trix G enerated from corrmtxEnte r a s igna l da ta ma t r ix Xmgenera ted from dat a using corrmtx .

randn('state',0);n = 0:699;x = cos(0.257*pi*(n)) + 0.1*randn(size(n));Xm = corrmtx(x,7,'mod');[P,w] = pmusic(Xm,2);

Exa mp le 5: Using W indow ing to Create the Effect of a Signal Da ta M a trixU se the same signal, but let pmusic form t he 100-by-7 dat a ma tr ix using itsw indowing input a rgument s. In a ddition, specify a n FF T of length 512.

randn('state',0);n = 0:699;x = cos(0.257*pi*(n)) + 0.1*randn(size(n));[PP ff] = pmusic(x 2 512 [] 7 0);

Page 620: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 620/798

7-337

[PP,ff] pmusic(x,2,512,[],7,0);

Algorithm The na me MUS IC is an a cronym for MUlt iple SIgna l Classifica tion. TheMUS IC a lgorithm estima tes the pseudospectrum from a signa l or a correlationma tr ix using Schmidt ’s eigenspa ce a na lysis method [1]. The a lgorith mperforms eigenspace ana lysis of the signa l’s correla tion ma tr ix in order t oestima te th e signa l’s frequency content . This algorithm is part icular ly suita blefor signals th a t a re the sum of sinusoids with a ddit ive wh ite Ga ussian noise.The eigenva lues an d eigenvectors of th e signa l’s correla tion ma tr ix ar eestima ted if you don’t supply the correla tion ma tr ix.

The MU SI C pseudospectr um estima te is given by

P music f ( ) 1

e H f ( ) v k v k H

N

e f ( )

---------------------------------------------------------------- 1

v k H

e f ( )2

N

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

pmusic

where N is th e dimension of the eigenvectors an d v k i s the k -th eigenvector ofth e correlat ion ma tr ix. The integer p is the dimension of the signa l subspace,so the eigenvectors v k used in th e sum correspond to the sma llest eigenva luesa nd a lso spa n t he noise subspace. The vector e (f ) consists of complexexponentia ls, so the inn er product

a mounts t o a F ourier tr a nsform. This is used for computa tion of thepseudospectrum estimate. The FFT is computed for each v k and then thesqua red magnitudes are summed.

See Also corrmtx , pburg , peig , periodogram , pmtm, prony , psdplot , pwelch , rooteig ,

rootmusic

References [1] Ma rple, S.L . Di gi ta l Spectr a l An alysis , Englewood Cliffs, NJ , Pr entice-Ha ll,1987, pp. 373-378.

[2] Schmidt, R.O, “Multiple Emit ter Loca tion an d S ignal P ar a meterEstimation,” I EE E T ran s. Antennas Propagat ion, Vol. AP-34 (Ma rch 1986),pp. 276-280.

[3] St oica, P ., an d R.L. Moses, In t r oduct ion to Spectr a l Anal ysis , Pr entice-Ha ll,En glewood C liffs, NJ , 1997.

v k H e f ( )

Page 621: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 621/798

7-338

En glewood C liffs, NJ , 1997.

poly2ac

7poly2acPurpose Convert a prediction filter polynomial t o an a ut ocorrelat ion sequence

Syntax r = poly2ac(a,efinal)

Description r = poly2ac(a,efinal) finds th e aut ocorrelat ion vector r corresponding t oth e prediction filter polynomial a . The autocorrelation sequence produced isa pproximately th e same a s t ha t of th e output of th e au toregressive predictionfilter w hose coefficients a re determin ed by a . poly2ac a lso produces the fina llength(r) step prediction error efinal . I f a(1) is not equa l to 1 , poly2ac norma lizes t he prediction filter polynomia l by a(1) . a(1) cann ot be 0.

Remarks You can a pply this funct ion t o both rea l a nd complex polynomials.

Examples a = [1.0000 0.6147 0.9898 0.0004 0.0034 -0.0077];efinal = 0.2;r = poly2ac(a,efinal)

r =5.5917

-1.7277-4.4231

4.39851.6426

Page 622: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 622/798

7-339

-5.3126

See Also ac2poly , poly2rc , rc2ac

References [1] Ka y, S .M. M odern Spectr a l Est im at ion, En glewood C liffs, NJ ,Prentice-Hall, 1988.

poly2lsf

7poly2lsfPurpose Convert prediction filter coefficient s t o line spectr a l frequencies

Syntax lsf = poly2lsf(a)

Description lsf = poly2lsf(a) returns a vector lsf of line spectral frequencies (alsoknown a s line spectrum pairs) from a vector a of prediction filter coefficient s.

Examples a = [1.0000 0.6149 0.9899 0.0000 0.0031 -0.0082];lsf = poly2lsf(a)

lsf =0.78421.5605

1.87761.89842.3593

See Also lsf2poly

References [1] Deller, J .R., J .G. P roakis, a nd J .H.L. Ha nsen, “D i scr ete-Ti m e Pr ocessi n g of Speech Si gnal s ,” P rent ice-H a ll, 1993.

[2] Ra biner, L.R., a nd R.W. Scha fer, “ D i git al Pr ocessi ng of Speech Sign al s ,”Prentice Hall 1978

Page 623: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 623/798

7-340

Prentice-Hall, 1978.

poly2rc

7poly2rcPurpose Convert a prediction filter polynomial to reflection coefficients

Syntax k = poly2rc(a)[k,r0] = poly2rc(a,efinal)

Description k = poly2rc(a) converts th e prediction filter polynomial a to the reflectioncoefficients of the corresponding la tt ice structur e. a can be real or complex, a nda(1) cann ot be 0. If a(1) is not equa l to 1 , poly2rc norma lizes t he predictionfilter polynomia l by a(1) . k is a row vector of size length(a)-1 .

[k,r0] = poly2rc(a,efinal) retur ns t he zero-lag a utocorrela tion, r0 , basedon the fina l prediction error, efinal .

A simple, fa st w a y t o check if a ha s a ll of its roots inside t he unit circle is tocheck if ea ch of the element s of k ha s magnitu de less tha n 1.

stable = all(abs(poly2rc(a))<1)

Examples a = [1.0000 0.6149 0.9899 0.0000 0.0031 -0.0082];efinal = 0.2;

[k,r0] = poly2rc(a,efinal)

k =

Page 624: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 624/798

7-341

0.30900.98010.00310.0081

-0.0082

r0 =5.6032

Limitations I f abs(k(i)) == 1 for a ny i , finding th e reflection coefficients is a nill-condit ioned problem. poly2rc returns some NaNs and provide a w a rningmessage in th is ca se.

poly2rc

Algorithm poly2rc implement s th e recursive relat ionship

This r ela tions hip is ba sed on Levin son’s recurs ion [1]. To implement it,poly2rc loops th rough a in reverse order a fter discar ding its first element . Foreach loop itera tion i , th e function:

1 Sets k(i) equal t o a(i)

2 Applies th e second rela tionship a bove to elements 1 th rough i of th e

vector a .a = (a–k(i)*fliplr(a))/(1–k(i)^2);

See Also ac2rc , latc2tf , latcfilt , poly2ac , rc2poly , tf2latc

References [1] Ka y, S .M. M odern Spectr a l Est im at ion, Englewood C liffs, NJ ,Prentice-Hall, 1988.

k n ( ) a n n ( )=

a n 1– m ( )

a n m ( ) k n ( ) a n n m –( )–

1 k n ( ) 2–---------------------------------------------------------- m 1= 2 … n 1–, , , ,=

Page 625: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 625/798

7-342

polyscale

7polyscalePurpose Sca le the roots of a polynomial

Syntax b = polyscale(a,alpha)

Description b = polyscale(a,alpha) scales the roots of a polynomial in th e z -plane,where a is a vector cont a ining t he polynomial coefficients a nd alpha is thescaling factor.

I f alpha is a real value in the range [0 1] , then t he roots of a a re radia lly sca ledtowa rd the origin in the z -pla ne. Complex va lues for alpha al low a rbit ra rychan ges to the root loca tions.

Remark B y reducing t he ra dius of the roots in a n a utoregressive polynomial, th e

ba ndw idth of the spectr a l pea ks in the frequency response is expan ded(flat tened). This opera tion is often r eferred t o as bandw id th expansion .

See Also polystab , roots

Page 626: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 626/798

7-343

polystab

7polystabPurpose Stabilize polynomial

Syntax b = polystab(a)

Description polystab sta bilizes a polynomial w ith respect t o the unit circle; it reflects r ootswit h ma gnitudes grea ter th a n 1 inside the unit circle.

b = polystab(a) returns a row vector b cont a ining the sta bilized polynomia l,where a is a vector of polynomial coefficients, n ormally in t he z -domain.

Examples polystab can convert a linear-pha se filter into a m inimum-pha se filter w ith

the sa me ma gnitude response.h = fir1(25,0.4);hmin = polystab(h) * norm(h)/norm(polystab(h));

Algorithm polystab finds t he roots of the polynomia l an d ma ps those roots found outsideth e unit circle to the inside of th e 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);

a z ( ) a 1( ) a 2( ) z 1– L a m 1+( ) z m –+ + +=

Page 627: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 627/798

7-344

b = a(1)*poly(v);

See Also roots

prony

7pronyPurpose P rony’s method for time doma in IIR filter design

Syntax [b,a] = prony(h,n,m)

Description P rony’s method is an a lgorithm for f inding a n II R fi l ter with a prescribed t imedoma in impulse response. It h a s a pplica tions in filter design, exponent ia lsigna l modeling, and sy stem ident ifica tion (par a metric modeling).

[b,a] = prony(h,n,m) f inds a f i l ter with numerat or order n , denominatororder m, a nd t he time doma in impulse response in h . If the length of h is lesstha n the largest order ( n or m) , h is padded w ith zeros. prony returns t he f i ltercoefficient s in r ow vectors b a nd a , of length n + 1 a nd m+ 1 , r espectively. Thefilter coefficients a re in descending pow ers of z .

Examples Recover th e coefficients of a B utt erwort h filter from it s impulse response.

[b,a] = butter(4,0.2)

b =0.0048 0.0193 0.0289 0.0193 0.0048

H z ( ) B z ( )A z ( )----------- b 1( ) b 2( ) z 1– L b n 1+( ) z n –+ + +

a 1( ) a 2( ) z 1– L a m 1+( ) z m –+ + +----------------------------------------------------------------------------------------= =

Page 628: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 628/798

7-345

a =1.0000 -2.3695 2.3140 -1.0547 0.1874

h = filter(b,a,[1 zeros(1,25)]);[bb,aa] = prony(h,4,4)

bb =0.0048 0.0193 0.0289 0.0193 0.0048

ab =1.0000 -2.3695 2.3140 -1.0547 0.1874

Algorithm prony implement s t he met hod described in r eference [1]. This m eth od uses ava ria tion of th e covaria nce meth od of AR modeling t o find th e denomina torcoefficients a a nd th en finds th e numera tor coefficient s b for w hich th e impulse

prony

response of th e out put filter ma tches exactly t he first n + 1 sa mples of x . Thefilter is not necessa rily sta ble, but potent ially ca n recover th e coefficientsexactly if the da ta sequence is truly a n a ut oregressive moving a verag e (ARMA)process of th e corr ect order.

See Also butter , cheby1 , cheby2 , ellip , invfreqz , levinson , lpc , stmcb

References [1] P a rks, T.W., an d C .S. B urru s, Di gi ta l Fi l ter D esign, J ohn Wiley & Sons,1987, pp. 226-228.

Page 629: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 629/798

7-346

psdplot

7psdplotPurpose P lot power spectra l density (PS D) data

Syntax psdplot(Pxx,w)psdplot(Pxx,w,' units ')psdplot(Pxx,w,' units ',' yscale ')psdplot(Pxx,w,' units ',' yscale ',' title ')

Description psdplot(Pxx,w) plots the power spectral density da ta contained in t he vectorPxx a t th e frequencies specified in t he vector w. The vect ors Pxx a nd w mustha ve the same length. The ma gnitude of the da ta vector Pxx is plott ed in dB perra dians per sa mple versus frequency w on one plot. The un its for fr equen cy onth e plots a re ra d/sa mple.

psdplot(Pxx,w,' units ') displa ys t he frequency unit s a ccording t o the str ing' units ' . This st ring ca n be either:

• 'rad/sample' (default)• 'Hz'

psdplot(Pxx,w,' units ',' yscale ') displa ys the spectral density ma gnitudeunits a ccording to th e str ing ' yscale ' . This st ring ca n be either:

• 'db' (defau lt), for plott ing th e PS D in dB per units of frequency• 'linear' , for plott ing th e PS D in un its of power per units of frequency

Page 630: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 630/798

7-347

psdplot(Pxx,w,' units ',' yscale ','title') uses the cont ents of the string'title' a s th e title of the plot.

Examples t = 0:0.001:0.3;

x = cos(2*pi*t*200) + randn(size(t));[Pxx,w] = periodogram(x,[],'twosided',512);psdplot(Pxx,w,'','','Sample PSD Plot')

psdplot

See Also freqzplot , pburg , pcov , peig , periodogram , pmcov , pmusic , pwelch , pyulear

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8−35

−30

−25

−20

−15

−10

−5

0

5

10

15

Normalized Frequency ( ×πrad/sample)

P o w e r

S p e c

t r a l D e n s

i t y ( d B / r a

d / s a

m p

l e )

Sample PSD Plot

Page 631: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 631/798

7-348

pulstran

7pulstranPurpose G enerat e a pulse t ra in

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 pulse tr a ins from continuous functions or sa mpledprototype pulses.

y = pulstran(t,d,' func ') genera tes a pulse tra in based on sa mples of acont inuous fun ction, ' func ' , where ' func ' is :

'gauspuls' , for generat ing a G a ussian-modula ted sinusoidal pulse• 'rectpuls' , for generating a sampled aperiodic rectangle• 'tripuls' , for generat ing a sa mpled a periodic tr iangle

pulstran is evalua ted length(d) t imes and returns t he sum of the eva luat ionsy = func(t-d(1)) + func(t-d(2)) + ...

The function is evalua ted over the ra nge of argum ent va lues specified in

a r r a y t , a fter removing a scalar a rgument offset ta ken from the vector d . Notet h a t func must be a vectorized function tha t can ta ke a n a rra y t a s a nargument .

Page 632: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 632/798

7-349

An optiona l gain fa ctor may be applied to each delay ed evalua tion by specifyingd as a tw o-column ma trix, with the offset defined in column 1 and a ssocia tedga in in column 2 of d . Note th a t a row vector will be interpret ed as specifyingdelays only.

pulstran(t,d,' func ',p1,p2,...) a llows a ddit iona l para meters to be pa ssedt o ' func ' as necessary. For example,

func(t-d(1),p1,p2,...) + func(t-d(2),p1,p2,...) + ...

pulstran(t,d,p,fs) genera tes a pulse tra in tha t is the sum of multipledelay ed interpolat ions of th e prototy pe pulse in vector p , sampled a t t her a t e fs , where p spans th e t ime interval [0,(length(p)-1)/fs] , and i t ssa mples a re identically 0 outside this interval. B y default , l inea r interpolat ionis used for generating delays.

pulstran

pulstran(t,d,p) assumes that t he sampl ing ra t e fs i s equal to 1 Hz.

pulstran(...,' func ') specifies a lterna tive interpola tion methods. Seeinterp1 for a l ist of a vailable methods.

Examples Exa mple 1This exa mple genera tes a n a symmetric saw tooth wa veform w ith a repeti t ionfrequency of 3 Hz a nd a saw tooth w idth of 0.1s. I t h a s a signa l length of 1s a nda 1 kHz sample ra t e .

t = 0 : 1/1e3 : 1; % 1 kHz sample freq for 1 secd = 0 : 1/3 : 1; % 3 Hz repetition freqy = pulstran(t,d,'tripuls',0.1,-1);plot(t,y)

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

Page 633: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 633/798

7-350

0 0.2 0.4 0.6 0.8 10

0.1

0.2

pulstran

Exa mple 2This exa mple genera tes a periodic G a ussian pulse signa l at 10 kHz, wit h 50%band widt h. The pulse repeti t ion frequency is 1 kHz, sample rat e is 50 kHz, an dpulse tra in length is 10 msec. The repeti t ion a mplitude should at 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 634: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 634/798

7-351

0 0.002 0.004 0.006 0.008 0.01

pulstran

Exa mple 3This exa mple genera tes a tra in of 10 Ha mming w indows.

p = hamming(32);t = 0:320; d = (0:9)'*32;y = pulstran(t,d,p);plot(t,y)

See Also chirp , cos , diric , gauspuls , rectpuls , sawtooth , sin , sinc , square , tripuls

0 50 100 150 200 250 300 3500

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

Page 635: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 635/798

7-352

pwelch

7pwelchPurpose E stima te t he pow er spectra l density (P SD ) of a signa l using Welch’s meth od

Syntax [Pxx,w] = pwelch(x)[Pxx,w] = pwelch(x,window)[Pxx,w] = pwelch(x,window,noverlap)

[Pxx,w] = pwelch(x,window,noverlap,nfft)[Pxx,f] = pwelch(x,window,noverlap,nfft,fs)[...] = pwelch(x,window,noverlap,...,' range ')pwelch(...)

Description Note pwelch computes t he power spectr a l density, not t he pow er spectr um.The difference between them is discussed in “Spectr a l Ana lysis” on pa ge 3-6.

[Pxx,w] = pwelch(x) estimat es the power spectra l density Pxx of the inputsigna l vector x using Welch’s a verag ed modified periodogra m meth od ofspectral est ima tion. With t his synta x:

• The vector x is segmented into eight sections of equa l lengt h, each w ith 50%overlap.

Any r ema ining (tr a iling) entr ies in x tha t cannot be included in t he eightsegments of equa l length a re disca rded.• Ea ch segment is windowed with a Ha mming window (see hamming ) tha t i s

the sa me length a s the segment.

Page 636: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 636/798

7-353

the sa me length a s the segment.

The pow er spectra l density is calculat ed in units of pow er per ra dia ns persa mple. The corresponding vector of frequen cies w is computed in ra dia ns persample, and has the same length a s Pxx .

A real-va lued input vector x produces a fu ll pow er one-sided (in freq uency) P SD(by default), while a complex-valued x produces a t wo-sided PS D.

In general , the length N of th e FFT a nd t he values of the input x determine thelength of Pxx a nd t he ra nge of the corresponding norma lized frequencies. Forthis syn ta x, the (default) length N of the FF T is th e larger of 256 a nd t he nextpow er of tw o grea ter t ha n th e length of the segment. The followin g ta ble

pwelch

indica tes t he length of Pxx a nd t he ra nge of the corresponding norma lizedfrequencies for this syntax.

[Pxx,w] = pwelch(x,window) calculat es the modified periodogra m usingeither:

• The win dow lengt h window for the Ha mming window when window is apositive integer

• The w indow weight s specified in window when window is a vector

With this syntax, the input vector x is divided int o an int eger number ofsegments with 50%overla p, and ea ch segment is the sa me length a s thewindow. En tries in x tha t a re left over a fter i t is divided into segments a rediscard ed. If you specify window a s t he empty vector [] , then the s ignal dat a i sdivided into eight segments, a nd a Ha mming w indow is used on each one.

[Pxx,w] = pwelch(x,window,noverlap) divides x int o segments a ccording toi d d th i t g l t if th b f ig l l

Table 7-34: PSD Vector Characteristics for an FFT Length of N (Default)

Real/ ComplexInput Data

Length of Pxx Range of the CorrespondingNormalized Frequencies

Rea l-va lued ( N /2) + 1 [0, π]

Complex-valued N [0, 2 π)

Page 637: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 637/798

7-354

window , an d uses the integer noverlap to specify the nu mber of signa l sa mples(element s of x) tha t a re common to two a dja cent segments. noverlap must beless tha n t he length of th e wind ow you specify. If you specify noverlap as theempty vector [] , then pwelch determines th e segment s of x so th a t t here is 50%overlap (default).

[Pxx,w] = pwelch(x,window,noverlap,nfft) uses Welch’s meth od toestimat e the P SD wh ile specifying the length of the FFT wit h t he integer nfft .If you set nfft to t he empty vector [] , i t a dopts t he default va lue for N listedin the previous syntax.

pwelch

The lengt h of Pxx an d th e frequency ra nge for w depend on nfft and the valuesof the input x . The follow ing t a ble indica tes t he length of Pxx a nd t he frequencyra nge for w for this synta x.

[Pxx,f] = pwelch(x,window,noverlap,nfft,fs) uses the sa mplingfrequency fs specified in h ertz (Hz) to compute th e P SD vector ( Pxx ) a nd thecorrespond ing vector of frequen cies ( f ). In t his case, th e units for th e frequencyvector a re in Hz. The spectr a l density produced is ca lcula ted in un its of pow erper Hz. If you specify fs a s the empty vector [] , the sa mpling frequencydefaul ts to 1 Hz.

The frequency r a nge for f depends on nfft , fs , an d th e values of the input x .

The leng th of Pxx is the same as in Ta ble 7-35 . The followin g ta ble indicat es thefrequency ra nge for f for this synt a x.

Table 7-35: PSD and Frequency Vector Characteristics

Real/ ComplexInput Data

nfft Even/ Odd Length of Pxx Range of w

Rea l-va lued E ven (nfft/2 + 1) [0, π]

Rea l-va lued Odd (nfft + 1)/2 [0, π)

C om plex-va lued E ven or od d nfft [0, 2 π)

Table 7-36: PSDand Frequency Vector Characteristicswith fsSpecified

Page 638: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 638/798

7-355

Table 7 36: PSD and Frequency Vector Characteristics with fs Specified

Real/ Complex Input Data nfft Even/ Odd Range of f

Rea l-va lued E ven [0,fs/2]

Rea l-va lued Odd [0,fs/2)Complex-va lued E ven or odd [0,fs)

pwelch

[...] = pwelch(x,window,noverlap,...,' range ') specifies t he ra nge offrequency values. This synt a x is useful wh en x is rea l. The st ring ' range ' ca nbe eith er:

• 'twosided' : Compute the tw o-sided PS D over th e frequency ra nge [0,fs) .This is the defa ult for determining t he frequency ra nge forcomplex-valued x.- If y ou specify fs a s t he empty vector, [] , the frequency ra nge is [0,1) .- If y ou don’t specify fs , the frequency ran ge is [0, 2 π).

• 'onesided' : Compute t he one-sided P SD over t he frequency ra nges specifiedfor rea l x . This is th e default for det ermining t he frequency ra nge forreal-valued x .

The string ' range ' can appear anyw here in the syntax a f ter noverlap .

pwelch(x,...) wit h no output a rguments plots t he PS D estimat e in dB perunit frequency in t he current f igure window.

Examples Est imat e the P SD of a signa l composed of a sinusoid plus noise, sam pled a t1000 Hz. U se 33-sa mple windows w ith 32-sa mple overlap, a nd t he defau lt F FTlength, a nd display the tw o-sided P SD estimat e.

randn('state',0);Fs = 1000; t = 0:1/Fs:.3;x = cos(2*pi*t*200) + randn(size(t)); % 200Hz cosine plus noisepwelch(x,33,32,[],Fs,'twosided')

Page 639: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 639/798

7-356

pwelch

Algorithm pwelch calculat es th e power spectr a l density using Welch’s method (seereferences):

1 The input signal vector x is divided int o k overla pping segment s a ccordingt o window a nd noverlap (or their d efault va lues).

2 The specified (or default) window is applied to each segment of x .

3 An nfft -point F FT is applied to th e windowed da ta .

0 100 200 300 400 500 600 700 800 900−34

−32

−30

−28

−26

−24

−22

Frequency (Hz)

P o w e r

S p e c

t r a l D e n s

i t y ( d B / H z )

Welch PSD Estimate

Page 640: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 640/798

7-357

4 The (modified) periodogram of each windowed segment is computed.

5 The set of modified periodogra ms is a vera ged to form t he spectr um estima teS (e j ω).

6 The resulting spectrum estima te is scaled t o compute t he power spectra ldensity a s , wh ere F is :- 2π w hen you do not supply the sa mpling frequency- fs wh en you supply the sa mpling frequency

S e j ω( ) F ⁄

pwelch

The number of segments k t h a t x is divided into is ca lcula ted a s:

• Eight if you don’t specify window , or if you specify it a s t he empty vector []

• if you s pecify window a s a nonempty vector or a sca lar

In this equat ion, m is the length of th e signal vector x , o is th e number ofoverlapping sa mples ( noverlap ), an d l is the length of each segment (thewindow length).

See Also pburg , pcov , peig , periodogram , pmcov , pmtm, pmusic , psdplot , pyulear

References [1] H a yes, M., Stat is t ica l Di gi ta l Signal Processin g and M odel i ng , J ohn Wiley& Sons, 1996.

[2] St oica, P ., an d R.L. Moses, In t r oduct ion to Spectr a l Anal ysis , Pr entice-Ha ll,E nglew ood C liffs, NJ , 1997, pp. 52-54.

[3] Welch, P .D, “The U se of Fa st F ourier Tra nsform for t he Es tima tion of PowerSpectr a : A Meth od Ba sed on Time Averag ing Over Sh ort, ModifiedPeriodograms,” I EE E Tr ans. Au di o El ectr oacousti cs , Vol. AU-15 (J un e 1967),pp. 70-73.

k m o –l o –

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

Page 641: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 641/798

7-358

pyulear

7pyulearPurpose E stima te t he pow er spectr a l density using t he Yule-Wa lker AR meth od

Syntax Pxx = pyulear(x,p)[Pxx,w] = pyulear(x,p,nfft)[Pxx,f] = pyulear(x,p,nfft,fs)

[Pxx,f] = pyulear(x,p,nfft,fs,' range ')[Pxx,w] = pyulear(x,p,nfft,' range ')pyulear(...)

Description Pxx = pyulear(x,p) implements the Yule-Walker algorithm, a parametricspectral estima tion method, and r eturns Pxx , an estimat e of the power spectra ldensity (P SD ) of the vector x . The ent ries of x represent sa mples of adiscrete-time signa l. p is the int eger specifying th e order of an a utoregressive(AR) prediction model for t he signa l, used in estima ting t he P SD .

The pow er spectra l density is calculat ed in units of pow er per ra dia ns persa mple. Real-va lued input s produce full power one-sided (in frequ ency) P SD s(by defa ult), wh ile complex-va lued input s produce tw o-sided P SD s.

In genera l , the length of the F FT an d t he values of the input x determine thelength of Pxx a nd t he ra nge of the corresponding norma lized frequencies. Forth is synt a x, the (defau lt) FFT length is 256. The follow ing t a ble indicat es thelength of Pxx a nd t he ra nge of the corresponding norma lized frequencies forth is syntax.

Table 7-37: PSD Vector Characteristics for an FFT Length of 256 (Default)

Page 642: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 642/798

7-359

[Pxx,w] = pyulear(x,p) a lso returns w, a vector of frequencies at wh ich t heP SD is es t imat ed. Pxx a nd w ha ve the sam e length . The units for frequency a rera d/sa mple.

g ( )

Real/ ComplexInput Data

Length of Pxx Range of the CorrespondingNormalized Frequencies

Rea l-va lued 129 [0,π

]

Complex-va lued 256 [0, 2 π)

pyulear

[Pxx,w] = pyulear(x,p,nfft) uses the Yule-walker method to estimate theP SD wh ile specifying the length of the FF T with the int eger nfft . If y ou specifynfft a s th e empty vector [] , it a dopts th e defa ult va lue of 256.

The lengt h of Pxx a nd t he frequency ran ge for wdepend on nfft and the valuesof the input x . The follow ing t a ble indica tes t he length of Pxx a nd t he frequencyrange for w for this synta x.

[Pxx,f] = pyulear(x,p,nfft,fs) uses the sampling frequency fs specifieda s a n integer in hertz (Hz) to compute the P SD vector ( Pxx ) an d thecorr esponding vector of frequ encies ( f ). In t his case, th e units for th e frequencyvector a re in H z. The spectr a l density produced is ca lcula ted in u nits of power

per Hz. If you specify fs a s the empty vector [] , the sa mpling frequencydefaults t o 1 Hz.

The frequency range for f depends on nfft , fs , an d th e values of the input x .The lengt h of Pxx is the same as in Ta ble 7-38 . The follow ing t a ble indicat es the

Table 7-38: PSD and Frequency Vector Characteristics

Real/ ComplexInput Data

nfft Even/ Odd Length of Pxx Range of w

Rea l-va lued E ven (nfft/2 + 1) [0, π]

Rea l-va lued Odd (nfft + 1)/2 [0, π)C om plex-va lued E ven or odd nfft [0, 2 π)

Page 643: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 643/798

7-360

frequency ra nge for f for this synt a x.

Table 7-39: PSD and Frequency Vector Characteristics with fs Specified

Real/ Complex Input Data nfft Even/ Odd Range of f

Rea l-va lued E ven [0,fs/2]

Rea l-va lued Odd [0,fs/2)

Complex-va lued E ven or odd [0,fs)

pyulear

[Pxx,f] = pyulear(x,p,nfft,fs,' range ') or

[Pxx,w] = pyulear(x,p,nfft,' range ') specifies t he ra nge of frequencyva lues to include in f or w. This synt a x is useful w hen x is real. ' range ' can beeither:

• 'twosided' : Compute the tw o-sided PS D over th e frequency ra nge [0,fs) .This is the defa ult for determining t he frequency ra nge forcomplex-valued x.- If y ou specify fs a s t he empty vector, [] , the frequency ran ge is [0,1) .- If y ou don’t specify fs , the frequency ran ge is [0, 2 π).

• 'onesided' : Compute t he one-sided P SD over th e frequency ra nges specifiedfor rea l x . This is the defa ult for determining t he frequency ra nge forreal-valued x .

Note You can put the str ing ar gument ' range ' a nyw here in the inputargument l i s t a f ter p.

pyulear(...) plots the power spectral density in the current figure window.

The frequency ra nge on t he plot is t he sa me as t he ra nge of out put w (or f ) fora given set of pa ra meters.

Remarks The pow er spectr a l density is computed a s th e distribut ion of pow er per unitfrequency

Page 644: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 644/798

7-361

frequency.

This a lgorith m depends on your selecting a n a ppropriat e model order for yoursignal.

Examples B eca use the Yule-wa lker method estimat es the spectra l density by fi t t ing a nAR prediction model of a given order t o the signa l, first genera te a signa l froma n AR (a ll-pole) model of a given order. You can use freqz to check th ema gnitu de of the frequ ency response of your AR filter. This w ill give you a nidea of wh a t t o expect when you estima te the P SD using pyulear .

a = [1 -2.2137 2.9403 -2.1697 0.9606]; % AR filter coefficientsfreqz(1,a) % AR filter frequency responsetitle('AR System Frequency Response')

pyulear

Now generat e the input signa l x by filtering wh ite noise th rough th e AR filter.Est imat e the PS D of x based on a fourth-order AR prediction model, since inthis case, we know t ha t t he original AR system model a has o rder 4.

randn('state',1);x = filter(1,a,randn(256,1)); % AR system output

pyulear(x,4) % Fourth-order estimate

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−200

−150

−100

−50

0

50

100

Normalized Frequency ( ×πrad/sample)

P h a s e

( d e g r e e s

)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−20

−10

0

10

20

30

40

Normalized Frequency ( ×πrad/sample)

M a g n

i t u d e

( d B )

AR System Frequency Response

20

25Yule−Walker PSD Estimate

Page 645: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 645/798

7-362

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−25

−20

−15

−10

−5

0

5

10

15

Normalized Frequency ( ×πrad/sample)

P o w e r

S p e c

t r a l D e n s

i t y ( d B / r a

d / s a m p

l e )

pyulear

Algorithm Linea r prediction filters can be used to model the second-order sta tist ica lchar a cteristics of a signa l. The prediction filter output ca n be used to model th esignal w hen the input is w hite noise.

pyulear estima tes t he P SD of a n input s igna l vector using the Yule-Wa lker ARmeth od. This meth od, also ca lled the a ut ocorrelat ion or wind owed meth od, fitsa n a utoregressive (AR) linear prediction filter model to the signa l byminimizing t he forw a rd prediction error (ba sed on a ll observat ions of the in putsequence) in th e lea st sq ua res sense. This formulat ion leads t o theYule-Wa lker equa tions, w hich a re solved by th e Levinson-Dur bin recursion.The spectra l estima te retur ned by pyulear is the squared ma gnitude of thefrequency response of this AR model.

See Also aryule , lpc , pburg , pcov , peig , periodogram , pmcov , pmtm, pmusic , prony ,psdplot , pwelch

References [1] Ma rple, S .L., Di gi ta l Spectr a l An alysis , P rentice-Ha ll, 1987, Cha pter 7.

[2] St oica, P ., a nd R .L. Moses, In t r oduct ion to Spectr a l Anal ysis , Pr entice-Ha ll,1997.

Page 646: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 646/798

7-363

rc2ac

7rc2acPurpose Convert reflection coefficients t o an a utocorrela tion sequence

Syntax r = rc2ac(k,r0)

Description r = rc2ac(k,r0) finds t he a ut ocorrela tion coefficients, r , of th e out put of the

discret e-tim e prediction error filter from t he la tt ice-form reflection coefficientsk and initial zero-lag autocorrelation r0 .

Examples k = [0.3090 0.9800 0.0031 0.0082 -0.0082];r0 = 0.1;a = rc2ac(k,r0)

a =0.1000

-0.0309-0.0791

0.07870.0294

-0.0950

See Also ac2rc , poly2ac , rc2poly

References [1] Ka y, S .M., M odern Spectr a l Est im at ion , P rent ice-Ha ll, Englewood Cliffs,NJ , 1988.

Page 647: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 647/798

7-364

rc2is

7rc2isPurpose Convert reflection coefficients t o inverse sine para meters

Syntax isin = rc2is(k)

Description isin = is2rc(k) returns a vector of inverse sine parameters isin from a

vector of r eflection coefficient s k .

Examples k = [0.3090 0.9801 0.0031 0.0082 -0.0082];isin = rc2is(k)

isin =

0.2000 0.8728 0.0020 0.0052 -0.0052

See Also is2rc

References [1] Deller, J .R., J .G. P roakis, a nd J .H.L. Ha nsen, “ D i scr ete-Ti m e Pr ocessi ng of Speech Si gnal s ,” P rent ice-H a ll, 1993.

Page 648: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 648/798

7-365

rc2lar

7rc2larPurpose Convert reflection coefficient s to log a rea r a tio para meters

Syntax g = rc2lar(k)

Description g = rc2lar(k) returns a vector of log a rea ra tio pa ra meters g from a vector of

reflection coefficient s k .

Examples k = [0.3090 0.9801 0.0031 0.0082 -0.0082];g = rc2lar(k)

g =0.6389 4.6002 0.0062 0.0164 -0.0164

See Also lar2rc

References [1] Deller, J .R., J .G. P roakis, a nd J .H.L. Ha nsen, “D i scr ete-Ti m e Pr ocessi n g of Speech Si gnal s ,” P rent ice-H a ll, 1993.

Page 649: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 649/798

7-366

rc2poly

7rc2polyPurpose Convert reflection coefficients to a prediction filter polynomial

Syntax a = rc2poly(k)[a,efinal] = rc2poly(k,r0)

Description a = rc2poly(k) converts the reflection coefficients k corresponding to t hela tt ice structur e to the prediction filter polynomial a , wi th a(1) = 1 . The out puta is row vector of length length(k)+1 .

[a,efinal] = rc2poly(k,r0) retur ns t he final prediction error efinal basedon th e zero-lag a utocorrela tion, r0 .

Example Consider a lat tice IIR filt er given by reflection coefficients k .

k = [0.3090 0.9800 0.0031 0.0082 -0.0082];

It s equivalent prediction filter representa tion is given by

a = rc2poly(k)

a =1.0000 0.6148 0.9899 0.0000 0.0032 -0.0082

Algorithm rc2poly computes output a using Levinson’s r ecursion [1]. The fu nct ion:

1 Set s th e output vector a to th e first element of k

2 Loops through t he rema ining element s of k

For ea ch loop itera tion i , a = [a + a(i-1:-1:1)*k(i) k(i)] .

Page 650: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 650/798

7-367

3 Implements a = [1 a]

See Also ac2poly , latc2tf , latcfilt , poly2rc , rc2ac , rc2is , rc2lar , tf2latc

References [1] Ka y, S .M., M odern Spectr a l Est im at ion , P rent ice-Ha ll, Englewood Cliffs,NJ , 1988.

rceps

7rcepsPurpose Real cepstrum a nd m inimum pha se reconstruction

Syntax y = rceps(x)[y,ym] = rceps(x)

Description The r eal cepstr um is the inverse Fourier tra nsform of the rea l logar ithm of th ema gnitude of the Fourier t ra nsform of a sequence.

rceps(x) retur ns th e real cepstrum of the real sequence x . The rea l cepst rumis a r eal-va lued function.

[y,ym] = rceps(x) returns both t he real cepstrum y and a minimum phasereconst ructed version ym of the input sequence.

Algorithm rceps is a n M-file implement a tion of algorithm 7.2 in [2], th a t is,

y = real(ifft(log(abs(fft(x)))));

Appropriat e windowing in t he cepstra l doma in forms t he reconstructedminimum phase signal.

w = [1; 2*ones(n/2-1,1); ones(1 - rem(n,2),1); zeros(n/2-1,1)];ym = real(ifft(exp(fft(w.*y))));

See Also cceps , fft , hilbert , icceps , unwrap

References [1] Oppenheim, A.V., a nd R.W. S cha fer, Di gital Si gnal Pr ocessin g , E nglewoodCliffs, NJ , P rent ice-Ha ll, 1975.

Page 651: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 651/798

7-368

[2] Pr ogram s for Di gital Signal Pr ocessin g, IE EE P ress, New York, 1979.

rectpuls

7rectpulsPurpose G enera te a sam pled a periodic recta ngle

Syntax y = rectpuls(t)y = rectpuls(t,w)

Description y = rectpuls(t) returns a continuous, aperiodic, unity-height rectangularpulse a t t he sample t imes indica ted in arr ay t , cent ered about t = 0 and wi th adefau lt w idth of 1. Note tha t t he interva l of non-zero a mplitude is defined to beopen on t he right, tha t is , rectpuls(-0.5) = 1 while rectpuls(0.5) = 0 .

y = rectpuls(t,w) genera tes a r ecta ngle of widt h w.

rectpuls is typically used in conjunction with the pulse train generatingfunction pulstran .

See Also chirp , cos , diric , gauspuls , pulstran , sawtooth , sin , sinc , square , tripuls

Page 652: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 652/798

7-369

rectwin

7rectwinPurpose Compute a rectan gular w indow

Syntax w = rectwin(n)

Description w = rectwin(n) returns a recta ngular w indow of length n in t he column

vector w. This function is provided for completeness; a r ecta ngula r w indow isequiva lent t o no window a t a l l .

Algorithm w = ones(n,1);

See Also barthannwin , bartlett , blackman , blackmanharris , bohmanwin , chebwin ,gausswin , hamming , hann , kaiser , nuttallwin , triang , tukeywin , window

References [1] Oppenheim, A.V., a nd R.W. S cha fer. D i scr ete-Ti m e Si gnal Pr ocessing .U pper Sa ddle River, NJ : P rent ice-H a ll, 1999, pp. 468-471.

Page 653: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 653/798

7-370

remez

7remezPurpose Compute the Parks-McClellan optimal 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 Parks-McClellana lgorith m [1]. The Pa rks-McClella n a lgorith m uses the Remez excha ngea lgorithm a nd Ch ebyshev approximation theory to design fil ters with a noptima l fit betw een the desired and a ctua l frequency responses. The filters a reoptima l in th e sense tha t t he ma ximum error betw een t he desired frequencyresponse an d th e actua l frequency response is minimized. Filters designed thisway exhibit an equiripple behavior in their frequency responses and aresometimes called equir ipple filters. remez exhibits discontinuit ies a t the h eada nd t a il of its impulse response due to this equiripple nat ure.

b = remez(n,f,a) retur ns row vector b containing th e n+1 coefficient s of th eorder n FIR filter whose frequency-amplitude characteristics match thosegiven by vectors f a nd

Page 654: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 654/798

7-371

given by vectors f a nd a .

The out put filter coefficient s (ta ps) in b obey the symmetry relation

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

remez

Vectors f a nd a specify the frequency-ma gnit ude char a cteristics of the filter:

• f is a vector of pairs of normalized frequency points, specified in the ra ngebetw een 0 and 1, where 1 corresponds to th e Nyquist frequency. Thefrequencies must be in increa sing order.

• a is a vector conta ining t he desired amplitud es at th e point s specified in f .

The desired am plitude a t freq uencies betw een pairs of point s ( f (k ), f (k + 1)) fork odd is the line segment connecting t he point s ( f (k ), a (k )) and(f (k + 1), a (k + 1)).

The desired am plitude a t frequ encies betw een pairs of point s ( f (k ), f (k + 1)) fork even is un specified. The a rea s betw een such points a re tr a nsition or “don’tcare” r egions.

• f a nd a must be the sam e length. The length must be an even number.

The relat ionship betw een the f a nd a vectors in defining a desired frequencyresponse is shown in t he example below .

1.0Desired amplitude

response ( a )

0.5

f = [0 .3 .4 .6 .7 .9]a = [0 1 0 0 .5 .5]

Page 655: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 655/798

7-372

remez a lwa ys uses an even fi lter order for configurat ions w ith a passba nd a tth e Nyquist frequency. This is beca use for odd orders, t he frequency responsea t t he Nyquist frequ ency is necessar ily 0. If you specify an odd-va lued n , remez increments i t by 1.

0.0

Normalizedfrequency ( f )

"Don't care"/transition regions

0.1 0.2 0.3 0.4 0.5 0.6 0.70.0 0.8 0.9 1.0 (Nyquist)

remez

remez(n,f,a,w) uses the w eights in vector w to weight t he fi t in each frequencyba nd. The length of w is ha lf the length of f a nd a , so there is exactly one weightper band .

b = remez(n,f,a,' ftype ') a nd

b = remez(n,f,a,w,' ftype ') specify a filter t ype, where ' ftype ' is• 'hilbert' , for linear-pha se filters w ith odd symmet ry (ty pe III a nd t ype IV)

The out put coefficient s in b obey th e relat ion b (k ) = -b (n + 2-k ), k = 1, . .. ,n + 1. This class of f il ters includes the Hilbert tra nsformer, which has adesired amplitu de of 1 a cross th e ent ire ba nd.

For example,h = remez(30,[0.1 0.9],[1 1],'hilbert');

designs a n a pproximate FI R H ilbert tra nsformer of length 31.

• 'differentiator' , for t ype III a nd t ype IV fi l ters, using a specia l weightingtechnique

For nonzero a mplitude ban ds, it w eights th e error by a fa ctor of 1/ f so tha tthe error a t low frequencies is much sma ller t ha n a t high frequencies. ForFIR differentia tors, which ha ve an a mplitude chara cterist ic proportional t ofrequency, these filters minimize the ma ximum relat ive error (th e maximumof the ra tio of the error t o the desired am plitude).

b = remez(...,lgrid) uses the integer lgrid to cont rol the density of thefrequency grid, wh ich h a s roughly (lgrid*n)/(2*bw) frequency points, w herebw is th e fra ction of th e tota l frequency ba nd int erval [0,1] covered by f .

Page 656: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 656/798

7-373

bw is th e fra ction of th e tota l frequency ba nd int erval [0,1] covered by f .Increasing lgrid often results in f i l ters tha t more exactly ma tch a n equiripplefilter, but t ha t t a ke longer to compute. The default va lue of 16 is the minimumva lue tha t sh ould be specified for lgrid . Note tha t the lgrid argument mustbe a 1-by-1 cell ar ra y.

b = remez(n,f,' fresp ',w) retur ns row vector b conta ining the n+1 coefficient s of th e order n FIR filter w hose frequency-a mplitude cha ra cteristicsbest a pproxima te t he response specified by function fresp . The fun ction iscalled from within remez with the following synta x.

[dh,dw] = fresp (n,f,gf,w)

remez

The ar gument s ar e simila r to those for remez :

• n is th e filter order.• f is the vector of norma lized frequency band edges th a t a ppea r monotonica lly

betw een 0 a nd 1, wh ere 1 is the Nyquist frequency.• gf

is a vector of grid points t ha t h a ve been linearly int erpola ted over eachspecified frequ ency ban d by remez . gf determines the frequency grid atwh ich t he response function must be eva luat ed, and conta ins the sa me dat areturned by cremez in the fgrid field of th e opt structure.

• w is a vector of real, positive weight s, one per ba nd, used dur ing optimizat ion.w is optional in t he call to remez ; if not specified, it is set to unit y w eightingbefore being passed t o fresp .

• dh a nd dw a re the desired complex frequency response a nd ba nd w eightvectors, respectively, eva lua ted a t ea ch frequency in grid gf .

The predefined freq uency response fun ction fresp t h a t remez calls is remezfrf in the signal/private directory.

b = remez(n,f,' fresp ',p1,p2,...,w) a llow s you to specify add itiona lpara meters ( p1 , p2 , etc.) to pa ss t o fresp . Note tha t b = remez(n,f,a,w) is asynonym for b = remez(n,f,'remezfrf',a,w) , where a is a vector

cont a ining th e desired am plitudes at th e point s specified in f .

b = remez(n,f,' fresp ',w,' ftype ') a nd

b = remez(n,f,' fresp ',p1,p2,...,w,' ftype ') design a ntisymmetric(odd) ra th er th a n sym metric (even) filters, wh ere ' ftype ' is either 'd' for adifferentiator or 'h' for a Hilbert t ra nsformer

Page 657: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 657/798

7-374

differentiator or 'h' for a Hilbert t ra nsformer.

In th e absence of a specifica tion for ftype , a prelimina ry call is made to fresp to determine the default symmetry property sym . This call is ma de using th esyntax.

sym = fresp ('defaults',n,f,[],w,p1,p2,...)

The arguments n , f , w, etc., ma y be used as n ecessary in determining a na ppropriat e va lue for sym , wh ich remez expect s t o be eith er 'even' or 'odd' . I ft he fresp function does not support th is ca lling synta x, remez default s to evensymmetry.

remez

[b,delta] = remez(...) returns t he ma ximum ripple height in delta .

[b,delta,opt] = remez(...) returns a structure w ith t he following fields.

Example G ra ph the desired an d a ctua l frequency responses of a 17th -orderP a rks-McClellan bandpa ss fi l ter.

f = [0 0.3 0.4 0.6 0.7 1]; a = [0 0 1 1 0 0];b = remez(17,f,a);[h,w] = freqz(b,1,512);plot(f,a,w/pi,abs(h))legend('Ideal','remez Design')

opt.fgrid Frequ ency grid vector used for th e filter design optimiza tion

opt.des Desired frequency r esponse for each point in opt.fgrid

opt.wt Weighting for each point in opt.fgrid

opt.H Actua l frequency response for ea ch point in opt.fgrid

opt.error Err or a t ea ch point in opt.fgrid (opt.des-opt.H )

opt.iextr Vector of indices int o opt.fgrid for extr ema l frequencies

opt.fextr Vector of extremal frequencies

1.2

1.4Idealremez Design

Page 658: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 658/798

7-375

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

remez

Algorithm remez is a ME X-file version of the origina l Fort ra n code from [1], a ltered t odesign arbitra ri ly long fil ters with a rbitra ri ly ma ny l inea r bands.

remez designs type I , II , III , a nd IV linea r-phase fi lters. Type I a nd t ype II a rethe defaults for n even a nd n odd, respectively, w hile type II I ( n even) an dt y pe I V (n odd) a re obta ined with t he 'hilbert' a nd 'differentiator' flags.

The different t ypes of filters ha ve different sy mmetr ies a nd cert a in const ra intson th eir freq uency r esponses (see [5] for more det a ils).

Diagnostics If you get th e following w a rning message,

-– Failure to Converge -–

Probable cause is machine rounding error.

it is possible tha t t he filter design ma y st ill be correct. Verify the design bychecking it s fr equency response.

See Also butter , cheby1 , cheby2 , cremez , ellip , fir1 , fir2 , fircls , fircls1 , firls ,firrcos gremez remezord yulewalk

Linear PhaseFilter Type

FilterOrder

Symmetry of Coefficients Response H(f),f = 0

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

Type I E ven even: No rest r ict ion No rest r ict ion

Type I I Odd No rest r ict ion H (1) = 0Type I I I E ven 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 659: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 659/798

7-376

firrcos , gremez , remezord , yulewalk

References [1] Pr ogram s for Di gital Signal Pr ocessin g, IE EE P ress, New York, 1979,Algorith m 5.1.

[2] Selected Paper s in Di gital Signal Pr ocessin g, II , IEE E P ress, New York,1979.

[3] P a rks, T.W., an d C .S. B urru s, Di gi ta l F i l ter D esign , J ohn Wiley & Sons,New York:, 1987, p. 83.

remez

[4] Ra biner, L.R., J .H. McClella n, a nd T.W. Pa rks, “FIR D igita l Filter DesignTechniques Using Weighted Chebyshev Approximations,” Proc. IE EE 63(1975).

[5] Oppenheim, A.V., a nd R.W. S cha fer, D i scr ete-Ti m e Si gnal Pr ocessi ng ,P rent ice-H a ll, E nglew ood Cliffs, NJ , 1989, pp. 256-266.

Page 660: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 660/798

7-377

remezord

7remezordPurpose Parks-McClellan optimal FIR filter order estimation

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 a mplitudes, an d w eights t ha t meetinput specifica tions f , a , and dev .

• f is a vector of frequency ba nd edges (betw een 0 a nd f s /2, w here f s i s thesampling frequency), and a is a vector specifying t he desired a mplitude onthe ba nds defined by f . The leng th of f is tw o less tha n t wice the length of a .The desired fun ction is piecewise const a nt .

• dev is a vector t he same size as a tha t specifies the ma ximum allowa bledeviat ion or ripples betw een the frequency response and th e desiredamplitude of the output filter for each band.

U se remez wit h t he result ing order n , frequen cy vect or fo , am plitude responsevector ao , and w eights w to design th e filter b wh ich a pproximately meets thespecifications given by remezord input para meters f , a , and dev .

b = remez(n,fo,ao,w)

[n,fo,ao,w] = remezord(f,a,dev,fs) specifies a sa mpling frequency fs .fs defa ults to 2 Hz, implying a Nyq uist frequency of 1 Hz. You can t hereforespecify ban d edges sca led to a par ticular a pplica tion’s sa mpling frequency.

In some ca ses remezord underestima tes t he order n . If t he filter does not meet

Page 661: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 661/798

7-378

th e specifica tions, try a higher order such a s n+1 or n+2 .

c = remezord(f,a,dev,fs,' cell ') generates a cell-array whose elementsare the para meters to remez .

Examples Exa mple 1Design a m inimum-order lowpa ss f i lter w ith a 500 Hz pa ssband cutofffrequency an d 600 Hz stopband cutoff frequency, wit h a sam pling frequency of2000 Hz, a t leas t 40 dB a t tenuat ion in the s topband, and less than 3 dB ofripple in the pa ssband.

remezord

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);freqz(b,1,1024,fs);title('Lowpass Filter Designed to Specifications');

−1000

−800

−600

−400

−200

0

P h a s e

( d e g r e e s

)

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

−80

−60

−40

−20

0

20

Frequency (Hz)

M a g n

i t u d e

( d B )

Lowpass Filter Designed to Specifications

Page 662: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 662/798

7-379

Note tha t t he fil ter falls slightly short of meeting the stopband a tt enuat ion a ndpa ssba nd ripple specifica tions. Usin g n+1 in the call to remez instead of n achieves the desired amplitude characteristics.

Exa mple 2Design a lowpa ss fil ter with a 1500 Hz pa ssband cutoff frequency a nd 2000 Hzstopba nd cutoff frequency, with a sam pling frequency of 8000 Hz, a ma ximumstopba nd a mplitude of 0.1, a nd a ma ximum passband error (ripple) of 0.01.

0 100 200 300 400 500 600 700 800 900 1000−1200

Frequency (Hz)

remezord

[n,fo,ao,w] = remezord([1500 2000],[1 0],[0.01 0.1],8000 );b = remez(n,fo,ao,w);

This is equiva lent t o

c = remezord( [1500 2000],[1 0],[0.01 0.1],8000,'cell');b = remez(c:);

Note In some cases, remezord underest ima tes or overestima tes the order n . I fth e filter does not m eet the specifica tions, try a higher order such as n+1or n+2 .

Results a re inaccura te if the cut off frequencies are nea r 0 or th e Nyquistfrequency.

Algorithm remezord uses th e a lgorith m suggest ed in [1]. This meth od is inaccura te forba nd edges close to eith er 0 or t he Nyqu ist frequency ( fs/2 ).

See Also buttord , cheb1ord , cheb2ord , ellipord , kaiserord , remez

References [1] Ra biner, L.R., a nd O. Herrm a nn, “The P redicta bility of Certa in OptimumFinit e Impulse Response Digita l Filters,” IE EE T ran s. on Cir cui t Theory ,Vol. CT-20, No. 4 (J uly 1973), pp. 401-408.

[2] Ra biner, L.R., an d B . G old. Th eory and Appl i cat ion of Di gi ta l Si gnal Processing . En glew ood Cliffs, NJ : Pr ent ice-H a ll, 1975, pp. 156-157.

Page 663: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 663/798

7-380

resample

7resamplePurpose Cha nge sampling ra te by a ny ra t ional fa ctor

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) resa mples the sequence in vector x a t p/q t imes theoriginal sampling ra te, using a polyphase fi l ter implementa tion. p a nd q mustbe posit ive int egers. The lengt h of y is equa l to ceil(length(x)*p/q) . I f x is amatr ix , resample w orks dow n t he columns of x .

resample applies an anti-aliasing (lowpass) FIR filter to x during theresa mpling process. It d esigns the filter using firls with a Ka iser window.

y = resample(x,p,q,n) uses n terms on either side of th e current sa mple,x(k) , to perform t he resa mpling. The length of th e FIR filter resample uses isproportional t o n ; larg er values of n provide better a ccura cy at th e expense ofmore comput a tion t ime. The defa ult for n is 10. If you let n = 0 , resample performs a nea rest-neighbor interpola tion

y(k) = x(round((k-1)*q/p)+1)where y(k) = 0 if the index to x i s great er than length(x).

y = resample(x,p,q,n,beta) uses beta a s the design para meter for theKa iser window t hat resample employs in d esigning t he low pas s filter. Thedefault for beta is 5.

Page 664: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 664/798

7-381

y = resample(x,p,q,b) filters x using the vector of filter coefficients b .

[y,b] = resample(x,p,q) returns the vector b , which conta ins thecoefficients of the filter a pplied t o x during t he resam pling process.

resample

Examples Resa mple a s imple linear sequence at 3/2 the origina l ra te.

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')

Notice that the la st few points of the output y a re inaccura te. In i ts f i l teringprocess, resample a ssumes the samples at t imes before an d a fter the given

−0.5 0 0.5 1 1.5−0.5

0

0.5

1

1.5

Time

originalresampled

Page 665: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 665/798

7-382

sa mples in x a re equa l to zero. Thus la rge deviat ions from zero a t t he end

points of the sequence x can ca use inaccura cies in y a t it s end points. Thefollowin g tw o plots illust ra te t his side effect of resample .

x = [1:10 9:-1:1]; y = resample(x,3,2);subplot(2,1,1);plot(1:19,x,'*',(0:28)*2/3 + 1,y,'o');title('Edge Effects Not Noticeable');legend('original','resampled');

resample

x = [10:-1:1 2:10]; y = resample(x,3,2);subplot(2,1,2);plot(1:19,x,'*',(0:28)*2/3 + 1,y,'o')title('Edge Effects Very Noticeable');legend('original','resampled');

Algorithm resample performs a n FI R design using firls , follow ed by rat e cha ngingimplemented wit h upfirdn .

See Also decimate , downsample , firls , interp , interp1 , intfilt , kaiser , spline ,upfirdn upsample

0 5 10 15 200

2

4

6

8

10Edge Effects Not Noticeable

originalresampled

0 5 10 15 200

5

10

15 Edge Effects Very Noticeable

originalresampled

Page 666: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 666/798

7-383

upfirdn , upsample

residuez

7residuezPurpose z -transform partial-fraction expansion

Syntax [r,p,k] = residuez(b,a)[b,a] = residuez(r,p,k)

Description residuez converts a discrete time system, expressed as t he ra tio of tw opolynomials, to par tia l fraction expa nsion, or residue, form. It a lso converts t hepar tia l fra ction expan sion ba ck to the origina l polynomial coefficient s.

[r,p,k] = residuez(b,a) finds t he residues, poles, and direct terms of apar tia l fraction expa nsion of the ra tio of tw o polynomials, b (z ) a nd a (z ).Vectors b a nd a specify the coefficients of the polynomials of the discrete-timesystem b (z ) / a (z ) in descendin g powers of z .

If th ere are no multiple roots a nd a > n-1 ,

The ret urn ed column vector r cont a ins t he residues, column vector p containsth e pole locat ions, a nd r ow vector k cont a ins th e direct t erms. The number ofpoles is

n = length(a)-1 = length(r) = length(p)

The dir ect t erm coefficient vector k is empty if length(b) is less tha nlength(a) ; otherwise

b z ( ) b 0 b 1 z 1– b 2 z 2– L b m z m –+ + + +=

a z ( ) a 0 a 1 z 1– a 2 z 2– L a n z n –+ + + +=

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

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

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

Page 667: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 667/798

7-384

g ( ) ;

length(k) = length(b) - length(a) + 1I f p(j) = ... = p(j+s-1) is a pole of multiplicity s , then t he expa nsionincludes terms of th e form

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

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

r j s r 1–+( )

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

residuez

[b,a] = residuez(r,p,k) with three input a rguments a nd tw o outputa rguments, converts t he part ial fra ction expansion ba ck to polynomia ls wit hcoefficients in row vectors b a nd a .

The residue function in the st a nda rd MATLAB langua ge is very similar t oresiduez . It computes the pa rt ial fra ction expansion of cont inuous-time

syst ems in t he La place doma in (see reference [1]), ra th er th a n discrete-timesystems in the z -domain a s does residuez .

Algorithm residuez a pplies sta nda rd MATLAB functions an d pa rtia l fraction techniquesto find r , p , and k from b a nd a . I t f inds

• The direct terms a using deconv (polynomia l long division) w henlength(b) > length(a)-1 .

The poles using p = roots(a) .• Any repeat ed poles, reordering th e poles a ccording t o th eir mult iplicities.• The residue for each nonrepeating pole p i by multiplying b (z )/a (z ) by

1/(1 - p i z -1) an d evaluat ing the result ing ra tional function a t z = p i .• The residues for the repeated poles by solving

S2*r2 = h - S1*r1

for r2 using \ . h is t he impulse response of t he reduced b (z ) / a (z ), S1 is ama tr ix whose column s a re impulse responses of the first-order systems m a deup of the nonrepea ting r oots, a nd r1 is a column conta ining t he residues forthe n onrepea ting roots. E a ch column of ma trix S2 is a n impulse response.For ea ch root p j of multiplicity s j, S2 contains s j columns representing t heimpulse responses of ea ch of the followin g sys tems.

1 1 1

Page 668: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 668/798

7-385

The vector h and mat r ices S1 a nd S2 have n + xtra rows, where n i s the tota lnumber of roots and the interna l para meter xtra , set to 1 by defau lt,determines t he degree of overdeterm ina tion of th e system of equa tions.

See Also convmtx , deconv , poly , prony , residue , roots , ss2tf , tf2ss , tf2zp , zp2ss

1

1 p j z 1–

----------------------- 1

1 p j z 1–

–( )2

------------------------------- L 1

1 p j z 1––( )s j

--------------------------------, , ,

residuez

References [1] Oppenheim, A.V., a nd R.W. S cha fer, Di gital Si gnal Pr ocessin g ,P rent ice-H a ll, Eng lewood Cliffs, NJ , 1975, pp. 166-170.

Page 669: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 669/798

7-386

rlevinson

7rlevinsonPurpose Compute th e reverse Levinson-Dur bin r ecursion

Syntax r = rlevinson(a,efinal)[r,u] = rlevinson(a,efinal)[r,u,k] = rlevinson(a,efinal)[r,u,k,e] = rlevinson(a,efinal)

Description The r everse L evinson-Dur bin recursion implements th e st ep-down a lgorithmfor solving t he following sy mmetr ic Toeplitz syst em of linear equa tions for r ,where r = [ r (1) L r (p+ 1) ] a nd r (i )* denotes the complex conjugate of r (i ).

r = rlevinson(a,efinal) solves the a bove system of equa tions for r givenvector a , where a = [1 a (2) L a (p + 1)]. In linea r prediction a pplicat ions, r represents t he a ut ocorrelat ion sequence of th e input t o the prediction errorfilter, where r(1) is th e zero-la g element . The figure below shows th e ty pica l

filter of this ty pe, wh ere H (z ) is th e optima l linear predictor, x (n ) is t he inputsignal, is the predicted signal, a nd e (n ) is the prediction error.

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

Page 670: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 670/798

7-387

In put vector a represent s t he polynomial coefficients of this prediction err orfilter in d escending powers of z.

A z ( )

A z ( ) 1 a 2( ) z 1– L a n 1+( ) z p –+ + +=

rlevinson

The filter must be minimum pha se to genera te a va lid aut ocorrelat ionsequence. efinal is the scala r prediction error power, which is equa l to theva ria nce of the prediction error signa l, σ2(e ).

[r,u] = rlevinson(a,efinal) re turns upper t r iangular mat r ix U from t heU D U * decomposition

where

a nd E is a dia gona l mat rix with elements returned in output e (see below ). Thi sdecomposition permits t he efficient evalua tion of the inverse of thea utocorrelation ma trix, R -1 .

Output ma tr ix u cont a ins th e prediction filter polynomia l, a , from eachitera tion of t he reverse Levinson-Dur bin recursion

R 1–

U E 1–

U ∗=

R

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

r 2( ) r 1( ) L r p 1–( )∗

M O O Mr p ( ) L r 2( ) r 1( )

=

U

a 1 1( )∗a 2 2( )∗L a p 1+ p 1+( )∗

0 a 2 1( )∗O a p 1+ p ( )∗

0 0 O a p 1+ p 1–( )∗

M O O M

=

Page 671: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 671/798

7-388

wh ere a i ( j ) is th e j th coefficient of th e i th ord er prediction filter polynomia l (i.e.,step i in t he recursion). For exa mple, the 5th order prediction filter polynomialis

a5 = u(5:-1:1,5)'

Note tha t u(p+1:-1:1,p+1)' is the input polynomial coefficient vector a .

0 L 0 a p 1+ 1( )∗

rlevinson

[r,u,k] = rlevinson(a,efinal) returns a vector k of length (p + 1) containingthe reflection coefficients. The reflection coefficients are the conjugates of thevalues in th e first row of u .

k = conj(u(1,2:end))

[r,u,k,e] = rlevinson(a,efinal) retur ns a vector of length p + 1 conta iningth e prediction errors from each it era tion of the reverse Levinson-Dur binrecursion: e(1) is t he prediction error from t he first -order model, e(2) i s theprediction error from the second-order model, and so on.

These prediction error values form t he dia gonal of the ma tr ix E in the U D U * decomposition of R -1.

See Also levinson , lpc , prony , stmcb

References [1] Ka y, S .M., M odern Spectr a l Est im at ion: Th eory an d Appl i cat ion ,P rent ice-Ha ll, Englew ood C liffs, NJ , 1988.

R 1–

U E 1–

U ∗=

Page 672: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 672/798

7-389

rooteig

7rooteigPurpose Estimate frequency and power content using the eigenvector method

Syntax [w,pow] = rooteig(x,p)[f,pow] = rooteig(...,fs)[w,pow] = rooteig(...,' corr ')

Description [w,pow] = rooteig(x,p) estimat es the frequency content in th e t ime sa mplesof a signa l x , and re turns w, a vector of frequencies in r a d/sa mple, and th ecorresponding signa l pow er in t he vector pow in dB per ra d/sa mple. The inputs ignal x is specified eith er a s:

• A row or column vector r epresentin g one observat ion of th e signa l• A recta ngular a rra y for w hich each row of x represents a sepa ra te

observa tion of th e signal (for exa mple, each row is one output of a n a rra y ofsensors, a s in a rra y processing), such tha t x'*x is an estima te of thecorrelation ma trix

Note You ca n use t he output of corrmtx to generate such a n a rray x .

You can specify th e second input a rgument p a s either:

• A scala r integer. In t his case, the signa l subspace dimension is p .• A tw o-element vector. In th is case, p(2) , th e second element of p , represent s

a thr eshold tha t is multiplied by λmin , the sma llest est imat ed eigenvalue ofthe signal’s correlation matrix. Eigenvalues below the threshold λmin *p(2) a re assign ed to the noise subspa ce. In th is ca se, p(1) specifies t he ma ximumdimension of th e signa l subspace.

Page 673: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 673/798

7-390

The extr a t hreshold para meter in th e second ent ry in p provides you moreflexibility a nd cont rol in a ssigning t he noise and sign a l subspa ces.

The lengt h of th e vector w is th e computed dimension of th e signa l subspace.For real-valued input da ta x , th e length of the corresponding power vector pow is given by

length(pow) = 0.5*length(w)

For complex-va lued input da ta x , pow a nd w ha ve the same length .

rooteig

[f,pow] = rooteig(...,fs) retur ns t he vector of frequencies f calculatedin Hz. You supply th e sampling frequency fs in H z. If y ou specify fs wi th theempty vector [] , the sa mpling frequency defau lts t o 1 Hz.

[w,pow] = rooteig(...,' corr ') forces the input argument x to beinterpreted as a correlation mat rix ra ther tha n a ma trix of signa l data . For this

synta x, you must supply a squ a re mat rix for x , an d a ll of its eigenva lues mustbe nonnegative.

Note You ca n pla ce th e string ' corr ' anyw here af ter p.

Examples Find th e frequency cont ent in a signa l composed of thr ee complex exponent ia lsin noise. Use t he modified covaria nce meth od to estima te t he correla tionma tr ix used by the eigenvector meth od.

randn('state',1); n=0:99;s = exp(i*pi/2*n)+2*exp(i*pi/4*n)+exp(i*pi/3*n)+randn(1,100);

% Estimate correlation matrix using modified covariance method.

X=corrmtx(s,12,'mod');

[W,P] = rooteig(X,3)

W =0.78111.57671.0554

P =3.9971

Page 674: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 674/798

7-391

3.99711.13621.4102

Algorithm The eigenvector met hod used by rooteig i s the same a s tha t used by peig . Thea lgorith m performs eigenspace a na lysis of the signa l’s correla tion ma tr ix inorder to estima te th e signal’s frequency content .

rooteig

The differ ence betw een peig a nd rooteig is :

• peig returns the pseudospectrum a t a l l frequency samples.• rooteig returns t he estimat ed discrete frequency spectrum, a long w ith t he

corresponding signa l power estima tes.

rooteig is most useful for frequency estima tion of signa ls ma de up of a su m ofsinusoids embedded in a ddit ive white G a ussian noise.

See Also corrmtx , peig , pmusic , rootmusic

Page 675: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 675/798

7-392

rootmusic

7rootmusicPurpose Est imat e frequency a nd power content using the root MU SIC a lgorithm

Syntax [w,pow] = rootmusic(x,p)[f,pow] = rootmusic(...,fs)[w,pow] = rootmusic(...,' corr ')

Description [w,pow] = rootmusic(x,p) estimat es the frequency content in th e t imesa mples of a signal x , and re turns w, a vector of frequ encies in ra d/sa mple, an dth e corresponding signa l power in t he vector pow in d B per ra d/sa mple. Theinput signal x is specified eith er a s:

• A row or column vector r epresent ing one observa tion of th e signa l• A recta ngular a rra y for w hich each row of x represents a separa te

observat ion of the signa l (for exam ple, each row is one output of a n a rra y ofsensors, a s in a rra y processing), such tha t x'*x is an estima te of thecorrelation ma trix

Note You ca n use t he output of corrmtx to generate such a n a rray x .

The second input a rgum ent, p is th e number of complex sinusoids in x. You ca nspecify p a s either:

• A scala r integer. In t his case, the signa l subspace dimension is p .• A tw o-element vector. I n t his ca se, p(2) , th e second element of p , represent s

a thr eshold tha t is multiplied by λmin , th e smallest est ima ted eigenva lue ofthe signal’s correlation matrix. Eigenvalues below the threshold λmin *p(2) a re assign ed to the noise subspa ce. In th is ca se, p(1) specifies t he ma ximumdimension of th e signa l subspace

Page 676: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 676/798

7-393

dimension of th e signa l subspace.

The extr a t hreshold pa ra meter in th e second ent ry in p provides you moreflexibility a nd cont rol in a ssigning th e noise a nd signa l subspa ces.

The lengt h of th e vector w is th e computed dimension of the signa l subspace.For real-valued input da ta x , t he length of the corresponding pow er vector pow is given by

length(pow) = 0.5*length(w)

rootmusic

For complex-va lued input d a ta x , pow a nd w ha ve the same length .

[f,pow] = rootmusic(...,fs) retur ns t he vector of frequencies f calculatedin Hz. You supply th e sampling frequency fs in H z. If y ou specify fs wi th theempty vector [] , the sa mpling frequency defaults to 1 Hz.

[w,pow] = rootmusic(...,' corr ') forces t he input a rgument x to beinterpreted as a correlation matr ix ra ther tha n a ma trix of signa l data . For thissynta x, you must supply a squa re mat rix for x , an d a ll of its eigenva lues mustbe nonnegative.

Note You ca n pla ce th e string ' corr ' anyw here af ter p.

Examples Find th e frequency cont ent in a signa l composed of thr ee complex exponent ialsin noise. Use t he modified cova ria nce meth od to estima te th e correlat ionma trix used by the MUS IC a lgorithm.

randn('state',1); n=0:99;s = exp(i*pi/2*n)+2*exp(i*pi/4*n)+exp(i*pi/3*n)+randn(1,100);

% Estimate correlation matrix using modified covariance method.

X=corrmtx(s,12,'mod');[W,P] = rootmusic(X,3)

W =1.57690.78171.0561

Page 677: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 677/798

7-394

P = 1.13583.99751.4102

Algorithm The MUS IC a lgorithm used by rootmusic i s the same as tha t used by pmusic .The a lgorith m performs eigenspace ana lysis of the signa l’s correla tion ma tr ixin order to estima te th e signal’s frequency content .

rootmusic

The d ifference betw een pmusic a nd rootmusic is :

• pmusic returns t he pseudospectrum a t a l l frequency samples.• rootmusic returns t he estimat ed discrete frequency spectrum, a long w ith

the corresponding signal power estimates.

rootmusic is most useful for frequency estima tion of signa ls ma de up of a su mof sinusoids embedded in a ddit ive white G a ussian noise.

Diagnostics If the input signal, x is real a nd a n odd number of sinusoids, p is specified, th iserror message is displayed

Real signals require an even number p of complex sinusoids.

See Also corrmtx , peig , pmusic , rooteig

Page 678: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 678/798

7-395

sawtooth

7sawtoothPurpose G enerat e a sa wt ooth or t r iangle wa ve

Syntax x = sawtooth(t)x = sawtooth(t,width)

Description sawtooth(t) genera tes a sa wt ooth w a ve with period 2 π for t he element s oftime vector t . sawtooth(t) is similar t o sin(t) , but creat es a saw tooth w avew ith pea ks of -1 and 1 inst ead of a sine w a ve. The sa w tooth w a ve is defined tobe -1 at mult iples of 2 π a nd t o increa se l inearly w ith t ime with a slope of 1/ π a ta ll other t imes.

sawtooth(t,width) genera tes a modified tr ia ngle wa ve where width , a scalarpara meter betw een 0 a nd 1, determines the point betw een 0 a nd 2 π at whichth e ma ximum occurs. The function increas es from -1 to 1 on t he int erval 0 to2π*width , th en decreases linear ly from 1 to -1 on t he interva l 2 π*width t o 2 π.Thus a para meter of 0.5 specifies a sta nda rd t r iangle wa ve, symmetric aboutt ime ins ta nt π w ith peak-to-peak a mplitude of 1. sawtooth(t,1) is equiva lentt o sawtooth(t) .

See Also chirp , cos , diric , gauspuls , pulstran , rectpuls , sin , sinc , square , tripuls

Page 679: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 679/798

7-396

schurrc

7schurrcPurpose Compute r eflection coefficient s from a n a ut ocorrela tion sequ ence

Syntax k = schurrc(r)[k,e] = schurrc(r)

Description k = schurrc(r) uses the S chur a lgorith m t o comput e a vector k of reflectioncoefficient s from a vector r representing an autocorrelation sequence. k a nd r a re th e sam e size. The reflection coefficient s represent t he lat tice pa ra metersof a prediction filter for a signa l wit h t he given a ut ocorrela tion sequence, r .When r i s a mat r ix, schurrc tr eat s each column of r a s a n independentautocorrelation sequence, and produces a matrix k , the sa me size as r . Ea chcolumn of k represents t he reflection coefficients for t he la tt ice filter forpredictin g th e process w ith th e corresponding a utocorrela tion sequence r .

[k,e] = schurrc(r) a lso comput es the sca lar e , the prediction error var ian ce.When r i s a ma tr ix , e is a row vector. The lengt h of e is the same as t he numberof column s of r .

Examples Cr eat e an a ut ocorrelat ion sequence from t he MATLAB speech signa l cont a inedin mtlb.mat , a nd use t he Schur a lgorithm t o compute th e reflection coefficientsof a la tt ice prediction filter for this a ut ocorrelat ion sequence.

load mtlbr = xcorr(mtlb(1:5),'unbiased');k = schurrc(r(5:end))

k =-0.7583

0.13840.7042

-0.3699

Page 680: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 680/798

7-397

See Also levinson

References [1] P roakis, J . an d D . Man olakis, Di gital Signa l Pr ocessin g: Pr in cipl es,Al gor i thm s, and Appl icat ions , Thir d edit ion, P rent ice-H a ll, 1996, pp. 868-873.

seqperiod

7seqperiodPurpose Compute t he period of a sequence

Syntax p = seqperiod(x)[p,num] = seqperiod(x)

Description p = seqperiod(x) returns t he integer p th a t corresponds to the period of th esequence in a vector x . The period p is computed a s th e minimum length of asubsequence x(1:p) of x th a t repeat s itself cont inuously every p sa mples in x .The lengt h of x does not ha ve to be a mult iple of p , so tha t a n incompleterepetition is permitt ed at th e end of x . If th e sequence x is not periodic, thenp = length(x) .

• I f x i s a ma tr ix , then seqperiod checks for periodicity a long each column of x .The resulting output p is a row vector with th e same num ber of columns a s x .

• I f x is a multidimensiona l arra y, then seqperiod checks for periodicity a longth e first nonsingleton dimension of x . In th is ca se:

- p is a m ultidimensiona l ar ra y of integers with a lead ing singletondimension.

- The length s of the rema ining dimensions of p correspond t o th ose of t hedimensions of x after the first nonsingleton one.

[p,num] = seqperiod(x) a lso returns t he number num of repetitions of x(1:p) in x . num might not be an integer.

Examples x = [4 0 1 6;2 0 2 7;4 0 1 5;2 0 5 6];

p = seqperiod(x)

Page 681: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 681/798

7-398

p = seqperiod(x)p =

2 1 4 3

seqperiod

The resu lt im plies:

• The firs t column of x ha s period 2.• The second column of x ha s period 1.• The t hir d column of x is not periodic, so p(3) is just th e number of row s of x .• The fourt h column of x ha s period 3, alt hough t he la st (second) repetition of

th e periodic sequence is incomplete.

Page 682: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 682/798

7-399

sgolay

7sgolayPurpose Savitzky-Golay filter design

Syntax b = sgolay(k,f)b = sgolay(k,f,w)[b,g] = sgolay(...)

Description b = sgolay(k,f) designs a Sa vitzky-G olay FIR smoothing fi lter b . Thepolynomial order k must be less tha n t he frame size, f , wh ich must be odd. Ifk = f-1 , th e designed filter produces no smooth ing. The output , b , is a n f -by-f ma tr ix whose row s represent th e time-va rying F IR filter coefficients. In asmooth ing filter implementa tion (for example, sgolayfilt ), th e last (f-1)/2 rows (each an FIR fi l ter) a re applied to the signal during the sta rtup t ra nsient,and the f i rs t (f-1)/2 rows ar e applied to the signa l during the terminaltra nsient. The center row is applied to the signal in th e steady st at e.

b = sgolay(k,f,w) specifies a weight ing vector w with length f , wh ichcont a ins th e real, positive-va lued weights t o be used during t he lea st-squa resminimization.

[b,g] = sgolay(...) [returns th e mat rix g of different iat ion filters. Ea chcolumn of g is a different ia tion filter for deriva tives of order p-1 wh ere p is thecolumn index. G iven a signa l x of lengt h f , you can find a n estimat e of the p t h

order derivative, xp , of its middle va lue from:

xp((f+1)/2) = (factorial(p)) * g(:,p+1)' * x

Remarks Sa vitzky-G ola y smooth ing filters (a lso called digita l smooth ing polynomialfilters or least squa res smooth ing filters) a re typically used to “smooth out” anoisy signa l wh ose frequency span (with out noise) is lar ge. In t his t ype ofapplication, Savitzky-Golay smoothing filters perform much better than

sta nda rd a vera ging FIR fil ters which t end to fil ter out a significan t portion of

Page 683: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 683/798

7-400

sta nda rd a vera ging FIR fi l ters, which t end to f il ter out a significan t port ion ofth e signal’s high frequency content a long w ith t he noise. Alth oughSa vitzky-G ola y filters ar e more effective at preserving th e pertinent highfrequency components of the signal, they are less successful than standarda veraging FI R fi l ters at rejecting n oise.

Sa vitzky-Golay fi l ters are optima l in the sense tha t t hey minimize thelea st-squa res error in f i t t ing a polynomial t o ea ch frame of noisy da ta .

sgolay

Example U se sgolay to smooth a noisy sinusoid and display t he result a nd th e first a ndsecond deriva tives.

N = 4;F = 21;[b,g]=sgolay(N,F);x=5*sin(.4*pi*0:.2:199);y=x+randn(1,996); % Noisy sinusoid

for n = (F+1)/2:996-(F+1)/2,% Zero-th order derivative (equivalent to sgolayfilt except% that it doesn't compute transients)

z0(n)=g(:,1)'*y(n - (F+1)/2 + 1: n + (F+1)/2 - 1)';% 1st order derivative

z1(n)=g(:,2)'*y(n - (F+1)/2 + 1: n + (F+1)/2 - 1)';% 2nd order derivative

z2(n)=2*g(:,3)'*y(n - (F+1)/2 + 1: n + (F+1)/2 - 1)';end

plot([x(1:length(z0))',y(1:length(z0))',z0'])legend('Noiseless sinusoid','Noisy sinusoid',...'Smoothed sinusoid')figure

plot([diff(x(1:length(z0)+1))',z1'])legend('Noiseless first-order derivative',...'Smoothed first-order derivative')figureplot([diff(diff(x(1:length(z0)+2)))',z2'])legend('Noiseless second-order derivative',...'Smoothed second-order derivative')

Page 684: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 684/798

7-401

Note The figures below a re zoomed t o show more deta il.

sgolay

140 160 180 200 220−6

−4

−2

0

2

4

6

Noiseless sinusoidNoisy sinusoidSmoothed sinusoid

Zero-th order

−2

0

2

4

6

Noiseless sinusoidNoisy sinusoid

Smoothed sinusoid

First derivative

Page 685: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 685/798

7-402

140 160 180 200 220−6

−4

sgolay

See Also fir1 , firls , filter , sgolayfilt

References [1] Orfa nidis, S.J ., I nt r odu cti on to Signal Pr ocessin g , P rent ice-Ha ll, Englew oodCliffs, NJ , 1996.

40 60 80 100 120 140 160 180 200 220

−0.25

−0.2

−0.15

−0.1

−0.05

0

0.05

0.1

0.15

0.2

0.25Noiseless second−order derivativeSmoothed second−order derivative

Second derivative

Page 686: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 686/798

7-403

sgolayfilt

7sgolayfiltPurpose Sa vitzky-G ola y fi ltering

Syntax y = sgolayfilt(x,k,f)y = sgolayfilt(x,k,f,w)y = sgolayfilt(x,k,f,w,dim)

Description y = sgolayfilt(x,k,f) a pplies a Sa vitzky-G olay FIR smoothing fi lter t o theda ta in vector x . I f x i s a mat r ix, sgolayfilt operates on each column. Thepolynomial order k must be less tha n t he frame size, f , wh ich must be odd. Ifk = f-1 , th e filter produces no smoothing.

y = sgolayfilt(x,k,f,w) specifies a weight ing vector w with length f , whichcont a ins th e real, positive-va lued weights t o be used during t he lea st-squa resminimiza tion. If w is not specified or if it is specified as empt y, [], wdefaults to

an ident i ty ma tr ix .

y = sgolayfilt(x,k,f,w,dim) specifies the dimension, dim , along which th efilter operat es. If dim is not s pecified, sgolayfilt operates along the firstnon-singleton dimension; th a t is, dimension 1 for column vectors a ndnontr ivial ma tr ices, and d imension 2 for row vectors.

Remarks Sa vitzky-G ola y smooth ing filters (a lso called digita l smooth ing polynomial

filters or lea st-squa res smooth ing filters) a re typically used t o “smooth out” anoisy signa l wh ose frequency span (with out noise) is lar ge. In t his t ype ofapplication, Savitzky-Golay smoothing filters perform much better thansta nda rd a vera ging FIR fi l ters, which t end to f il ter out a significan t port ion ofth e signal’s high frequency content a long w ith t he noise. Alth oughSa vitzky-G ola y filters ar e more effective at preserving th e pertinent highfrequency components of the signal, they are less successful than standarda veraging FI R fi l ters at rejecting n oise.

Sa vitzky-Golay fil ters are optima l in the sense tha t t hey minimize the

Page 687: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 687/798

7-404

Sa vitzky Golay fi l ters are optima l in the sense tha t t hey minimize thelea st-squa res error in f i t t ing a polynomial t o frames of noisy da ta .

Example Smooth t he mtlb signal by a pplying a cubic Sa vitzky-G olay fi lter t o dat aframes of length 41.

load mtlb % Load the data.smtlb = sgolayfilt(mtlb,3,41); % Apply the 3rd-order filter.

sgolayfilt

subplot(2,1,1)plot([1:2000],mtlb(1:2000)); axis([0 2000 -4 4]);title('mtlb'); grid;

subplot(2,1,2)plot([1:2000],smtlb(1:2000)); axis([0 2000 -4 4]);title('smtlb'); grid;

See Also medfilt1 , filter , sgolay , sosfilt

References [1] Orfa nidis, S.J ., I nt r odu cti on to Signal Pr ocessin g , P rent ice-Ha ll, Englew oodCliffs, NJ , 1996.

0 500 1000 1500 2000−4

−2

0

2

4mtlb

0 500 1000 1500 2000−4

−2

0

2

4smtlb

Page 688: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 688/798

7-405

sinc

7sincPurpose Sinc fun ction

Syntax y = sinc(x)

Description sinc comput es the sinc function of an in put vector or arr a y, wh ere the sincfunction is

This function is the cont inuous inverse Fourier tra nsform of th e recta ngula rpulse of widt h 2 π and heigh t 1.

y = sinc(x) r etu rns an a r ray y the sa me size as x , wh ose elements a re thesinc function of the elements of x .

The space of functions ba ndlimited in th e frequency ra nge is

spa nned by t he infinite (yet counta ble) set of sinc functions shifted by int egers.Thus a ny such ba ndlimited function g (t ) can be reconstruct ed from its sa mplesa t int eger spacings.

Example P erform ideal bandlimited interpolat ion by a ssuming tha t t he signa l to beinterpolat ed is 0 outside of the given t ime interval a nd t ha t i t ha s been sa mpled

sinc t ( )1 t 0=,

πt ( )sinπt

------------------- t 0≠,=

sinc t ( )1

2π------ e j ωt ωd

π–

π

∫ =

ω π– π[ , ]∈

g t ( ) g n ( ) sinc t n –( )

n ∞–=

∑=

Page 689: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 689/798

7-406

p g pa t exactly the Nyquist frequency.

t = (1:10)'; % A column vector of time samplesrandn('state',0);x = randn(size(t)); % A column vector of data

ts = linspace(-5,15,600)'; % times at which to interpolate data

y = sinc(ts(:,ones(size(t))) - t(:,ones(size(ts)))')*x;

sinc

plot(t,x,'o',ts,y)

See Also chirp , cos , diric , gauspuls , pulstran , rectpuls , sawtooth , sin , square ,tripuls

−5 0 5 10 15−2

1.5

−1

0.5

0

0.5

1

1.5

2

Page 690: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 690/798

7-407

sos2cell

7sos2cellPurpose Convert a second-order section ma tr ix to cell a rra ys

Syntax c = sos2cell(m)c = sos2cell(m,g)

Description c = sos2cell(m) chan ges a n L -by-6 second -order section m a t rix mgenerated

by tf2sos int o a 1-by- L cell a rra y of 1-by-2 cell ar ra ys c . You can use c t ospecify a qua ntized fi lter w ith L cascaded second-order sections.

The ma tr ix m should ha ve the form

m = [b1 a1;b2 a2; ... ;bL aL]

wh ere both bi a nd ai , wi th i = 1, ..., L , a re 1-by-3 row vectors. The r esult ing c is a 1-by- L cell a rra y of cells of the form

c = b1 a1 b2 a2 ... bL aL

c = sos2cell(m,g) with the optiona l gain term g , prepends the const a ntvalue g t o c . When you use the a dded gain term in t he comma nd, c is a 1-by- L cell array of cells of the form

c = g,1 b1,a1 b2,a2...bL,aL

Examples U se sos2cell to convert th e 2-by-6 second-order section m a tr ix produced bytf2sos int o a 1-by-2 cell ar ra y c of cells. Display th e second entry in th e firstcell in c .

[b,a] = ellip(4,0.5,20,0.6);m = tf2sos(b,a);c = sos2cell(m);c12

ans =1 0000 0 1677 0 2575

Page 691: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 691/798

7-408

1.0000 0.1677 0.2575

See Also tf2sos , cell2sos

sos2ss

7sos2ssPurpose Convert d igita l filter second-order section par a meters t o sta te-space form

Syntax [A,B,C,D] = sos2ss(sos)[A,B,C,D] = sos2ss(sos,g)

Description sos2ss converts a second-order section representa tion of a given digita l filter

to a n equivalent sta te-space representa tion.

[A,B,C,D] = sos2ss(sos) converts t he system sos , in second-order sectionform, to a single-input, sin gle-output sta te-spa ce representa tion.

The discrete transfer function in second-order section form is given by

sos is a L -by-6 ma tr ix orga nized a s

The en tr ies of sos must be real for proper conversion t o sta te spa ce. Thereturned ma tr 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, a nd D i s a scalar.

[A,B,C,D] = sos2ss(sos,g) convert s the syst em sos in second -order sectionform ith ga in g

x n 1+[ ] A x n [ ] B u n [ ]+=

y n [ ] C x n [ ] D u n [ ]+=

H z ( ) H k z ( )

k 1=∏

b 0 k b 1 k z 1– b 2 k z 2–+ +

1 a 1 k z 1– a 2 k z 2–+ +--------------------------------------------------------- -

k 1=

∏= =

so s

b 01 b 11 b 21 1 a 11 a 21

b 02 b 12 b 22 1 a 12 a 22M M M M M M

b 0 L b 1 L b 2 L 1 a 1 L a 2 L

=

Page 692: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 692/798

7-409

form with ga in g .

H z ( ) g H k z ( )

k 1=∏=

sos2ss

Example Compute t he st a te-space representa tion of a simple second-order sectionsystem 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 11 0 0 00 1 0 00 0 1 0

B =1000

C =21 2 -16 -1

D =-2

Algorithm sos2ss first converts from second-order sections t o tra nsfer fun ction us ingsos2tf , a nd t hen from tra nsfer function t o stat e-space using tf2ss .

See Also sos2tf , sos2zp , ss2sos , tf2ss , zp2ss

Page 693: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 693/798

7-410

sos2tf

7sos2tfPurpose Convert digit a l filter second-order section da ta to tra nsfer function form

Syntax [b,a] = sos2tf(sos)[b,a] = sos2tf(sos,g)

Description sos2tf converts a second-order section representa tion of a given digita l filter

to an equiva lent tra nsfer function representa tion.

[b,a] = sos2tf(sos) returns the numerator coefficients b a nd denomina torcoefficients a of th e tra nsfer function tha t describes a discrete-time syst emgiven by sos in second-order sect ion form. The second-order sect ion forma t ofH (z ) is given by

sos i s an L - by-6 ma tr ix th a t cont a ins t he coefficients of ea ch second-ordersection stored in its rows .

Row vectors b a nd a contain the numerator and denominator coefficients ofH (z ) stored in descending powers of z .

[b a] = sos2tf(sos g) returns t he tra nsfer function tha t describes a

H z ( ) H k

z ( )

k 1=∏b 0 k b 1 k z 1– b 2 k z 2–+ +

1 a 1 k z 1– a 2 k z 2–+ +--------------------------------------------------------- -

k 1=∏= =

so s

b 01 b 11 b 21 1 a 11 a 21

b 02 b 12 b 22 1 a 12 a 22

M M M M M Mb 0 L b 1 L b 2 L 1 a 1 L a 2 L

=

H z ( ) B z ( )A z ( )-----------

b 1 b 2 z 1– L b n 1+ z n –+ + +

a 1

a 2

z 1– L a m 1+

z m –+ + +------------------------------------------------------------------------= =

Page 694: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 694/798

7-411

[b,a] sos2tf(sos,g) returns t he tra nsfer function tha t describes adiscrete-time s yst em given by sos in second-order section form w ith ga in g .

H z ( ) g H k z ( )

k 1=∏=

sos2tf

Example Compute t he tr a nsfer function representa tion of a simple second-order sectionsystem.

sos = [1 1 1 1 0 -1; -2 3 1 1 10 1];[b,a] = sos2tf(sos)

b =

-2 1 2 4 1a =

1 10 0 -10 -1

Algorithm sos2tf uses the conv function to multiply a ll of the num erat or anddenomina tor second-order polynomia ls t ogeth er.

See Also latc2tf , sos2ss , sos2zp , ss2tf , tf2sos , zp2tf

Page 695: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 695/798

7-412

sos2zp

7sos2zpPurpose Convert digita l filter second-order section par a meters to zero-pole-ga in form

Syntax [z,p,k] = sos2zp(sos)[z,p,k] = sos2zp(sos,g)

Description sos2zp converts a second-order section representa tion of a given digita l filter

to a n equ ivalent zero-pole-ga in representa tion.

[z,p,k] = sos2zp(sos) returns the zeros z , poles p , and gain k of th e systemgiven by sos in second-order sect ion form. The second-order sect ion forma t ofH (z ) is given by

sos i s an L -by-6 matrix that contains the coefficients of each second-ordersection in its rows .

Column vectors z a nd p cont a in th e zeros and poles of the tr a nsferfunction H (z ).

where the orders n a nd m a re determined by the ma trix sos .

[z p k] = sos2zp(sos g) returns the zeros z , poles p , and gain k of the

H z ( ) H k z ( )

k 1=

∏b 0 k b 1 k z 1– b 2 k z 2–+ +

1 a 1 k z 1– a 2 k z 2–+ +--------------------------------------------------------- -

k 1=

∏= =

so s

b 01 b 11 b 21 1 a 11 a 21

b 02 b 12 b 22 1 a 12 a 22M M M M M M

b 0 L b 1 L b 2 L 1 a 1 L a 2 L

=

H z ( ) k z z 1–( ) z z 2–( )L z z n –( )

p p 1–( ) p p 2–( )L p p m –( )----------------------------------------------------------------------=

Page 696: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 696/798

7-413

[z,p,k] sos2zp(sos,g) returns the zeros z , poles p , and gain k of thesyst em given by sos in second-order section form w ith ga in g .

H z ( ) g H k z ( )

k 1=∏=

sos2zp

Example Compute t he poles, zeros, a nd ga in of a simple system in second-order sectionform.

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.8660i1.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 section by repeatedlycalling tf2zp .

See Also sos2ss , sos2tf , ss2zp , tf2zp , zp2sos

Page 697: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 697/798

7-414

sosfilt

7sosfiltPurpose Second-order (biqua dra tic) II R digita l filtering

Syntax y = sosfilt(sos,x)

Description y = sosfilt(sos,x) a pplies t he second-order section digita l filter sos to thevector x . The outpu t, y , is the same length a s x .

sos represent s t he second-order section digita l filter H (z )

by an L -by-6 ma tr ix cont a inin g t he coefficient s of each second-order section inits rows.

I f x i s a mat r ix, sosfilt a pplies the filter t o ea ch column of x independently.

Output y is a ma trix of the sa me size, conta ining the fi ltered dat acorresponding to each column of x .

See Also filter , medfilt1 , sgolayfilt

References [1] Orfa nidis, S.J ., I nt r odu cti on to Signal Pr ocessin g , P rent ice-Ha ll, Englew oodCliffs, NJ , 1996.

H z ( ) H k z ( )

k 1=∏

b 0 k b 1 k z 1– b 2 k z 2–+ +

1 a 1 k z 1– a 2 k z 2–+ +--------------------------------------------------------- -

k 1=

∏= =

so s

b 01 b 11 b 21 1 a 11 a 21

b 02 b 12 b 22 1 a 12 a 22M M M M M M

b 0 L b 1 L b 2 L 1 a 1 L a 2 L

=

Page 698: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 698/798

7-415

specgram

7specgramPurpose Time-dependent frequency a na lysis (spectr ogram )

Syntax B = specgram(a)B = specgram(a,nfft)[B,f] = specgram(a,nfft,fs)[B,f,t] = specgram(a,nfft,fs)

B = specgram(a,nfft,fs,window)B = specgram(a,nfft,fs,window,numoverlap)specgram(a)B = specgram(a,f,fs,window,numoverlap)

Description specgram comput es the wind owed discrete-time Fourier tra nsform of a signa lusing a sliding wind ow. The spectrogra m is the ma gnitu de of this function.

B = specgram(a) calculat es the win dowed discrete-time Fourier tra nsform forth e signal in vector a . This syntax uses the default values:

• nfft = min(256,length(a))• fs = 2• window is a periodic Ha nn (Ha nning) window of length nfft .• numoverlap = length(window)/2

nfft specifies th e FFT length t ha t specgram uses. This va lue determines th efrequencies a t w hich the discrete-time Fourier tra nsform is computed. fs is asca lar tha t specifies t he sa mpling frequency. window specifies a w indowingfunction a nd t he number of samples specgram uses in it s sectioning of vect or a .numoverlap is th e number of samples by w hich th e sections overla p. Anya rguments th a t you omit from the end of the input par a meter l ist use thedefault va lues shown a bove.

I f a is real , specgram comput es the discrete-time Fourier tr a nsform a t positivefrequencies only. I f n is even, specgram re turns nfft/2+1 rows (including th ezero a nd Nyq uist frequency terms). If n is odd, specgram returns nfft/2 rows.The n umber of column s in B is

Page 699: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 699/798

7-416

The n umber of column s in B is

k = fix((n-numoverlap)/(length(window)-numoverlap))

I f a is complex, specgram comput es the discrete-time Fourier tra nsform a t bothpositive and n egat ive frequencies. In th is ca se, B is a complex ma trix w ith nfft

specgram

rows. Time increases linea rly a cross t he columns of B, s tar t ing wi th sa mple 1in column 1. Frequency increases l inea rly down t he rows, sta rt ing a t 0.

B = specgram(a,nfft) uses the specified FFT length nfft in its calculations.

[B,f] = specgram(a,nfft,fs) returns a vector f of frequencies a t wh ich t hefunction comput es the discrete-time Fourier t ra nsform. fs ha s no effect on th eoutput B; it is a fr equency sca ling multiplier.

[B,f,t] = specgram(a,nfft,fs) retur ns frequency and t ime vectors f a nd t respectively. t is a column vector of scaled times, wit h length equa l to thenu mber of column s of B. t(j) is the ea rl iest t ime at wh ich th e j th w indow intersects a . t(1) is alwa ys equal to 0.

B = specgram(a,nfft,fs,window) specifies a windowing function a nd t he

num ber of samples per section of the x vector. If you supply a sca lar for window ,specgram uses a H a nn w indow of tha t length. The length of the window mustbe less tha n or equa l to nfft .

B = specgram(a,nfft,fs,window,numoverlap) overla ps t he sections of x bynumoverlap samples.

You can use th e empty ma trix [] to specify the defau lt va lue for any inputa rgument. For example,

B = specgram(x,[],10000)

is equivalent t o

B = specgram(x)

but w ith a sam pling frequency of 10,000 Hz instea d of the default 2 Hz.

specgram(...) with no output a rguments displa ys the scaled logar ithm of thespectrogra m in the current f igure w indow using

imagesc(t f 20*log10(abs(b))) axis xy colormap(jet)

Page 700: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 700/798

7-417

imagesc(t,f,20 log10(abs(b))), axis xy, colormap(jet)

The axis xy mode displa ys t he low-frequency cont ent of th e first portion of thesigna l in t he lower-left corner of th e a xes. specgram uses fs to label the axesaccording to true time and frequency.

specgram

B = specgram(a,f,fs,window,numoverlap) computes the spectrogram a t t hefrequ encies specified in f , using either th e chirp z -tr a nsform (for more th a n 20evenly spa ced frequencies) or a polypha se decima tion filter ba nk. f is a vectorof frequencies in hertz; i t must ha ve at lea st t wo elements.

Example Displa y th e spectr ogram of a digitized speech signal.

load mtlbspecgram(mtlb,512,Fs,kaiser(500,5),475)title('Spectrogram')

Note You can view a nd ma nipulat e a similar spectrogram in t he Signal

P rocessin g Toolbox Demos, which y ou access in from t he MATLAB L a unchP a d .

Time

F r e q u e n c y

Spectrogram

0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.450

500

1000

1500

2000

2500

3000

3500

Page 701: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 701/798

7-418

Algorithm specgram calculat es the spectrogra m for a g iven signa l as follows:

1 It splits the signa l into overlapping sections a nd a pplies the wind ow specified by the window para meter to each section.

specgram

2 It comput es the discrete-time Fourier tra nsform of each section w ith alength nfft FF T to produce an estima te of the short -term frequency cont entof th e signal; th ese tr a nsforms ma ke up th e columns of B. The quant i ty(length(window) - numoverlap) specifies by how ma ny sa mples specgram shifts the window.

3 For real input, specgram trunca tes the spectrogram to the first nfft/2 + 1

points for nfft even a nd (nfft + 1)/2 for nfft odd.

Diagnostics An a ppropriate dia gnostic message is displayed w hen 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 input.

See Also cohere , csd , pwelch , tfe

References [1] Oppenheim, A.V., a nd R.W. Scha fer, D i scr ete-Ti m e Si gnal Pr ocessi ng ,P rent ice-Ha ll, En glewood Cliffs, NJ , 1989, pp. 713-718.

[2] Ra biner, L.R., a nd R.W. Scha fer, D igi tal Pr ocessi ng of Speech Sign al s ,P rent ice-Ha ll, Englew ood C liffs, NJ , 1978.

Page 702: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 702/798

7-419

sptool

7sptoolPurpose Open t he digita l signa l processing G U I (SP Tool)

Syntax sptool

Description sptool opens S P Tool, a gra phical u ser interface (G U I) tha t ma na ges a suite offour other G U Is. These GU Is provide access to ma ny of th e signal, filter, and

spectr a l a na lysis functions in th e toolbox. When you ty pe sptool a t t h ecomma nd line, the follow ing G U I opens.

U sing SP Tool you ca n:

• Ana lyze signa ls l isted in the Signals l ist box wit h th e Signal B rowser• Design or edit filters w ith th e Filter D esigner (includes a P ole/Zero Ed itor)• Ana lyze filter r esponses for filters listed in t he Filters l ist box with the Fil ter

Viewer• Apply filters in th e Filters list box to signa ls in the Signals list box• Creat e and a na lyze signal spectra w ith th e Spectrum Viewer

Page 703: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 703/798

7-420

• P rint t he Signa l Br owser, Fil ter Viewer, Fil ter Designer, and SpectrumViewer

You can activate the four integrated signal processing GUIs from SPTool.

sptool

Signa l Brow serThe Signa l B rowser allows you to view, measure, a nd a na lyze the t ime-domaininforma tion of one or more signa ls. To activa te t he Signa l Br owser, press theView button under the Signals list box in SP Tool.

Filter DesignerThe Filter Designer a llows you to design and edit F IR a nd II R filters of variouslength s and t ypes, with sta nda rd (lowpa ss, highpass, bandpa ss, band stop, andmult iban d) configura tions. To a ctivat e the Filter Designer, press either t heNew button or the Edit button under the Filters list box in S P Tool.

The Filt er Designer h a s a P ole/Zero Ed itor you can a ccess from th e Algorithms pulldown.

Page 704: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 704/798

7-421

sptool

Filter ViewerThe Filter View er a llows you to view th e cha ra cteristics of a designed orimport ed filter, including its m a gnitu de response, pha se response, group delay ,pole-zero plot, impulse response, and step response. To activate the Filter

Viewer, press th e View button under the Filters list box in S P Tool.

Page 705: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 705/798

7-422

sptool

You ca n a na lyze multiple filter responses by checking several response plotoptions, as sh own in th e next figure.

Page 706: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 706/798

7-423

sptool

Spectrum ViewerThe Spectr um View er allows you to graphically a na lyze frequency-domain da tausing a variety of methods of spectral density estimat ion, including th e Bur gmeth od, th e FFT meth od, th e multita per method (MTM), the MU SI Ceigenvector met hod, Welch’s met hod, a nd t he Yule-Wa lker AR meth od. Toa ctiva te t he Spectrum Viewer:

• P ress the Create button under the Spectra list box to comput e th e powerspectr a l density for a signa l selected in th e Signals list box in S P Tool. Youma y need to press Apply to view the spectra .

• P ress the View button t o ana lyze spectra selected under t he Spectra list boxin S P Tool.

• P ress the Update button under the Spectra list box in SP Tool to modify aselected pow er spectra l density signa l.

In ad dit ion, you ca n right -click in a ny plot display a rea of the G U Is t o modifysigna l properties.

Page 707: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 707/798

7-424

S ee Ch a pter 6, “SP Tool: A Signa l Pr ocessing GU I Suit e,” for a fu ll discussion ofhow to use S P Tool.

See Also fdatool

square

7squarePurpose Genera te a square wave

Syntax x = square(t)x = square(t,duty)

Description x = square(t) genera tes a squa re wa ve wit h period 2 π for the elements of

time vector t . square(t) is similar t o sin(t) , but creat es a square wa ve wi thpea ks of ± 1 instea d of a sine wa ve.

x = square(t,duty) genera tes a squa re wa ve with specified dut y cycle, duty .The du ty cycle is th e percent of the period in w hich th e signa l is positive.

See Also chirp , cos , diric , gauspuls , pulstran , rectpuls , sawtooth , sin , square ,tripuls

Page 708: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 708/798

7-425

ss2sos

7ss2sosPurpose Convert digit a l filter st a te-space par a meters t o second-order sections form

Syntax [sos,g] = ss2sos(A,B,C,D)[sos,g] = ss2sos(A,B,C,D,iu)[sos,g] = ss2sos(A,B,C,D,' order ')[sos,g] = ss2sos(A,B,C,D,iu,' order ')

[sos,g] = ss2sos(A,B,C,D,iu,' order ',' scale ')sos = ss2sos(...)

Description ss2sos converts a sta te-spa ce represent a tion of a given digita l filter to a nequiva lent second-order section represent a tion.

[sos,g] = ss2sos(A,B,C,D) f inds a ma tr ix sos in s econd -order s ection formwith gain g tha t is equivalent to the st a te-space system represented by input

arguments A , B, C, and D. The input syst em must be single output a nd rea l. sos i s an L -by-6 ma t rix

wh ose rows conta in t he numera tor a nd denomina tor coefficients b ik a nd a ik oft he second-order sect ions of H (z ).

[sos,g] = ss2sos(A,B,C,D,iu) specifies a scala r iu tha t determines whichinput of the sta te-spa ce syst em A , B, C, D is used in t he convers ion. The defa ultfor iu is 1.

so s

b 01 b 11 b 21 1 a 11 a 21

b 02 b 12 b 22 1 a 12 a 22M M M M M M

b 0 L b 1 L b 2 L 1 a 1 L a 2 L

=

H z ( ) g H k z ( )

k 1=∏ g

b 0 k b 1 k z 1– b 2 k z 2–+ +

1 a 1 k z 1– a 2 k z 2–+ +--------------------------------------------------------- -

k 1=

∏= =

Page 709: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 709/798

7-426

ss2sos

[sos,g] = ss2sos(A,B,C,D,' order ') a nd

[sos,g] = ss2sos(A,B,C,D,iu,' order ') specify th e order of th e rows in sos ,where ' order ' is :

• 'down' , to order th e sections so th e first row of sos cont a ins t he poles closestto th e unit circle

• 'up' , to order t he sections so the first row of sos conta ins t he poles fa rth estfrom th e unit circle (defau lt)

The zeros a re alw a ys pa ired wit h t he poles closest t o them.

[sos,g] = ss2sos(A,B,C,D,iu,' order ',' scale ') specifies the desiredscaling of th e ga in a nd t he num era tor coefficients of all second-order sections,where ' scale ' is :

• 'none' , to a pply no sca ling (defau lt)• 'inf' , to a pply infinity-norm scaling• 'two' , t o apply 2-norm sca ling

U sing infinity-norm scaling in conjunction with up -ordering minimizes t heprobability of overflow in t he rea lizat ion. U sing 2-norm sca ling in conjunctionwi th down -ordering minimizes the peak round-off noise.

sos = ss2sos(...) embeds t he overa ll system ga in, g , in th e first section,H 1(z ), so th a t

Example Find a second-order section form of a B utt erwort h low pas s filter.

[A,B,C,D] = butter(5,0.2);sos = ss2sos(A,B,C,D)

sos =

H z ( ) H k z ( )

k 1=∏=

Page 710: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 710/798

7-427

sos

0.0013 0.0013 0 1.0000 -0.5095 01.0000 2.0008 1.0008 1.0000 -1.0966 0.35541.0000 1.9979 0.9979 1.0000 -1.3693 0.6926

ss2sos

Algorithm ss2sos uses a four-step a lgorith m t o determine t he second-order sectionrepresenta tion for a n input sta te-space system:

1 It finds th e poles and zeros of th e system given by A , B, C, and D.

2 It uses the function zp2sos , wh ich first gr oups the zeros a nd poles intocomplex conjuga te pa irs using t he cplxpair function. zp2sos then forms th esecond-order sections by ma tching t he pole a nd zero pa irs a ccording to t hefollowing rules:a Ma tch t he poles closest t o the unit circle w ith t he zeros closest t o those

poles.

b Ma tch t he poles next closest t o the unit circle w ith t he zeros closest t ot hose poles.

c Continue unti l a l l of th e poles a nd zeros are ma tched.

ss2sos groups real poles int o sections w ith th e real poles closest t o them ina bsolute va lue. The sa me rule holds for rea l zeros.

3 It orders the sections a ccording to th e proximity of the pole pairs t o the unitcircle. ss2sos norma lly orders t he sections w ith poles closest t o the unitcircle las t in t he cascad e. You ca n t ell ss2sos to order t he sections in th ereverse order by specifying t he 'down' flag.

4 ss2sos scales th e sections by t he norm specified in t he ' scale ' argument .For a rbit ra ry H (ω), th e scaling is d efined by

where p can be either ∞or 2. See the references for details. This scaling isa n a tt empt t o minimize overflow or peak round-off noise in fixed point filterimplementations.

Diagnostics If th ere is more tha n one input t o the system, ss2sos gives the following errormessage.

State-space system must have only one input.

H p 1

2π------ H ω( )p ωd

0

2 π

∫ 1p ---

=

Page 711: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 711/798

7-428

State space system must have only one input.

See Also cplxpair , sos2ss , ss2tf , ss2zp , tf2sos , zp2sos

ss2sos

References [1] J a ckson, L.B ., Di gi ta l Fi l ters and Signal Processin g , 3rd ed., KluwerAcademic P ublishers, B oston, 1996. Ch a pter 11.

[2] Mitra , S .K., Di gital Signa l Processin g: A Com put er -Based A ppr oach ,McGr a w-H ill, New York, 1998. Cha pter 9.

[3] Vaidyan a tha n, P .P. ,“Robust Digita l Fil ter Structures,” H and book for Di gital Si gnal Pr ocessin g , S.K. Mitra a nd J .F. Ka iser, ed. , J ohn Wiley & Sons,New York, 1993, Chapter 7.

Page 712: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 712/798

7-429

ss2tf

7ss2tfPurpose Convert sta te-space fil ter par a meters to t ra nsfer function form

Syntax [b,a] = ss2tf(A,B,C,D,iu)

Description ss2tf converts a sta te-spa ce represent a tion of a given syst em to a n equivalenttra nsfer function r epresenta tion.

[b,a] = ss2tf(A,B,C,D,iu) returns t he tra nsfer function

of th e system

from t he iu -th input . Vector a cont a ins t he coefficients of the denomina tor indescendin g pow ers of s . The numera tor coefficients a re return ed in arr a y b wi thas ma ny rows as t here are outputs y . ss2tf a lso works with systems in discretetime, in w hich case i t returns t he z -transform representation.

The ss2tf function is part of the st a nda rd MATLAB langua ge.

Algorithm The ss2tf function uses poly to find the characteristic polynomial det( sI-A )and the equal ity

See Also latc2tf , sos2tf , ss2sos , ss2zp , tf2ss , zp2tf

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

x · A x B u +=

y C x D u +=

H s ( ) C sI A–( ) 1– B det sI A– B C +( ) det sI A–( )–det sI A–( )

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

Page 713: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 713/798

7-430

ss2zp

7ss2zpPurpose Convert sta te-space filter pa ra meters to zero-pole-ga in form

Syntax [z,p,k] = ss2zp(A,B,C,D,i)

Description ss2zp converts a sta te-space representa tion of a given system to a n equivalentzero-pole-gain representation. The zeros, poles, and gains of state-spacesystems represent the transfer function in factored form.

[z,p,k] = ss2zp(A,B,C,D,i) calculat es the t ra nsfer function in fa ctoredform

of the continuous-time s yst em

from th e i th input (using the i th columns of B a nd D). The colum n vector p cont a ins t he pole locat ions of th e denomina tor coefficient s of the t ra nsferfunction. The ma tr ix z conta ins the numera tor zeros in i ts columns, with a sma ny columns as t here are outputs y (row s in C). The colum n v ector k contains

the ga ins for each numera tor tra nsfer function.ss2zp a lso works for discrete time syst ems. The input st a te-spa ce syst em mustbe real.

The ss2zp function is part of the st a nda rd MATLAB langua ge.

Example H ere are tw o wa ys of finding t he zeros, poles, a nd ga ins of a discrete-timetra nsfer function

b [2 3]

H s ( ) Z s ( )P s ( )---------- k

s z 1–( ) s z 2–( )L s z n –( )s p 1–( ) s p 2–( )L s p n –( )------------------------------------------------------------------= =

x · A x B u +=

y C x D u +=

H z ( ) 2 3 z 1–

+

1 0.4 z 1–

z 2–

+ +-----------------------------------------=

Page 714: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 714/798

7-431

b = [2 3];a = [1 0.4 1];[b,a] = eqtflength(b,a);[z,p,k] = tf2zp(b,a)

ss2zp

z =0.0000

-1.5000

p =-0.2000 + 0.9798i-0.2000 - 0.9798i

k =2

[A,B,C,D] = tf2ss(b,a);[z,p,k] = ss2zp(A,B,C,D,1)

z =0.0000

-1.5000

p =-0.2000 + 0.9798i-0.2000 - 0.9798i

k =2

Algorithm ss2zp finds t he poles from the eigenvalues of th e A a rra y. The zeros a re thefinite solutions to a genera lized eigenvalue problem.

z = eig([A B;C D], diag([ones(1,n) 0]);

In ma ny situ at ions t his a lgorithm produces spurious la rge, but f inite, zeros.ss2zp interprets these large zeros as infinite.

ss2zp finds th e gains by solving for th e first n onzero Ma rkov par a meters.

See Also pzmap , sos2zp , ss2sos , ss2tf , tf2zp , zp2ss

References [1] La ub, A.J ., an d B .C. Moore, “Ca lcula tion of Tra nsmission Zeros U sing QZTechniques,” Automat ica 14 (1978), p. 557.

Page 715: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 715/798

7-432

stmcb

7stmcbPurpose Compute a linear model using Steiglitz-McBride itera tion

Syntax [b,a] = stmcb(h,nb,na)[b,a] = stmcb(y,x,nb,na)[b,a] = stmcb(h,nb,na,niter)[b,a] = stmcb(y,x,nb,na,niter)[b,a] = stmcb(h,nb,na,niter,ai)[b,a] = stmcb(y,x,nb,na,niter,ai)

Description St eigli tz-McB ride i tera tion is an a lgorithm for f inding a n II R fi l ter with aprescribed time domain impulse response. It h a s a pplicat ions in both filterdesign a nd syst em ident ifica tion (par a metric modeling).

[b,a] = stmcb(h,nb,na) finds t he coefficient s b a nd a of th e system b (z ) / a (z )

with approximate impulse response h , exactly nb zeros, an d exactly na poles.[b,a] = stmcb(y,x,nb,na) finds t he syst em coefficients b a nd a of th e systemthat, given x as input , has y as output . x a nd y must be the sam e length.

[b,a] = stmcb(h,nb,na,niter) a nd

[b,a] = stmcb(y,x,nb,na,niter) use niter itera tions. The defau lt for niter is 5.

[b,a] = stmcb(h,nb,na,niter,ai) a nd

[b,a] = stmcb(y,x,nb,na,niter,ai) use th e vect or ai as the in it ia l es t imateof the denomina tor coefficients. I f ai is not s pecified, stmcb uses the outputa rgument from [b,ai] = prony(h,0,na) a s the vector ai .

stmcb retur ns t he IIR filt er coefficients in length nb+1 a nd na+1 row vectors b a nd a . The filter coefficient s a re ordered in d escending pow ers 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 716: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 716/798

7-433

stmcb

Example Approximate t he impulse response of a B utt erworth fi lter w ith a system oflow er order.

[b,a] = butter(6,0.2);h = filter(b,a,[1 zeros(1,100)]);freqz(b,a,128)

[bb,aa] = stmcb(h,4,4);

freqz(bb,aa,128)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−600

−500

−400

−300

−200

−100

0

Normalized Frequency ( ×πrad/sample)

P h a s e

( d e g r e e s )

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−300

−250

−200

−150

−100

−50

050

Normalized Frequency ( ×πrad/sample)

M a g n

i t u d e

( d B )

−40

−20

0

20

e ( d e g r e e s

)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−20

−10

0

10

20

30

40

Normalized Frequency ( ×πrad/sample)

M a g n

i t u d e

( d B )

Page 717: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 717/798

7-434

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−100

−80

−60

Normalized Frequency ( ×πrad/sample)

P h a s e

Page 718: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 718/798

strips

7stripsPurpose St rip plot

Syntax strips(x)strips(x,n)strips(x,sd,fs)strips(x,sd,fs,scale)

Description strips(x) plots vector x in horizont a l strips of lengt h 250. If x i s a mat r ix,strips(x) plots each column of x . The left-most column (column 1) is the tophorizonta l st r ip.

strips(x,n) plots vector x in s t r ips tha t a re each n sa mples long.

strips(x,sd,fs) plots vector x in strips of duration sd second s, given asa mpling frequency of fs sa mples per second.

strips(x,sd,fs,scale) scales the vertical axes.

I f x i s a ma tr ix , strips(x,n) , strips(x,sd,fs) , and strips(x,sd,fs,scale) plot th e different columns of x on the sam e strip plot.

strips ignores the ima gina ry pa rt of complex-va lued x .

Example P lot t w o seconds of a frequency modulat ed sinusoid in 0.25 second str 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)

Page 719: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 719/798

7-436

strips

See Also plot , stem

0 0.05 0.1 0.15 0.2 0.25

1.75

1.5

1.25

1

0.75

0.5

0.25

0

Page 720: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 720/798

7-437

tf2latc

7tf2latcPurpose Convert tra nsfer function fi lter pa ra meters to lat t ice fi l ter form

Syntax [k,v] = tf2latc(b,a)k = tf2latc(1,a)[k,v] = tf2latc(1,a)k = tf2latc(b)k = tf2latc(b,’ phase ’)

Description [k,v] = tf2latc(b,a) finds the la t t ice pa ra meters k and the ladderparameters v for a n I IR (ARMA) la tt ice-lad der filter, n ormalized by a(1) . Notetha t a n error is generat ed if one or more of the lat t ice para meters are exactlyequa l to 1.

k = tf2latc(1,a) finds the la t t ice pa ra meters k for a n I IR a ll-pole (AR)lattice filter.

[k,v] = tf2latc(1,a) retur ns t he sca lar la dder coefficient a t t he correctposition in vector v . All other elemen ts of v a re zero.

k = tf2latc(b) finds the la t t ice pa ra meters k for a n F IR (MA) la tt ice filter,normalized by b(1) .

k = tf2latc(b,’ phase ’) specifies t he t ype of FIR (MA) la tt ice filter, w here‘phase’ is• ’max’ , for a ma ximum phase fi lter.• ’min’ , for a minimum pha se filter.

See Also latc2tf , latcfilt , tf2sos , tf2ss , tf2zp

Page 721: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 721/798

7-438

tf2sos

7tf2sosPurpose Convert digit a l filter t ra nsfer function da ta to second-order sections form

Syntax [sos,g] = tf2sos(b,a)[sos,g] = tf2sos(b,a,' order ')[sos,g] = tf2sos(b,a,' order ',' scale ')sos = tf2sos(...)

Description tf2sos converts a tra nsfer function representa tion of a given digita l f i lter t o anequiva lent s econd-order section r epresent a tion.

[sos,g] = tf2sos(b,a) f inds a ma tr ix sos in second -order section form w ithgain g tha t is equiva lent to the digita l f i lter represented by tra nsfer functioncoefficient vectors a a nd b .

sos i s an L -by-6 ma tr ix

whose rows contain the numerator and denominator coefficients b ik a nd a ik oft he second-order sect ions of H (z ).

[sos,g] = tf2sos(b,a,' order ') specifies th e order of th e rows in sos , where' order ' is :

• 'down' , to order th e sections so th e first row of sos cont a ins t he poles closestto th e unit circle

H z ( )B z ( )A z ( )-----------

b 1 b 2 z 1– L b n 1+ z n –+ + +

a 1 a 2 z 1– L a m 1+ z m –+ + +------------------------------------------------------------------------= =

so s

b 01 b 11 b 21 1 a 11 a 21

b 02 b 12 b 22 1 a 12 a 22M M M M M M

b 0 L b 1 L b 2 L 1 a 1 L a 2 L

=

H z ( ) g H k z ( )

k 1=∏ g

b 0 k b 1 k z 1– b 2 k z 2–+ +

1 a 1 k z 1– a 2 k z 2–+ +--------------------------------------------------------- -

k 1=

∏= =

Page 722: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 722/798

7-439

to th e unit circle• 'up' , to order t he sections so the first row of sos conta ins t he poles fa rth est

from th e unit circle (defau lt)

tf2sos

[sos,g] = tf2sos(b,a,' order ',' scale ') specifies t he desired scaling of thega in a nd n umera tor coefficient s of all second-order sections, w here ' scale ' is :

• 'none' , to a pply no scaling (defau lt)• 'inf' , to a pply infinity-norm scaling• 'two' , t o apply 2-norm sca ling

U sing infinity -norm scaling in conjunction w ith up -ordering minimizes t heproba bility of overflow in t he rea lizat ion. U sing 2-norm scaling in conjunctionwi th down -ordering minimizes the peak round-off noise.

sos = tf2sos(...) embeds the overall system gain, g , in th e first section,H 1(z ), so tha t

Algorithm tf2sos uses a four-step a lgorith m t o determine t he second-order sectionrepresenta tion for a n input tra nsfer function system:

1 It finds th e poles and zeros of th e system given by b a nd a .

2 It uses the function zp2sos , wh ich first gr oups the zeros a nd poles intocomplex conjuga te pa irs using t he cplxpair function. zp2sos then forms th esecond-order sections by ma tching t he pole a nd zero pa irs a ccording to t hefollowing rules:

a Ma tch t he poles closest t o the unit circle w ith t he zeros closest t o thosepoles.

b Ma tch t he poles next closest t o the unit circle w ith t he zeros closest t ot hose poles.

c Continue unti l a l l of th e poles a nd zeros are ma tched.

tf2sos groups real poles int o sections w ith th e real poles closest t o them ina bsolute va lue. The sa me rule holds for rea l zeros.

3 It orders the sections a ccording to th e proximity of the pole pairs t o the unitcircle. tf2sos norma lly orders t he sections w ith poles closest t o the unitcircle las t in t he cascad e You ca n t ell tf2sos to order t he sections in th e

H z ( ) H k

z ( )

k 1=∏=

Page 723: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 723/798

7-440

circle las t in t he cascad e. You ca n t ell tf2sos to order t he sections in th ereverse order by specifying t he 'down' flag.

tf2sos

4 tf2sos scales th e sections by t he norm specified in th e ' scale ' argument .For a rbit ra ry H (ω), th e scaling is defined by

where p can be either ∞or 2. See the references for deta ils on th e sca ling.This sca ling is a n a tt empt t o minimize overflow or peak round-off noise infixed point filter implementa tions.

See Also cplxpair , sos2tf , ss2sos , tf2ss , tf2zp , zp2sos

References [1] J a ckson, L.B ., Di gi ta l Fi l ters and Signal Processin g , 3rd ed., KluwerAcademic P ublishers, B oston, 1996, Ch a pter 11.

[2] Mitra , S .K., Di gital Signa l Processin g: A Com put er -Based A ppr oach ,McGr a w-H ill, New York, 1998, Cha pter 9.

[3] Vaidyan a tha n, P .P. , “Robust Digita l Fil ter Structures,” H and book for Di gital Si gnal Pr ocessin g , S.K. Mitra a nd J .F. Ka iser, ed. , J ohn Wiley & Sons,New York, 1993, Chapter 7.

H p 1

2 π------ H ω( )p ωd

0

2 π

∫ 1p ---

=

Page 724: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 724/798

7-441

tf2ss

7tf2ssPurpose Convert tra nsfer function fi l ter pa ra meters to st a te-space form

Syntax [A,B,C,D] = tf2ss(b,a)

Description tf2ss converts t he para meters of a t ra nsfer function representa tion of a givensystem t o those of a n equivalent sta te-space representa tion.

[A,B,C,D] = tf2ss(b,a) re turns the A , B, C, and D ma trices of a st a te spacerepresent a tion for th e single-input t ra nsfer function

in controller canonical form

The in put vector a cont a ins t he denomina tor coefficients in descending pow ersof s . The rows of th e ma tr ix b cont a in t he vectors of numera tor coefficients (ea chrow corresponds to a n output ). In t he discrete-time case, you must supply b a nda to correspond t o the numera tor a nd denominat or polynomia ls wit hcoefficients in descending powers of z .

For discrete-time syst ems you must ma ke b ha ve the sam e number of columnsa s the length of a . You can do th is by padding ea ch numera tor represented in b (a nd possibly t he denominat or represented in t he vector a ) with tra iling zeros.You can use th e function eqtflength to a ccomplish t his if b a nd a a re vectorsof unequa l lengths.

The tf2ss function is part of the st a nda rd MATLAB langua ge.

Example Consider the syst em

H s ( ) B s ( )A s ( )-----------

b 1 s n 1– L b n 1– s b n + + +

a 1 s m 1– L a m 1– s a m + + +------------------------------------------------------------------------ C sI A–( ) 1– B D += = =

x · A x B u +=y C x D u +=

H s ( )

2 s 3+

s 2 2 s 1+ +

s 2 0 4 s 1+ +---------------------------------=

Page 725: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 725/798

7-442

s 0.4 s 1+ +

tf2ss

To convert th is syst em to st a te-space, type

b = [0 2 3; 1 2 1];a = [1 0.4 1];[A,B,C,D] = tf2ss(b,a)

A =-0.4000 -1.0000

1.0000 0

B =10

C =2.0000 3.00001.6000 0

D =01

Note There is disa greement in th e litera tu re on na ming conventions for th ecanonical forms. It is easy, however, to generate similarity transformations

that convert these results to other forms.

See Also sos2ss , ss2tf , tf2sos , tf2zp , zp2ss

Page 726: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 726/798

7-443

tf2zp

7tf2zpPurpose Convert t ra nsfer function filter par a meters t o zero-pole-ga in form

Syntax [z,p,k] = tf2zp(b,a)

Description tf2zp finds th e zeros, poles, a nd ga ins of a t ra nsfer function.

[z,p,k] = tf2zp(b,a) finds th e mat rix of zeros z , t he vector of poles p , and

th e associa ted vector of ga ins k from the t ra nsfer function para meters b a nd a :• The numera tor polynomials a re represented a s columns of the ma tr ix b .• The denomina tor polynomial is r epresented in t he vector a .

G iven a SI MO continuous-time syst em in polynomial tr a nsfer function form

or

you ca n use th e output of tf2zp to produce the s ingle-input, mult ioutput(SI MO) fact ored t ra nsfer function form

or

H s ( ) B s ( )

A s ( )-----------

b 1 s n 1– L b n 1– s b n + + +

a 1 s m 1– L a m 1– s a m + + +------------------------------------------------------------------------= =

H z ( ) B z ( )A z ( )------------

b 1 b 2 z 1– L b n 1– z n – b n z n – 1–+ + +

a 1 a 2 z 1– L a m 1– z m – a m z m – 1–+ + +

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

H s ( ) Z s ( )P s ( )---------- k

s z 1–( ) s z 2–( )L s z m –( )s p 1–( ) s p 2–( )L s p n –( )------------------------------------------------------------------= =

H z ( ) Z z ( )

P z ( )---------- k

z z 1–( ) z z 2–( )L z z m –( )

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

Page 727: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 727/798

7-444

tf2zp

The followin g describes the input a nd output a rgument s for tf2zp :

• The vector a specifies t he coefficients of the denomina tor polynomial A (s )(or A(z )) in d escending powers of s (z -1).

• The i th row of the matr ix b represents t he coefficients of the i th numerat orpolynomial (th e i th r ow of B (s ) or B (z )). Specify a s ma ny r ows of b as therea re outputs.

• For continuous-time syst ems, choose t he n umber n b of column s of b t o be lesstha n or equal to the length n a of the vector a .

• For discrete-time s yst ems, choose the n umber n b of column s of b to be equa lto the length n a of the vector a . You ca n use t he function eqtflength t oprovide equal length vectors in th e ca se tha t b a nd a a re vectors of unequa llengths. Otherwise, pa d the numerat ors in the mat rix b (a nd, possibly, t hedenominat or vector a) with zeros.

The zero locat ions a re retur ned in t he columns of the ma tr ix z , w i th a s manycolumns a s th ere are rows in b .• The pole loca tions a re ret urned in t he column vector p a nd th e gains for each

numerat or t ra nsfer function in t he vector k .

The tf2zp function is part of the st a nda rd MATLAB langua ge.

Example Find th e zeros, poles, and ga ins of the discrete-time syst em

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

[b,a] = eqtflength(b,a); % Make lengths equal.[z,p,k] = tf2zp(b,a) % Obtain the zero-pole-gain form.

H z ( ) 2 3 z 1–

+

1 0.4 z 1–

z 2–

+ +-----------------------------------------=

Page 728: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 728/798

7-445

tf2zp

z =0

-1.5000

p =-0.2000 + 0.9798i-0.2000 - 0.9798i

k =2

See Also sos2zp , ss2zp , tf2sos , tf2ss , zp2tf

Page 729: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 729/798

7-446

tfe

7tfePurpose Est imat e the tra nsfer function from input an d output

Syntax Txy = tfe(x,y)Txy = tfe(x,y,nfft)[Txy,f] = tfe(x,y,nfft,fs)Txy = tfe(x,y,nfft,fs,window)Txy = tfe(x,y,nfft,fs,window,numoverlap)Txy = tfe(x,y,..., ' dflag ')tfe(x,y)

Description Txy = tfe(x,y) finds a tra nsfer function estimat e Txy given input signalvector x a nd output signa l vector y . The tr ansfer fun cti on is the quotient of thecross spectrum of x a nd y a nd t he pow er spectrum of x .

The relat ionship betw een the input x a nd output y is modeled by th e linea r,t ime-invaria nt tra nsfer function Txy .

Vectors x a nd y must be the sam e length. Txy = tfe(x,y) uses t he follow ingdefault va lues:

• nfft = min(256,(length(x))• fs = 2• window is a periodic Ha nn (Ha nning ) w indow of length nfft• numoverlap = 0

nfft specifies th e FFT length t ha t tfe uses. This va lue determines th efrequencies at wh ich t he power spectrum is estimat ed. fs i s a scalar tha tspecifies t he sa mpling frequency. window specifies a w indowing function a ndth e number of sam ples tfe uses in its sectioning of the x a nd y vectors.numoverlap is th e number of samples by w hich th e sections overla p. Anya rguments th a t a re omitted from the end of the para meter l ist use the defa ultvalues shown above.

I f x is real , tfe estima tes th e tra nsfer function a t positive frequencies only; inthis case, the output Txy is a column vector of length nfft/2+1 for nfft even

d ( ff 1)/2 f ff dd If i l f i h f

T x y f ( )P x y f ( )

P x x f ( )---------------=

Page 730: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 730/798

7-447

a nd (nfft+1)/2 for nfft odd. If x or y is complex, tfe estimates the transferfunction for both positive an d nega tive frequencies a nd Txy has length nfft .

tfe

Txy = tfe(x,y,nfft) uses the specified FFT length nfft in est imat ing t hetra nsfer function.

[Txy,f] = tfe(x,y,nfft,fs) returns a vector f of frequencies a t w hich tfe est imat es the tra nsfer function. fs is the sam pling frequency. f is the sa me sizea s Txy , so plot(f,Txy ) plots t he tr a nsfer function estima te versus properlyscaled frequency. fs ha s no effect on t he output Txy ; it is a frequency sca ling

multiplier.

Txy = tfe(x,y,nfft,fs,window) specifies a windowing function and thenumber of sa mples per section of t he x vector. If you supply a sca lar for window ,Txy uses a H a nn w indow of tha t length. The length of the w indow must be lesstha n or equal to nfft ; tfe zero pad s th e sections if the length of th e window exceeds nfft .

Txy = tfe(x,y,nfft,fs,window,numoverlap) overla ps t he sections of x bynumoverlap samples.

You can use t he empty m a trix [] to specify th e defa ult va lue for any inputargument except x or y . For exam ple,

Txy = tfe(x,y,[],[],kaiser(128,5))

uses 256 as t he va lue for nfft a nd 2 as t he value for fs .

Txy = tfe(x,y,...,' dflag ') specifies a detrend option, w here ' dflag ' is :

• 'linear' , to remove the best str a ight-line fit from t he prewindowed sectionsof x a nd y

• 'mean' , to remove the mea n from th e prewindowed sections of x a nd y• 'none' , for no detrend ing (defau lt)

The ' dflag ' para meter must appear last in th e list of input a rguments. tfe

recognizes a ' dflag ' s t r ing no mat ter how many in termediate a rguments a reomitted.

tfe(...) with no output a rguments plots t he magnit ude of the tra nsferfunction estima te a s decibels versus frequency in th e current figure window.

Page 731: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 731/798

7-448

tfe

Example Compute and plot the transfer function estimate between two colored noisesequences x a nd y .

h = fir1(30,0.2,rectwin(31));x = randn(16384,1);y = filter(h,1,x);tfe(x,y,1024,[],[],512)title('Transfer Function Estimate')

Algorithm tfe uses a four-step a lgorith m:

1 It mult iplies the detrend ed sections by window .

2 It t a kes the length nfft FF T of each section.

3 It a vera ges the squares of the spectra of the x sections t o form Pxx a nd

a verag es the products of th e spectra of th e x a nd y sections to form Pxy .4 It calcula 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

T r a n f e r F u

n c t i o n E s t i m a t e ( d B )

Transfer Function Estimate

Page 732: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 732/798

7-449

tfe

Diagnostics An a ppropriat e diagnostic message is displayed w hen incorrect ar guments 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 , cohere , csd , pwelch , spa

Page 733: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 733/798

7-450

triang

7tr iangPurpose Compute a tr iangular window

Syntax w = triang(n)

Description triang(n) re turns an n-point t ria ngula r w indow in th e column vector w. Thecoefficients of a tr ia ngular window a re

For n odd:

For n even:

The tr ian gular w indow is very similar to a B a rtlet t w indow. The Ba rtlet twindow a lwa ys ends wit h zeros a t sa mples 1 a nd n , while the tr ia ngularw indow is nonzero a t t hose point s. For n odd, the center n-2 points of

triang(n-2) a re equivalent to bartlett(n) .

Example N=200;w = triang(200);plot(w);title('Triangular Window')

w k [ ]

2 k n 1+------------- 1 k

n 1+2

-------------≤ ≤,

2 n k 1+–( )n 1+

------------------------------- n 1+2

------------- k n ≤ ≤,=

w k [ ]2 k 1–

n ---------------- 1 k n

2---≤ ≤,

2 n k 1+–( )n

------------------------------- n 2--- 1+ k n ≤ ≤,

=

Page 734: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 734/798

7-451

triang

See Also bartlett , barthannwin , blackman , blackmanharris , bohmanwin , chebwin ,gausswin , hamming , hann , kaiser , nuttallwin , rectwin , tukeywin , window

References [1] Oppenheim, A.V., a nd R.W. S cha fer, D i scr ete-Ti m e Si gnal Pr ocessing ,P rent ice-H a ll, En glew ood C liffs, NJ , 1989, pp. 447-448.

0 20 40 60 80 100 120 140 160 180 2000

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1Triangular Window

Page 735: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 735/798

7-452

tripuls

7tripulsPurpose G enera te a sam pled a periodic tr ia ngle

Syntax y = tripuls(T)y = tripuls(T,w)y = tripuls(T,w,s)

Description y = tripuls(T) retur ns a cont inuous, aperiodic, symmetr ic, unit y-height

tria ngular pulse a t the t imes indicat ed in arra y T, cent ered a bout T=0 and wi tha defa ult w idth of 1.

y = tripuls(T,w) genera tes a t r ian gular pulse of width w.

y = tripuls(T,w,s) genera tes a t r iangula r pulse wit h skew s , where-1 < s < 1 . When s is 0, a symmetric tr iangula r pulse is generated.

See Also chirp , cos , diric , gauspuls , pulstran , rectpuls , sawtooth , sin , square ,tripuls

Page 736: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 736/798

7-453

tukeywin

7tukeywinPurpose Compute a Tukey w indow

Syntax w = tukeywin(n, α)

Description w = tukeywin(n,r) re turns an n-point, Tukey w indow in column vector w.Tukey w indows a re cosine-ta pered wind ows. α is the ra tio of ta per t o consta ntsections a nd is betw een 0 a nd 1 define. is a rectwin window and is

a hann window.

Example Compute 128-point Tukey w indows w ith five different t a pers.

wtuk = [];for i = linspace(0,1,5)

wtuk = [wtuk tukeywin(128,i)];endplot(linspace(0,1,128),wtuk)axis([0 1 0 1.05 ] );legend('R=0 Rect.','R=1/4','R=1/2','R=3/4','R=1 Hanning',0);title('Tukey Windows for Five Taper Ratio Values');

Algorithm The equa tion for computing t he coefficients of a Tukey w indow is

α 0≤ α 1≥

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

Tukey Windows for Five Taper Ratio Values

R=0 Rect.R=1/4R=1/2R=3/4

R=1 Hanning

Page 737: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 737/798

7-454

tukeywin

See Also barthannwin , bartlett , blackman , blackmanharris , bohmanwin , chebwin ,gausswin , hann , hamming , kaiser , nuttallwin , rectwin , triang , window

References [1] ha rris, f. j . “On th e Use of Windows for H a rmonic Ana lysis wit h t he DiscreteFourier Tra nsform.” Pr oceedi ngs of th e I EE E . Vol. 66 (J a nua ry 1978). pp.66-67.

w k 1+[ ]

1.0 0 k ≤ N 2---- 1 α+( )≤,

0.5 1.0 πk

N 2---- 1 α+( )–

N 1 α–( )---------------------------------cos+ N 2---- 1 α+( ) k N ≤ ≤,

=

Page 738: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 738/798

7-455

udecode

7udecodePurpose Decode 2 n -level qua nt ized integer inputs t o floa ting-point out puts

Syntax y = udecode(u,n)y = udecode(u,n,v)y = udecode(u,n,v,' saturatemode ')

Description y = udecode(u,n) inverts t he operat ion of uencode a nd reconstructs

quantized floating-point values from an encoded multidimensional array ofintegers u . The input a rgument n must be an integer betw een 2 a nd 32. Theinteger n specifies tha t there a re 2 n qua ntiza tion levels for th e inputs, so tha tentr ies in u must be either:

• Signed int egers in the ra nge [-2 n /2, (2 n /2) - 1]• U nsigned integers in the ran ge [0, 2 n -1]

Inputs can be real or complex values of a ny int eger da ta type ( uint8 , uint16 ,uint32 , int8 , int16 , int32 ). Overflows (entr ies in u outside of the ra ngesspecified a bove) a re sa tu ra ted t o the endpoints of the ra nge interva l. Theoutput y ha s the same dimensions a s u . I ts entries have values in the ran ge[-1,1] .

y = udecode(u,n,v) decodes u such tha t th e output y has values in the range[-v,v] , wh ere the defa ult va lue for v is 1.

y = udecode(u,n,v,' SaturateMode ') decodes u a nd t reat s input overflows(ent ries in u outsid e of [-v,v] ) a ccording to th e string ' saturatemode ' , wh ichcan be one of t he following:

• 'saturate' : Sa tura te overflows. This is the default method for t reat ingoverflows.- Ent ries in signed inputs u wh ose values are outside of the ra nge

[-2 n /2, (2 n /2) - 1] a re a ssigned t he va lue determined by t he closest endpointof th is interval.

- Ent ries in unsigned inputs u wh ose values are outside of the ra nge[0, 2 n -1] a re a ssigned t he va lue determined by t he closest endpoint of thisinterval.

Page 739: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 739/798

7-456

udecode

• 'wrap' : Wra p a ll overflow s a ccording t o the followin g:- Ent ries in signed inputs u wh ose values are outside of the ra nge

[-2 n /2, (2 n /2) - 1] a re wra pped back into tha t ra nge using modulo 2 n

arithmetic (calculated using u = mod(u+2^n/2,2^n)-(2^n/2) ).- Ent ries in unsigned inputs u wh ose values are outside of the ra nge

[0, 2 n -1] a re w ra pped ba ck int o the requir ed ra nge before decoding us ingmodulo 2 n arithmetic (calculated using u = mod(u,2^n) ).

Examples u = int8([-1 1 2 -5]); % Create a signed 8-bit integer string.ysat = udecode(u,3) % Decode with 3 bits.ysat =

-0.2500 0.2500 0.5000 -1.0000

Notice the la st ent ry in u sat ura tes to 1, the default peak input ma gnitude.

Cha nge the pea k input ma gnitude.ysatv = udecode(u,3,6) % Set the peak input magnitude to 6.ysatv =

-1.5000 1.5000 3.0000 -6.0000

The last input entry st i l l sat ura tes. Try w ra pping th e overflows.

ywrap = udecode(u,3,6,'wrap')

ywrap =

-1.5000 1.5000 3.0000 4.5000

Try adding more quantization levels.

yprec = udecode(u,5)yprec =

-0.0625 0.0625 0.1250 -0.3125

Algorithm The a lgorith m a dh eres to th e definition for uniform decoding specified in ITU -TRecommenda tion G .701 . Int eger input va lues are un iquely ma pped (decoded)from one of 2 n uniformly spaced integer va lues to qua nt ized float ing-pointvalues in the ra nge [-v,v] . The sma llest integer input va lue allowed ismapped to - v a nd th e la rgest integer input value allowed is ma pped to v .

Page 740: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 740/798

7-457

udecode

Va lues outside of the a llowable input r a nge are either sat ura ted or wra pped,a ccording t o specifica tion.

The rea l a nd ima gina ry component s of complex inputs a re decodedindependently.

See Also uencode

References Gener al Aspects of D igi tal Tr ansmi ssion System s: Vocabul ar y of Di gital Tr ansmission and M ul t ip l exing, and Pul se Code M odul at ion (PCM) T erm s ,Int erna tiona l Telecommun ica tion U nion, ITU -T Recommenda tion G .701,Ma rch, 1993.

Page 741: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 741/798

7-458

uencode

7uencodePurpose Qua nt ize a nd encode floa ting-point input s to integer out puts

Syntax y = uencode(u,n)y = uencode(u,n,v)y = uencode(u,n,v,' SignFlag ')

Description y = uencode(u,n) qua ntizes the entries in a multidimensiona l arra y of

floa ting-point num bers u a nd encodes them a s integers using 2 n -levelquant iza t ion. n must be an in teger betw een 2 a nd 32 (inclusive). Input s can bereal or complex, double- or single-precision. The output y an d the input u a rea rra ys of the sa me size. The element s of the output y a re unsigned integerswith ma gni tudes in the range [0, 2 n -1]. E lement s of th e input u outside of th erange [-1,1] are t rea t ed as overflows a nd a re sa tura ted.

• For entries in the input u tha t a re less tha n -1, the va lue of the output of

uencode is 0.• For entries in th e input u tha t a re grea ter tha n 1, the value of the output of

uencode is 2n -1.

y = uencode(u,n,v) allows th e input u to ha ve ent ries wit h floa ting-pointvalues in the ra nge [-v,v] before sat ura ting t hem (the default value for v i s 1).E lement s of the input u outside of the ra nge [-v,v] a re treat ed as overflowsand a re sa tu ra ted.

• For input ent ries less tha n - v , the va lue of the output of uencode is 0.• For input entries grea ter tha n v , the va lue of the output of uencode is 2n -1.

y = uencode(u,n,v,' SignFlag ') ma ps entr ies in a multidimensiona l arra y offloa ting-point num bers u wh ose entr ies ha ve va lues in th e range [ -v,v ] to a ninteger output y . Input entr ies outside this ra nge are sa tura ted. The integerty pe of th e output depends on th e string ' SignFlag ' a nd th e number of

qua ntiza tion levels 2n

. The st rin g ' SignFlag ' can be one of the following:• 'signed' : Outputs a re signed integers with ma gnitudes in the range

[-2 n /2, (2 n /2) - 1].• 'unsigned' (defa ult): Outputs a re unsigned integers with ma gnitudes in the

range [0, 2 n -1].

Page 742: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 742/798

7-459

uencode

The output da ta types ar e optimized for the number of bits a s shown in theta ble below .

Examples Ma p floa ting -point scala rs in [-1, 1] to uint8 (unsigned) integers, a nd producea sta ircase plot . Note tha t the h orizonta l a xis plots from -1 to 1 and the verticala xis plots from 0 to 7 ( 2^3-1 ).

u = [-1:0.01:1];

y = uencode(u,3);plot(u,y,'.')

n Unsigned Integer Signed Integer

2 t o 8 uint8 int8

9 t o 16 uint16 int16

17 t o 32 uint32 int32

−1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 10

1

2

3

4

5

6

7

Page 743: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 743/798

7-460

uencode

Now look a t sa tur a tion effects w hen you under specify the peak value for th einput.

u = [-2:0.5:2];y = uencode(u,5,1)

y =0 0 0 8 16 24 31 31 31

Now look at th e out put for

u = [-2:0.5:2];y = uencode(u,5,2,'signed')

y =-8 -4 0 4 8 12 16 20 23

Algorithm uencode ma ps the floa ting-point input va lue to a n integer va lue determin ed byth e requirement for 2 n levels of qua nt izat ion. This encoding a dheres to th edefinit ion for un iform encoding specified in I TU -T Recommen da tion G .701.The input ra nge [-v,v] is divided into 2 n evenly spaced intervals. Inputentries in the ra nge [-v,v] a re first q ua nt ized according to this subdivision ofthe input ra nge, and then ma pped to one of 2 n integers. The ra nge of the outputdepends on w hether or not you specify tha t you w a nt signed integers.

See Also udecode

References Gener al Aspects of D igi tal Tr ansmi ssion Systems: Vocabul ar y of Di gital Tr ansmi ssion and M ul t i p lexing, and Pul se Code M odul at ion (PCM) T erm s ,In terna tiona l Telecommun ica tion U nion, ITU -T Recommenda tion G .701,Ma rch, 1993.

Page 744: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 744/798

7-461

unwrap

7unwrapPurpose Unw rap phase angles

Syntax p = unwrap(p)

Description p = unwrap(p) corrects t he pha se an gles in vector p by a dding mult iples of, where needed, to smooth th e tra nsit ions a cross bra nch cuts. When p is a

matr ix , unwrap corrects t he pha se an gles dow n ea ch column. The pha se must

be in radia ns.The unwrap function is pa rt of the sta nda rd MATLAB langua ge.

Limitations unwrap tr ies to detect bra nch cut crossings, but it ca n be fooled by spar se,ra pidly changing pha se values.

See Also abs , angle

2π±

Page 745: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 745/798

7-462

upfirdn

7upfirdnPurpose U psample, apply an FIR fi l ter, and downsa mple

Syntax yout = upfirdn(xin,h)yout = upfirdn(xin,h,p)yout = upfirdn(xin,h,p,q)[yout,zf] = upfirdn(xin,h,...,zi)

Description upfirdn performs a cascad e of thr ee opera tions:

1 Upsampling the input da ta in the matr ix xin by a fa ctor of the integer p (inserting zeros)

2 FIR fi ltering th e upsampled signa l da ta wit h t he impulse response sequencegiven in the vector or ma tr ix h

3 Downsa mpling t he result by a factor of the integer q (throwing awa ysamples)

upfirdn ha s been implement ed a s a ME X-file for ma ximum speed, so only theoutputs a ctua lly needed ar e computed. The FIR filter is usua lly a lowpa ssfi lter, w hich you must design using a nother function such a s remez or fir1 .

Note The fun ction resample performs a n FI R design using firls , followedby ra te changing implemented with upfirdn .

yout = upfirdn(xin,h) fi lters th e input signa l xin wit h the FIR fil ter havingimpulse response h . I f xin is a r ow or column vector, then it r epresent s a singlesignal. If xin is a ma tr ix, th en each column is filtered independent ly. If h is arow or column vector, then it represent s one FIR filter. If h i s a ma tr ix , theneach column is a separa te FI R impulse response sequence. If yout is a r ow orcolumn vector, then it represents one signa l. If yout is a ma trix, then ea chcolumn is a sepa ra te output. No upsampling or dow nsa mpling is implement edwith th is syntax.

yout = upfirdn(xin,h,p) specifies th e integer upsa mpling fact or p , where p ha s a defaul t value of 1.

Page 746: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 746/798

7-463

upfirdn

yout = upfirdn(xin,h,p,q) specifies th e integer downsa mpling factor q ,where q has a defaul t value of 1.

[yout,zf] = upfirdn(xin,h,...,zi) specifies initia l sta te condit ions in t hevector zi .

The size of th e initia l condit ion vect or zi must be the same a s length(h)-1 , thenumber of delays in t he FIR filter.

When xin is a vector, t he size of the fina l condit ion vector zf is length(h)-1 ,th e number of dela ys in t he filter. When xin i s a mat r ix, zf i s an ma tr ix wi th(length(h)-1) rows a nd (size(xin,2)) columns.

Note Since upfirdn performs convolution and rate changing, the yout s ignals have a different length t ha n xin . The nu mber of row s of yout isapproximately p/q times t he number of rows of xin .

Remarks Usually the inputs xin a nd th e fi l ter h a re vectors, in w hich case only oneoutput signal is produced. However, wh en these arguments a re arr a ys, eachcolumn is tr eated a s a sepa ra te signal or f i l ter. Valid combinat ions a re:

1 xin is a vector a nd h is a vector.

There is one filter a nd one signa l, so t he funct ion convolves xin wi th h . Theoutput signa l yout is a r ow vector if xin is a row; otherw ise, yout is a columnvector.

2 xin i s a ma tr ix and h is a vector.

There is one filter a nd m a ny s igna ls, so the function convolves h with eachcolumn of xin . The result ing yout will be an ma trix with t he same numberof columns a s xin .

3 xin is a vector a nd h i s a mat r ix.There a re ma ny filters a nd one signa l, so th e function convolves ea ch columnof h wi th xin . The resu ltin g yout will be an ma trix with t he same number ofcolumns a s h .

Page 747: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 747/798

7-464

upfirdn

4 xin i s a ma tr ix and h is a m a trix, both with the sa me number of columns.

There ar e man y filters a nd ma ny signa ls, so th e function convolvescorr esponding columns of xin a nd h . The resu ltin g yout i s an mat r ix wi thth e same number of columns a s xin a nd h .

Examples If both p a nd q a re equal t o 1 (tha t is , there is no ra te changing), the result isordina ry convolution of tw o signa ls (equiva lent t o conv ).

yy = upfirdn(xx,hh);

This exa mple implement s a seven-chan nel filter ba nk by convolving sevendifferent filters with one input signal, then downsamples by five.

% Assume that hh is an L-by-7 array of filters.yy = upfirdn(xx,hh,1,5);

Implement a ra te cha nge from 44.1 kHz (CD sa mpling ra te) to 48 kHz (DATra te), a ra tio of 160/147. This r equires a low pas s filter w ith cutoff frequency a tω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 t his exa mple, the fi lter design a nd resampling ar e separa te steps. Note tha tresample w ould do both steps a s one.

Algorithm upfirdn uses a polypha se interpola tion st ructur e. The num ber of mult iply-a ddopera tions in the polypha se structur e is a pproximat ely (L h Lx -pL x )/q w here L h a n d Lx a re the lengths of h [n ] a nd x [n ], r espectively.

A more accura te flops count is computed in t he progra m, but t he a ctua l countis still approxima te. For long signa ls x [n ], th e formula is often exa ct.

Diagnostics I f p a nd q ar e large an d do not h ave ma ny common factors, you ma y see thismessage

Filter length is too large - reduce problem complexity.

Inst ead, you should use an interpolat ion function, such a s interp1 , to performthe resampling and then fi l ter the input.

Page 748: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 748/798

7-465

upfirdn

See Also conv , decimate , downsample , filter , interp , intfilt , resample , upsample

References [1] Crochiere, R.E., a nd L.R. Ra biner, M ul ti -Rate Signal Processin g ,P rent ice-Ha ll, En glewood C liffs, NJ , 1983, pp. 88-91.

[2] Crochiere, R.E., “A G eneral P rogra m t o Perform Sa mpling Ra te Conversionof Da ta by Rat ional Ra t ios ,”Program s for Di gital Signa l Pr ocessin g , IEEEP ress , New Yor k, 1979, pp. 8.2-1 to 8.2-7.

Page 749: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 749/798

7-466

upsample

7upsamplePurpose Increase the sampling rat e of the input signal

Syntax y = upsample(x,n)y = upsample(x,n,phase)

Description y = upsample(x,n) increases the sa mpling ra te of x by insert ing n-1 zer osbetween sa mples. x can be a vector or a ma trix. If x is a ma trix, each column is

considered a separa te sequence. The upsa mpled y ha s x*n samples.

y = upsample(x,n,phase) specifies t he nu mber of sa mples by w hich to offsetth e upsampled sequence. phase must be a n integer from 0 to n-1.

Examples In crease the sa mpling ra te of a s equence by 3.

x = [1 2 3 4];y = upsample(x,3);x,y

x =1 2 3 4

y =1 0 0 2 0 0 3 0 0 4 0 0

Increase the sa mpling ra te of the sequence by 3 and a dd a phase offset of 2.

x = [1 2 3 4];y = upsample(x,3,2);x,y

x =1 2 3 4

y =

0 0 1 0 0 2 0 0 3 0 0 4

Page 750: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 750/798

7-467

upsample

Increase the sampling rat e of a ma trix by 3.

x = [1 2; 3 4; 5 6;];y = upsample(x,3);x,y

x =1 23 45 6

y =1 20 00 03 40 0

0 05 60 00 0

See Also decimate , downsample , interp , interp1 , resample , spline , upfirdn

Page 751: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 751/798

7-468

vco

7vcoPurpose Voltage controlled oscillator

Syntax y = vco(x,fc,fs)y = vco(x,[Fmin Fmax],fs)

Description y = vco(x,fc,fs) crea tes a signal tha t oscil la tes at a frequency determinedby the real input vector or a rra y x wit h sa mpling frequency fs . fc is the ca rrier

or reference frequency; w hen x is 0, y i s an fc Hz cosine wi th ampl itude 1sampled a t fs H z. x ra nges from -1 t o 1 , where x = -1 corresponds t o0 frequency output, x = 0 corresponds t o fc , and x = 1 corresponds t o 2*fc .Output y is the same size a s x .

y = vco(x,[Fmin Fmax],fs) sca les th e frequency modulat ion ra nge so tha t± 1 va lues of x yield oscillations of Fmin H z a n d Fmax Hz respectively. For bestresults, Fmin a nd Fmax should be in th e ran ge 0 to fs/2 .

B y defaul t , fs is 1 a nd fc is fs/4 .

I f x i s a ma tr ix , vco produces a m a tr ix whose columns oscillat e according t o thecolumn s of x .

Example G enera te t w o seconds of a signa l sa mpled at 10,000 sa mples/second w hoseinsta nta neous frequency is a tr ia ngle function of t ime.

fs = 10000;t = 0:1/fs:2;x = vco(sawtooth(2*pi*t,0.75),[0.1 0.4]*fs,fs);

P lot the spectrogram of the generat ed signal .

specgram(x,512,fs,kaiser(256,5),220)

Page 752: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 752/798

7-469

vco

Algorithm vco performs FM modulation using the modulate function.

Diagnostics If a ny va lues of x lie outs ide [-1, 1], vco gives the following error messa ge.

X outside of range [-1,1].

See Also demod , modulate

Time

F r e q u e n c y

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.80

500

1000

1500

2000

2500

3000

3500

4000

4500

5000

Page 753: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 753/798

7-470

window

7window Purpose Compute a specific w indow

Syntax w = window(fhandle,n)w = window(fhandle,n, winopt )

w = window(fhandle,n,sidelobe)

Description w = window(fhandle,n) re turns the n-point window, specified by its function

handle , fhandle , in column vector w. Function ha ndles are w indow functionna mes preceded by a n @.

Note For more informa tion on each w indow fun ction a nd it s option(s), refer

to its reference page.

w = window(fhandle,N, winopt ) retur ns t he win dow specified by its funct ionhandle , fhandle, a nd i ts option va lue or st r ing in winopt . Only blackman ,chebwin , gausswin , hamming , hann , and tukeywin windows t ake a n option.

w = window(fhandle,N,sidelobe) retur ns t he window specified by its

function ha ndle, fhandle . I f fhandle is either @chebwin or @kaiser , a secondnumerica l para meter must be entered. For Chebyshev sidelobe is the numberof decibels tha t t he sidelobe magn itude is below th e ma inlobe; for Ka isersidelobe is the beta value.

Example Crea te an d plot three windows.

N = 65;

@barthannwin @hamming

@bartlett @hann

@blackman @kaiser

@blackmanharris @nuttallwin

@bohmanwin @rectwin

@chebwin @triang

@gausswin @tukeywin

Page 754: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 754/798

7-471

window

w = window(@blackmanharris,N);w1 = window(@hamming,N);w2 = window(@gausswin,N,2.5);plot(1:N,[w,w1,w2]); axis([1 N 0 1]);legend('Blackman-Harris','Hamming','Gaussian');

See Also barthannwin , bartlett , blackman , blackmanharris , bohmanwin , chebwin ,gausswin , hamming , hann , kaiser , nuttallwin , rectwin , triang , tukeywin

10 20 30 40 50 600

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

Blackman−HarrisHammingGaussian

Page 755: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 755/798

7-472

xcorr

7xcorrPurpose E stima te t he cross-correla tion function

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 estima tes t he cross-correla tion sequence of a r a ndom process.Autocorrela tion is han dled as a special case.

The t rue cross-corr elat ion sequen ce is

where x n a nd y n a re jointly sta tionary ra ndom processes, , an d E ·is th e expected va lue operat or. xcorr must est ima te th e sequence beca use, inpra ctice, only a finit e segment of one rea lizat ion of the infinite-length r a ndomprocess is ava ilable.

c = xcorr(x,y) return s t he cross-correla tion sequence in a length 2* N -1vector, w here x a nd y a re length N vectors ( N >1). I f x a nd y are not the samelength, t he shorter vector is zero-pad ded to t he length of the longer vector.

B y defaul t , xcorr computes raw correlat ions wit h n o norma liza tion.

The out put vector c ha s element s given by c (m ) = c xy (m -N ), m = 1, ..., 2N -1.

In genera l, the correlat ion function requires norma lizat ion to produce a na ccura te est ima te (see below).

R x y m ( ) E x n m + y *n E x n y *n m – ==

∞– n ∞< <

R ˆ

x y m ( )

x n m + y n *

n 0=

N m – 1–

∑ m 0≥

R ˆ

y x *

m –( ) m 0<

=

Page 756: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 756/798

7-473

xcorr

c = xcorr(x) is th e a ut ocorrela tion sequence for t he vector x . I f x i s an N -by-P matr ix , c i s a mat r ix wi th 2N -1 rows w hose P 2 columns contain thecross-correlation sequences for all combinations of the columns of x . For moreinformat ion on ma tr ix processing wit h xcorr, see “Multiple Cha nnels” onpage 3-5 .

c = xcorr(x,y,' option ') specifies a norma lizat ion option for th ecross-correlation, where ' option ' is :

• 'biased' : B ias ed estima te of the cross-correla tion function

• 'unbiased' : U nbia sed estima te of the cross-correla tion function

• 'coeff' : Norma lizes the sequence so th e aut ocorrelat ions a t zero la g a reidentically 1.0

• 'none' , to use the ra w , unscaled cross-correla tions (default )

See reference [1] for m ore informa tion on t he propert ies of bias ed a nd u nbia sedcorrelation estimates.

c = xcorr(x,' option ') specifies one of th e a bove norma lizat ion options forthe au tocorrelat ion.

c = xcorr(x,y,maxlags) retur ns t he cross-correla tion sequence over th e lagrange [-maxlags:maxlags] . Output c has length 2*maxlags+1 .

c = xcorr(x,maxlags) returns the autocorrelation sequence over the lagrange [-maxlags:maxlags] . Output c has length 2*maxlags+1 . I f x i s anN

-by-P

matr ix , c i s a mat r ix wi th 2*maxlags+1 rows wh oseP 2

columns cont a inth e au tocorrela tion sequences for a ll combina tions of the columns of x .

c = xcorr(x,y,maxlags,' option ') specifies both a ma ximum num ber of lagsa nd a scaling option for t he cross-correla tion.

c = xcorr(x,maxlags,' option ') specifies both a ma ximum num ber of lagsa nd a sca ling option for th e aut ocorrelation.

c x y b i ased , m ( )1N ---- c x y m ( )=

c x y u n bi a sed , m ( )1

N m –------------------- c x y m ( )=

Page 757: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 757/798

7-474

xcorr

[c,lags] = xcorr(...) returns a vector of the lag indices a t wh ich c w a sest imat ed, wi th t he range [-maxlags:maxlags] . When maxlags is notspecified, t he ra nge of lags is [-N+1:N-1] .

In a ll cases, th e cross-correla tion or a ut ocorrelat ion computed by xcorr has thezeroth la g in th e middle of th e sequence, at element or row maxlags+1 (elementor row N if maxlags is n ot s pecified).

Examples The second outpu t, lags , is useful for plotting the cross-correlation ora ut ocorrelat ion. For example, the estima ted a ut ocorrelat ion of zero-mea nG aussian w hi te noise c w w (m ) can be displa yed for -10 ≤ m ≤ 10 usin g

ww = randn(1000,1);[c_ww,lags] = xcorr(ww,10,'coeff');stem(lags,c_ww)

Sw apping the x a nd y input a rgument s reverses (a nd conjuga tes) th e outputcorrela tion sequence. For row vectors, th e resulting s equences a re reversed leftto right ; for column vectors, up a nd d own. The followin g exam ple illustra testh is property ( mat2str is used for a compa ct displa y of complex numbers).

x = [1,2i,3]; y = [4,5,6];[c1,lags] = xcorr(x,y);c1 = mat2str(c1,2), lagsc1 =

[6-i*8.9e-016 5+i*12 22+i*10 15+i*8 12+i*8.9e-016]lags =-2 -1 0 1 2

c2 = conj(fliplr(xcorr(y,x)));c2 = mat2str(c2,2)c2 =

[6-i*8.9e-016 5+i*12 22+i*10 15+i*8 12+i*8.9e-016]

For the ca se where input a rgument x is a ma trix, the output columns ar earra nged so tha t ext ra ct ing a row an d rearra nging i t in to a squa re arrayproduces th e cross-correla tion ma tr ix corresponding to t he la g of th e chosenrow. F or exa mple, the cross-correla tion a t zero la g can be retrieved by

randn('state',0)X = randn(2,2);[M,P] = size(X);c = xcorr(X);

Page 758: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 758/798

7-475

xcorr

c0 = zeros(P); c0(:) = c(M,:) % Extract zero-lag row

c0 =2.9613 -0.5334

-0.5334 0.0985

You ca n ca lcula te t he ma tr ix of correla tion coefficients th a t th e MATLABfunction corrcoef genera tes by substi tuting

c = xcov(X,'coef')

in t he la st example. The function xcov subtracts the mean an d then cal lsxcorr .

U se fftshift to move the second ha lf of the sequence sta rt ing a t the zeroth lagto th e front of th e sequence. fftshift swa ps the first a nd second ha lves of asequence.

Algorithm For more informat ion on estima ting cova ria nce a nd correla tion functions, see[1].

See Also conv , corrcoef , cov , xcorr2 , xcov

References [1] Orfa nidis, S.J ., Optim um Signal Pr ocessin g. An I nt r oduct ion. 2nd Edi t i on ,P rent ice-Ha ll, Englew ood C liffs, NJ , 1996.

Page 759: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 759/798

7-476

xcorr2

7xcorr2Purpose E stima te t he tw o-dimensional cross-correla tion

Syntax C = xcorr2(A)C = xcorr2(A,B)

Description C = xcorr2(A,B) retur ns t he cross-correla tion of ma tr ices A a nd B wi th noscaling. xcorr2 is t he t w o-dimensional version of xcorr . I t ha s i t s maximumvalue when th e two mat rices are aligned so tha t t hey are sha ped a s similarlya s possible.

xcorr2(A) is the a utocorrelation ma trix of input ma trix A . I t is identical toxcorr2(A,A) .

See Also conv2 , filter2 , xcorr

Page 760: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 760/798

7-477

xcov

7xcovPurpose Estimate the cross-covariance function (mean-removed cross-correlation)

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 estima tes th e cross-cova ria nce sequence of ra ndom processes.Aut ocovaria nce is ha ndled a s a specia l ca se.

The t rue cross-cova ria nce sequen ce is th e cross-corr elat ion of mean -removedsequences

wh ere a nd ar e the mean values of the tw o sta tionary ra ndom processes,a nd E · is the expected value operator. xcov estima tes th e sequence beca use,in pra ctice, a ccess is ava ilable to only a finite segment of the infinit e-lengthra ndom process.

v = xcov(x,y) retur ns t he cross-cova ria nce sequence in a lengt h 2 N -1 vector,where x a nd y a re length N vectors. For informa tion on how a rra ys a reprocessed w ith xcov, see “Multiple Ch a nnels” on page 3-5 .

v = xcov(x) is th e a utocova ria nce sequence for t he vector x . Where x i s anN -by- P a r r a y, v = xcov(x) r etu rns an a r ra y wi th 2 N -1 rows w hose P 2 columnscont a in t he cross-cova ria nce sequences for a ll combina tions of t he columns of x .

By defaul t , xcov computes raw covaria nces w ith no norma liza tion. For alength N vector

φx y

µ( ) E x n m +

µx

–( ) y n

µy

–( )* =

µx µy

c x y m ( )x n m +( ) 1

N ---- x i

i 0=

N 1–

∑–

y n * 1

N ---- y i

*

i 0=

N 1–

∑–

n 0=

N m – 1–

∑ m 0≥

c y x * m –( ) m 0<

=

Page 761: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 761/798

7-478

xcov

The out put vector c ha s element s given by c(m) = c xy (m -N ), m = 1, ..., 2N -1.

The cova ria nce function requires norma lizat ion t o estima te t he functionproperly.

v = xcov(x,' option ') specifies a scaling option, where ' option ' is :

• 'biased' , for biased est ima tes of t he cross-cova ria nce function•

'unbiased' , for unbia sed estima tes of t he cross-cova ria nce function• 'coeff' , to norma lize th e sequence so th e aut o-cova ria nces at zero la g a re

identically 1.0• 'none' , to use the ra w , unsca led cross-cova ria nces (defau lt)

See [1] for more informa tion on t he properties of bia sed a nd u nbia sedcorrelation a nd cova riance estimat es.

[c,lags] = xcov(x,y,maxlags) where x a nd y a re length mvectors, return sth e cross-cova ria nce sequence in a length 2*maxlags+1 vector c . lags is avector of the la g indices w here c wa s es t imated, tha t i s , [-maxlags:maxlags] .

[c,lags] = xcov(x,maxlags) is the a ut ocovaria nce sequence over th e ran geof lag s [-maxlags:maxlags] .

[c,lags] = xcov(x,maxlags) where x i s an m-by-p a r ra y, r etu rns a r ray c wi th2*maxlags+1 rows wh ose P 2 columns cont a in th e cross-cova ria nce sequencesfor a ll combina tions of th e columns of x .

[c,lags] = xcov(x,y,maxlags,' option ') specifies a scaling option, wh ere' option ' i s the las t input a rgument .

In a ll ca ses, xcov gives a n output such tha t t he zeroth lag of the cova riancevector is in t he middle of the sequence, at element or row maxlag+1 or a t m.

Examples The s econd outpu t lags is useful wh en plotting . For exam ple, the estima teda ut ocovaria nce of uniform wh ite noise c w w (m ) can be displa yed 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 762: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 762/798

7-479

xcov

Algorithm xcov computes the mean of i ts inputs, subtra cts the mean , an d th en ca llsxcorr . For more informa tion on estima ting covaria nce a nd correla tionfunctions, see [1].

Diagnostics xcov does not check for a ny errors other t ha n t he correct num ber of inputa rgument s. Inst ead , it relies on th e error checking in xcorr .

See Also conv , corrcoef , cov , xcorr , xcorr2

References [1] Orfa nidis, S.J ., Optim um Signal Pr ocessin g. An I nt r oduct ion. 2nd Edi t i on ,P rent ice-Ha ll, Englew ood C liffs, NJ , 1996.

Page 763: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 763/798

7-480

yulewalk

7yulewalkPurpose Recursive digita l filter design

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

Description yulewalk designs recursive IIR digital filters using a least-squares fit to aspecified frequency response.

[b,a] = yulewalk(n,f,m) returns row vectors b a nd a containing th e n+1 coefficient s of th e order n II R filter wh ose frequency-ma gnit ude cha ra cteristicsa pproximat ely mat ch those given in vectors f a nd m:

• f is a vector of frequency point s, specified in t he ra nge betw een 0 a nd 1,w here 1 corresponds t o half t he sa mple frequency (th e Nyquist frequency).The first point of f must be 0 a nd th e la st point 1, with a ll intermediat epoints in increa sing order. Duplica te frequency points a re allowed,corresponding t o steps in t he frequency response.

• m is a vector conta ining the desired magnit ude response at the pointsspecified in f .

• f a nd mmust be the sam e length.• plot(f,m) displays the fi l ter sha pe.

The output filter coefficients a re ordered in descending powers of z .

When specifying t he frequency response, avoid excessively sha rp t ra nsit ionsfrom passba nd t o stopban d. You ma y need to experiment w ith t he slope of th etr a nsition region to get the best filter design.

Example Design a n 8th -order lowpa ss filter a nd overplot th e desired frequency responsewit h t he a ctual frequency response.

f = [0 0.6 0.6 1];m = [1 1 0 0];[b,a] = yulewalk(8,f,m);[h,w] = freqz(b,a,128);plot(f,m,w/pi,abs(h),'--')legend('Ideal','yulewalk Designed')title('Comparison of Frequency Response Magnitudes')

B z ( )A z ( )-----------

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

Page 764: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 764/798

7-481

yulewalk

Algorithm yulewalk performs a lea st-squa res fit in the t ime doma in. I t computes th edenomina tor coefficients using modified Yule-Wa lker equa tions, w ithcorrela tion coefficients comput ed by inverse Fourier tr a nsforma tion of thespecified frequency response. To compute the numerator, yulewalk ta kes thefollowin g steps:

1 Computes a numerat or polynomial corresponding t o an a ddit ivedecomposition of the power frequency response.

2 Eva lua tes t he complete frequency response corresponding to the num erat ora nd denominat or polynomials.

3 U ses a spectr a l factorizat ion technique to obta in the impulse response of thefilter.

4 Obtains t he numerat or polynomial by a lea st-squa res fit to this impulseresponse.

See Also butter , cheby1 , cheby2 , ellip , fir2 , firls , maxflat , remez

References [1] Friedla nder, B ., a nd B . P orat , “The Modified Yule-Wa lker Method of ARMASpectra l Estima tion,” I EE E T r ansacti ons on Aer ospace E l ectroni c System s ,AES -20, No. 2 (Ma rch 1984), pp. 158-173.

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

1.4Comparison of Frequency Response Magnitudes

Idealyulewalk Designed

Page 765: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 765/798

7-482

zp2sos

7zp2sosPurpose Convert digital filter zero-pole-gain parameters to second-order sections form

Syntax [sos,g] = zp2sos(z,p,k)[sos,g] = zp2sos(z,p,k,' order ')[sos,g] = zp2sos(z,p,k,' order ',' scale ')sos = zp2sos(...)

Description zp2sos converts a discrete-time zero-pole-ga in r epresenta tion of a given digita lfilter to a n equiva lent second-order section representa tion.

U se [sos,g] = zp2sos(z,p,k) to obta in a mat r ix sos in second -order sectionform with ga in g equivalent to the discrete-time zero-pole-gain filterrepresented by input a rguments z , p , and k . Vectors z a nd p cont a in th e zerosa nd poles of the filter ’s t ra nsfer function H (z ), not necessarily in a ny pa rt icula rorder.

where n a nd m a re the length s of z a nd p , respectively, a nd k i s a sca la r ga in .The zeros and poles must be real or complex conjugate pairs. sos i s an L -by-6mat r ix

whose rows contain the numerator and denominator coefficients b ik a nd a ik oft he second-order sect ions of H (z ).

The n umber L of rows of the ma trix sos is the closest integer grea ter t ha n orequal t o the maximum of n /2 a nd m /2.

H z ( ) k z z 1–( ) z z 2–( )L z z n –( )

z p 1–( ) z p 2–( )L z p m –( )--------------------------------------------------------------------=

so s

b 01

b 11

b 21

1 a 11

a 21

b 02 b 12 b 22 1 a 12 a 22M M M M M M

b 0 L b 1 L b 2 L 1 a 1 L a 2 L

=

H z ( ) g H k z ( )

k 1=∏ g

b 0 k b 1 k z 1– b 2 k z 2–+ +

1 a 1 k z 1– a 2 k z 2–+ +--------------------------------------------------------- -

k 1=

∏= =

Page 766: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 766/798

7-483

zp2sos

7484

[sos,g] = zp2sos(z,p,k,' order ') specifies the order of the rows in sos ,where ' order ' is :

• 'down' , to order the sections so the first r ow of sos cont a ins t he poles closestto th e unit circle

• 'up' , to order t he sections so the first row of sos contains the poles farthestfrom th e unit circle (defau lt)

[sos,g] = zp2sos(z,p,k,' order ',' scale ') specifies the desired scaling ofth e gain a nd t he numera tor coefficients of a ll second-order sections, wh ere' scale ' is :

• 'none' , to a pply no scaling (defau lt)• 'inf' , to a pply infinity-norm scaling• 'two' , t o apply 2-norm sca ling

U sing infinity -norm scaling in conjunction w ith up -ordering minimizes t heproba bility of overflow in t he rea lizat ion. U sing 2-norm scaling in conjunctionwi th down -ordering minimizes the peak round-off noise.

sos = zp2sos(...) embeds the overall system gain, g , in th e first section,H 1(z ), so tha t

Example Find a second-order section form of a B ut terw orth lowpa ss filter.

[z,p,k] = butter(5,0.2);sos = zp2sos(z,p,k);

H z ( ) H k z ( )

k 1=∏=

Page 767: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 767/798

7-484

zp2sos

7485

Algorithm zp2sos uses a four-step a lgorithm to det ermine t he second-order sectionrepresenta tion for a n input zero-pole-ga in syst em:

1 It groups the zeros an d poles into complex conjuga te pa irs using t hecplxpair function.

2 It forms t he second-order section by ma tching t he pole and zero pa irsa ccording to t he follow ing ru les:

a Ma tch t he poles closest t o the unit circle w ith t he zeros closest t o thosepoles.

b Ma tch t he poles next closest t o the unit circle with th e zeros closest t oth ose poles.

c Continue unti l a l l of th e poles a nd zeros are ma tched.

zp2sos groups real poles int o sections w ith th e real poles closest t o them ina bsolut e value. The sa me rule holds for rea l zeros.

3 It orders the sections a ccording to th e proximity of the pole pairs t o the unitcircle. zp2sos norma lly orders t he sections w ith poles closest t o the unitcircle la st in t he cascad e. You ca n t ell zp2sos to order t he sections in th ereverse order by specifying t he down flag.

4 zp2sos scales th e sections by t he norm specified in th e ' scale ' argument .For a rbit ra ry H (ω), th e scaling is defined by

where p can be either ∞or 2. See th e references for deta ils on t he scaling.This sca ling is a n a tt empt t o minimize overflow or peak round-off noise infixed point filter implementa tions.

See Also cplxpair , filternorm , sos2zp , ss2sos , tf2sos , zp2ss , zp2tf

H p 1

2 π------ H ω( )p

ωd 0

2 π

1p ---

=

Page 768: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 768/798

7-485

zp2sos

7-486

References [1] J a ckson, L.B ., Di gi ta l Fi l ters and Signal Processin g , 3rd ed., KluwerAcademic P ublishers, B oston, 1996, Ch a pter 11.

[2] Mitra, S.K., Di gital Signal Pr ocessin g: A Comp uter-Based A ppr oach ,McGr a w -Hill, New York, 1998, Ch a pter 9.

[3] Va idyana tha n, P .P. , “Robust Digita l Fil ter Structures,” H and book for Di gital Si gnal Pr ocessin g , S.K. Mitra a nd J .F. Ka iser, ed., J ohn Wiley & Sons,New York, 1993, Chapter 7.

Page 769: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 769/798

7-486

zp2ss

7-487

7zp2ssPurpose Convert zero-pole-ga in filter pa ra meters t o sta te-spa ce form

Syntax [A,B,C,D] = zp2ss(z,p,k)

Description zp2ss converts a zero-pole-ga in representa tion of a g iven system t o anequivalent sta te-space representa tion.

[A,B,C,D] = zp2ss(z,p,k) finds a sing le input, mult iple output, st a te-spacerepresentation

given a system in factored transfer function form.

Column vector p specifies t he pole locat ions, a nd m a tr ix z th e zero locat ionswit h a s ma ny columns a s there a re outputs. The gains for ea ch numerat ortransfer function are in vector k . The A , B, C, and D ma trices ar e return ed incont roller ca nonica l form.

Inf va lues may be used a s place holders in z if some columns ha ve fewer zerostha n others .

Algorithm zp2ss , for single-input syst ems, groups complex pairs together into t wo-by-tw oblocks down t he diag onal of the A ma tr ix. This requires t he zeros a nd poles tobe real or complex conjuga te pa irs.

See Also sos2ss , ss2zp , tf2ss , zp2sos , zp2tf

x · A x B u +=

y C x D u +=

H s ( ) Z s ( )

P s ( )---------- k

s z 1–( ) s z 2–( )L s z n –( )

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

Page 770: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 770/798

7487

zp2tf

7-488

7zp2tfPurpose Convert zero-pole-ga in filter pa ra meters t o tra nsfer function form

Syntax [b,a] = zp2tf(z,p,k)

Description zp2tf forms t ra nsfer function polynomials from t he zeros, poles, and ga ins of asyst em in factored form.

[b,a] = zp2tf(z,p,k) finds a ra tional tra nsfer function

given a system in fa ctored tra nsfer function form

Column vector p specifies th e pole loca tions, a nd m a tr ix z specifies the zerolocations, with a s ma ny columns a s th ere are outputs. The gains for eachnumerat or t ra nsfer function are in vector k . The zeros an d poles must be realor come in complex conjugate pairs. The polynomial denominator coefficientsa re return ed in row vector a and the polynomial numerator coefficients arereturned in ma trix b , which has a s ma ny rows a s there are columns of z .

Inf va lues ca n be used as pla ce holders in z if some columns ha ve fewer zerostha n others .

Algorithm The syst em is converted t o tra nsfer function form using poly wi th p a n d t h ecolumn s of z .

See Also sos2tf , ss2tf , tf2zp , zp2sos , zp2ss

B s ( )A s ( )-----------

b 1 s n 1–( ) L b n 1–( )s b n + + +

a 1 s m 1–( ) L a m 1–( )s a m + + +--------------------------------------------------------------------------------=

H s ( ) Z s ( )P s ( )---------- k

s z 1–( ) s z 2–( )L s z m –( )s p 1–( ) s p 2–( )L s p n –( )------------------------------------------------------------------= =

Page 771: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 771/798

zplane

7-489

7zplanePurpose Zero-pole plota

Syntax zplane(z,p)zplane(b,a)[hz,hp,ht] = zplane(z,p)

Description This fun ction d isplays th e poles a nd zeros of discrete-time sy stems.

zplane(z,p) plots t he zeros specified in column vect or z a nd t he poles specifiedin column vector p in th e current figure wind ow. The symbol 'o' represent s azero a nd t he symbol 'x' represent s a pole. The plot includes t he unit circle forreference. If z a nd p a re a r rays , zplane plots th e poles an d zeros in th e columnsof z a nd p in different colors.

You can override th e aut omat ic scaling of zplane using

axis([xmin xmax ymin ymax])

or

set(gca,'ylim',[ymin ymax])

or

set(gca,'xlim',[xmin xmax])

a fter call ing zplane . This is useful in t he case w here one or a few of th e zerosor poles have such a la rge magnit ude tha t t he others a re grouped t ight lya round the origin and a re hard t o dist inguish.

zplane(b,a) where b a nd a a re row vectors, first uses roots to find t he zerosa nd poles of th e tra nsfer function represent ed by numera tor coefficients b a nddenomina tor coefficient s a .

[hz,hp,ht] = zplane(z,p) retur ns vectors of ha ndles to th e zero lines, hz ,a nd t he pole lines, hp . ht is a vector of ha ndles t o the a xes/unit circle line a ndto text objects, w hich a re present w hen t here a re multiple zeros or poles. Ifth ere a re no zeros or n o poles, hz or hp is the empty ma trix [] .

Page 772: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 772/798

zplane

7-490

Examples For da ta sa mpled at 1000 Hz, plot th e poles and zeros of a 4th-order ellipticlow pass digita l filter w ith cut off frequency of 200 Hz, 3 dB of ripple in t hepassba nd, and 30 dB of att enuat ion in the stopband.

[z,p,k] = ellip(4,3,30,200/500);zplane(z,p);title('4th-Order Elliptic Lowpass Digital Filter');

To genera te th e same plot w ith a tr a nsfer function representa tion of the filter,use the following comma nds.

[b,a] = ellip(4,3,30,200/500); % Transfer functionzplane(b,a)

See Also freqz

−1 −0.5 0 0.5 1

−1

−0.8

−0.6

−0.4

−0.2

0

0.2

0.4

0.6

0.8

1

Real Part

I m a g

i n a r y

P a r t

4th−Order Elliptic Lowpass Digital Filter

Page 773: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 773/798

I-1

Index

Numerics2-norm 7-181

AA/D conver sion 7-459abs 7-26ac2poly 7-27ac2rc 7-28a liased sinc functions 1-13

command for 7-145aliasing

impulse inva ria nce 2-42prevent ing 4-23red ucing 4-40

all-pole filters. See IIR filtersa ll-zero filters. See FIR filtersam 4-31AM. See amplitude modulationamdsb–sc 4-31, 7-293amdsb–tc 4-31, 7-293amplitude demodulation

double side-ba nd, suppressed carr ier 7-142

double side-band, transmitted carrier 7-142single side-band 7-142

amplitude modulation 4-31double side-ba nd, suppressed carr ier 7-293double side-band, transmitted carrier 7-293quadrature 4-32single side-band 7-293

amssb4-32, 7-293a na log filter s 2-39

ba ndpa ss 7-276bandstop 7-279B essel 2-12, 2-39, 7-38, 7-39bilinear tr a nsformat ion 2-43Butterworth 2-9, 2-39, 7-64, 7-65, 7-66

Chebyshev 2-39Ch ebysh ev Type I 2-10, 7-78, 7-90Chebyshev Type II 2-11, 7-96convert ing t o digita l 2-42, 7-246desig n 2-8discretiza tion 2-42ellipt ic 2-39, 7-155frequency response 1-27, 2-13, 7-206highpass 7-281impulse inva ria nce 2-42inverse 7-255lowpa ss 7-283order estima tion

Butterworth 7-71

Ch ebysh ev Type I 7-80, 7-85Chebyshev Type II 7-85ellipt ic 7-163

plotting 2-13representational models 1-42See al so IIR filters

a na log frequency xxvian alog signals . See signalsanalytic signals 7-238angle 7-29a nt i-sym met ric filters 2-26AR filters, sta bility check 7-341AR models. See a ut oregressive (AR) modelsarburg 4-13, 7-30arcov 4-13, 7-31

ARMA filters 1-16, 4-15, 4-17P rony’s met hod 4-15St eiglitz-McBr ide met hod 4-17See al so IIR filters

armcov 4-13, 7-32ARX models 4-15aryule 4-13, 7-33

Page 774: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 774/798

Index

I-2

ASC II files, importing 1-14a ut ocorrela tion 7-339, 7-474au tocorrelation sequences

converting from reflection coefficients 7-364estima tion, va rian ce 3-4filter coefficients

convert ing t o an d from 7-27, 7-28, 7-339filters, m ultiple cha nnels 3-5two-dimensional 7-477

a ut ocovar ia nce 7-478mult iple cha nnels 3-5

autoregressive (AR) models 1-16B urg m eth od 7-30, 7-299, 7-303cova ria nce met hod 7-31, 7-304modified covaria nce met hod 7-32, 7-321,

7-325Yule-Wa lker AR met hod 7-33, 7-359, 7-363See al so IIR filters

autoregressive moving average (ARMA) filters.See ARMA filter s

averaging filters 1-15axis labels 6-50axis par am eters

Filt er View er 6-50Spectru m View er 6-50

Bband edges, prewarping 2-44bandlimited interpolation 7-406ba ndpa ss filters 7-71, 7-80, 7-85, 7-163

B essel 7-39Butterworth 7-65Ch ebysh ev Type I 7-90, 7-92Chebyshev Type II 7-95desig n 2-7ellipt ic 7-155

exam ple, Ch ebyshev Type I 2-40FIR 2-22, 7-188impulse inva ria nce 2-42tr a nsformat ion from lowpa ss to 7-276

ba ndst op filters 2-7, 7-71, 7-80, 7-85, 7-163B essel 7-39Butterworth 7-66Chebyshev Type I 7-91Chebyshev Type II 7-95ellipt ic 7-156FIR 2-22, 7-187tr a nsformat ion from lowpa ss to 7-279

ban dw idth 2-41ba r thannwin 4-3 , 7-34bartlett 4-3 , 7-36

exa mple 4-4triang , comparison to 7-36

B art let t windows 4-4coefficients 7-36

Bartlett-Hanning 7-34Bessel filters 2-12, 2-39, 7-38

bandpass 7-39ba nds top 7-39cha ra cterist ics 2-12high pa ss 7-39limit a tions 7-41lowpass 7-39roots 7-38

besselap 2-6, 7-38exa mple 2-12

besself 2-6, 2-7, 7-39bias

correlation 3-4, 4-14power spectra l densit y 3-17, 3-18, 3-23va ria nce tra de-off 3-4

bilinear 2-6, 2-42, 2-43, 7-42bilinear tra nsformat ions 2-43, 2-44, 7-42

Page 775: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 775/798

Index

I-3

output representation 7-43prew a rping 2-44, 7-42

bit r eversa l 7-47bitrevorder 7-47blackman 4-3 , 7-49B lackma n w indows 4-5, 7-49B lackma n-Ha rris 7-51blackmanharris 4-3, 7-51B lackma n-Ha rris w indows 7-296Bohman 7-53bohmanwin 4-3 , 7-53boxcar 7-55boxcar wind ows. See recta ngular windowsbra ckets, indicating closed interva l xxvibuffer 7-55

buffer ing 7-55Burg method 3-8, 3-9, 3-33

exa mple 3-34Welch’s met hod, compa rison 3-35

buttap 2-6, 7-64exa mple 2-9

butter 2-6, 2-7, 7-65B utt erworth filters 2-9, 2-39, 7-64

bandpass 7-65ba nds top 7-66characteristics 2-9desig n 7-65genera lized 2-15high pa ss 7-66limit a tions 7-69

lowpass 7-65order estim a tion 2-8, 7-70

buttord 2-6, 7-70

Ccanonical forms 1-18, 7-443

carr ier freq uency 4-31, 7-293, 7-469carr ier signa ls 4-31, 7-142casca de, filt ers 1-38Cauer filters. See elliptic filterscceps 4-25 , 4-27, 7-75

exa mple 4-25cell2sos 7-77center frequency 2-41cent ra l feat ures 1-2cepstrum

a na lysis 4-25a pplica tions 4-25complex 4-25inverse 4-25, 4-27overview 4-25

real 4-25, 4-26, 7-368reconst ructin g signa ls (min imum -pha se) 4-27

cheb1ap 2-6 , 7-78exa mple 2-10, 2-40

cheb1ord 2-6 , 7-79cheb2ap 2-6 , 7-83

exa mple 2-11cheb2ord 2-6 , 7-84chebwin 4-3 , 7-89 , 7-116cheby1 2-6, 2-7, 7-90

exa mple 2-45cheby2 2-6, 2-7, 7-95Chebyshev error minimization 2-23, 7-371Chebyshev Type I filters 2-10, 2-39, 7-78, 7-90

ba ndpa ss 7-90, 7-92

ba nds top 7-91cha ra cterist ics 2-10desig n 7-90high pa ss 7-91lowpass 7-90order estim a tion 2-8, 7-79

Ch ebyshev Type I I filters 2-39, 7-95

Page 776: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 776/798

Index

I-4

ba ndpa ss 7-95bandstop 7-95char a cterist ics 2-11high pas s 7-95limita tions 7-94lowpass 7-95order estimation 2-8

Ch ebyshev w indow s 4-10, 7-89frequency response 4-10

chirp 1-10, 7-100chirp sign a ls 1-10chirp z -transforms (CZT) 4-36, 7-133

discrete Fourier tr a nsforms , compar ison 4-36frequency ana lysis, narr owban d 7-133

coding, PCM 7-459

coefficientscorrelation 7-115filter 1-16, 6-34, 7-27, 7-339, 7-341, 7-367linear prediction 7-285reflection 1-38, 7-28, 7-341, 7-364, 7-367sequence 7-364

cohere 3-9 , 7-106linearly dependent da ta 3-30

cohere 3-29coherence 3-29, 7-106

linearly dependent da ta 3-30colors, S P Tool 6-50communications 4-12, 4-31, 7-293

See al so modulat ion, demodulation, volta gecont rolled oscilla tion

comm unica tions simu la tion 7-142compact disc standards 4-22compa ction 4-39complex conjug a t e 7-120complex envelope. See Hilbert t ra nsformscomplex nu mbers, grouping by conjugat e 7-120confidence intervals

cross spectr a l densit y 3-27power spectra l densit y 3-27w ar nings 3-27

context-sensitive help 6-7continu ous signals. See signalscontinuous-time filters. See analog filterscont rol sy stem s 1-36Control Systems Toolbox 1-36conv 1-15, 1-21, 7-110conv2 1-15, 7-111conversions

a utocorrelat ion sequences to an d from filtercoefficients 7-27

a utocorrelat ion sequences to a nd from reflectioncoefficients 7-28

err ors in 1-43, 5-15filter coefficients to autocorrelation sequences

7-339filter coefficients to reflection coefficients 7-341,

7-367functions (table) 1-43reflection coefficient s to a ut ocorrela tion

sequ ences 7-364second-order section form s to st a te-spa ce forms

7-409second-order section forms to transfer functions

7-411second-order section forms to zero-pole-gain

forms 7-413sta te-spa ce forms t o second-order section forms

7-426state-space forms to zero-pole-gain forms 7-431transfer functions to lattice forms 7-438transfer functions to second-order section forms

7-439transfer functions to state-space forms 7-442

Page 777: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 777/798

Index

I-5

zero-pole-gain forms to second-order sectionforms 7-483

zero-pole-ga in form s t o sta te-spa ce form s7-487

convmtx 1-41, 1-43, 7-113convolution 7-110

cross-corr ela t ion 3-3exa mple 1-15filtering 1-15, 7-180matrices for 1-41, 1-43, 7-113

exa mple 7-113two-dimensional 7-111

corrcoef 7-115correlation 3-2

bia s 3-4, 4-14

coefficient matrices 7-115cross-corr ela t ion 7-473matrices

cova ria nce met hod 7-116modified covaria nce met hod 7-116

See al so au tocorrelation sequences,cross-corr elat ion sequences

corr elat ion ma tr ices 7-116corrmtx 7-116cosine w indow s 4-5cov 7-119covariance 3-2

matrices 7-119See al so autocovariance, cross-covariance

cova ria nce met hod 3-9, 3-36, 7-308

exa mple 3-36See al so modified covariance methodcplxpair 7-120cremez 2-17, 7-121cross spectr a l densit y 3-27, 7-129

confidence in ter va ls 3-27

See al so pow er spectra l density, spectr alestimation

cross-correlation sequences 3-3estim a tion 7-473

biased 3-4unbia sed 3-4

filters, m ult iple cha nn els 3-5norma lization 3-5two-dimensional 7-477

cross-cova ria nce 3-3, 7-478mult iple cha nn els 3-5

csd 3-9 , 3-27, 7-129cutoff frequency 2-39, 7-39czt 4-37, 7-133CZT. See chirp z -transforms

DD.C . component suppression 1-47d a t a

mult ichan nel 1-5, 1-8vectors 1-7

da ta compression 4-12

da ta ma tr ices 1-5, 1-8data vectors 1-5dct 4-38, 7-136

exa mple 4-39decimate 7-138decimation 7-138

FIR filter for 7-253decoding 7-456deconv 4-35, 7-141

exa mple 4-35deconvolut ion 4-35, 7-141defa ult session file 6-50delays

group 1-29

Page 778: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 778/798

Index

I-6

noninteger 2-27pha se 1-29signals 2-27

demod 4-31, 4-32, 7-142exa mple 4-32

demodula tion 4-32, 7-142am plitude, quad ra tur e 7-143exa mple 4-32met hods 4-32, 7-142pha se 7-143pulse position 7-143pulse w idt h 7-143

DFT. See discrete Fourier tra nsformsdftmtx 7-144difference equa tions 1-33

different ia tors 2-27, 7-200, 7-373digital audio tape standards 4-22digital filters

a nt i-causa l 1-21Butterworth 7-65cas cad e 1-38Chebyshev Type II 7-95coefficients 1-16convolution ma tr ices 1-41desig n 2-3ellipt ic 7-155FI R 2-17

II R, compar ison to 2-17fixed-point implement a tion 1-38frequency da ta , ident ificat ion from 7-259

frequency response 1-25group delay 1-29, 7-231IIR 2-5

FI R filters , compar ison to 2-5implement a tion 1-15, 7-174, 7-177

convolut ion 1-15FFT-based (FIR) 7-174

filter 1-17overlap-a dd met hod 1-23

impu lse res ponse 1-15, 1-24, 7-248init ia l conditions 1-18linear models 1-33models 1-33na mes 1-16order 1-16

state-space representation 1-35order estima tion

B utt erwort h 7-70, 7-79, 7-84Ch ebysh ev Type I 7-79, 7-84Chebyshev Type II 7-84ellipt ic 7-162equiripple FIR 7-378

pha se dela ys 1-29, 7-231poles 1-31, 1-34second-order sections 1-38specifications 2-8startup transients 1-22structures

la t t ice/la dd er 1-38transposed direct form II 1-18

time-domain representation 1-17tr a nsfer functions represent a tion 1-16transients 1-23two-dimensional 7-180zero-phase 1-21, 7-183zer os 1-31, 1-34See al so FIR filters, IIR filters

digita l frequency xxvidirect design 2-6diric 7-145Dir ichlet fun ctions 1-13

command for 7-145discrete cosine transforms (DCT) 7-136

a pplica tions 4-38

Page 779: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 779/798

Index

I-7

energy compa ction property 4-39exa mple 4-39inverse 4-38, 7-243signals, reconstructing 4-39

discrete F ourier t ra nsform s (DFT) 1-3, 1-45, 2-27,7-170

a lgorith ms 1-46applications 7-170eigenvector equiva lent 3-38exa mple 1-46goert zel 1-47IIR filter implementa tion 1-23inverse 1-45, 7-244

matrices 7-144two-dimensional 1-47, 7-245

magnitude 1-46matrices 7-144pha se 1-46signa l lengt h depend encies 1-46spectral analysis 3-6, 3-10time-dependent 4-29two-dimensional 1-47, 7-173See al so fast Fourier tr a nsforms (FFT), fft

discrete prolate spheroidal sequencesSee D P S S

discretiza tion 7-246bilinear tr a nsformat ions 2-43

prewarping 2-44impulse inva ria nce 2-42

discretiza tion, filter s 2-42

disk, loading variables from 6-43division, polynomials 7-141D P S S

direct met hod 7-149int erpolat ion 7-148

dpss 7-148dpss.mat 3-26

dpssclear 3-26 , 7-151dpssdir 3-26 , 7-152dpssload 3-26 , 7-153dpsssave 3-26 , 7-154duty cycles 1-9

Eechoes, det ection 4-25edge effects 1-23eigena na lysis 3-37

frequency estimation 3-37eigenvector method 3-8, 3-36, 7-309

root MU SI C 7-390See al so multiple signal cla ssification met hod

ellip 2-6 , 2-7 , 7-155ellipap 2-6 , 7-161

exa mple 2-11ellipord 2-6 , 7-162 , 7-167ellipt ic filter s 2-39, 7-155

ba ndpa ss 7-155bandstop 7-156cha ra cterist ics 2-11

highpass 7-156limita tions 7-159lowpa ss 7-155order est ima tion 2-8, 7-162, 7-167

encodingP C M 7-459un iform 7-459

eqtflength 7-167equiripple cha ra cteristics

Ch ebyshev Type I filters (passba nd) 2-10Ch ebyshev Type II filters (stopba nd) 2-11Chebyshev windows 4-10ellipt ic filter s 2-11, 7-155, 7-161P a rks-McClellan design 7-371

Page 780: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 780/798

Index

I-8

equiripple filters 2-23error minimizat ion

desired an d a ctua l response, betw een 2-23frequency ban ds, w eighting 2-26minim a x 2-23

estimationcross spectr a l densit y 3-27nonparametric

multiple signal classifica tion meth od(MUSIC) 3-8

mult ita per m eth od (MTM) 3-8Welch’s method 3-8

parametric 3-8Burg method 7-30cova ria nce met hod 7-31

modified cova ria nce met hod 7-32Yule-Wa lker m eth od 7-33

spectr a l densit y 3-8, 3-10transfer functions 3-28See al so para metric modeling

Ffast Fourier Transforms (FFT)

G oertzel a lgorithm 7-226fa st Fourier t ra nsforms (FF T) 1-23, 1-45

fft 1-23frequency response 1-25ra dix-2 a lgorithm 7-172signal processing, role in 1-45two-dimensional 7-173

fdatool 7-168fdatool 5-1

help on 6-7opening 5-6

fft 1-3 , 1-23, 1-45, 7-170exa mple 1-46

execution time 1-46num ber of sa mples 1-46out put 1-47, 7-176ra dix-2 a lgorithm 7-172

FF T filt erin g 1-23FFT. See fast Fourier t ra nsformsfft2 1-47, 1-47, 7-173

output 1-47fftfilt 1-20 , 7-174

filter , compa rison t o 7-174fftshift 1-47, 1-47 , 7-176filter

coefficients 1-16media n 4-30order 1-16

filter 1-3 , 1-17 , 1-21 , 7-177fftfilt , compa rison t o 7-174filtfilt , compa rison 1-22final condition parameters 1-18implementation 1-18initia l condition pa ra meters 1-18init ia l conditions 7-184

filter coefficient sreflection coefficient s, conversion s t o 7-341,

7-367filter design G U I 5-2

a na lysis butt ons 5-13analysis functions 5-13computing coefficients 5-12design m eth ods 5-8

design sessionsopening 5-25saving 5-25

export ing filters 5-21filter design specifica tion 5-9filter order specification 5-11filter ty pe 5-7

Page 781: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 781/798

Index

I-9

filtersa rchit ectu re 5-15implementation 5-15rea lizat ion 5-15st ructu re 5-15

frequ ency r esponse specifica tion 5-9group d elay 5-13importing coefficients 5-17import ing filt ers 5-17impulse response 5-13ma gnit ude response 5-13ma gnit ude r esponse specs 5-10opening 5-6pha se delay 5-13phase response 5-13

pole-zero plots 5-13saving coefficients 5-21st ep respons e 5-13

Filt er D esigner 6-11, 7-421FF T lengt h 6-50filter ty pes 6-11filters

editing 6-41

redesigning 6-49saving 6-33

FI R filt ers 6-11FI R met hods 6-11grid lines 6-50II R met hods 6-11opening 6-12, 6-22

overview 6-11plotscustomizing 6-50magnitude 6-49

P ole/Zero E dit or 6-46sa mple freq uency 6-34spectr a , overlay ing 6-12

zooming 6-50filter pa ra meters 6-50Filter Viewer 6-14, 7-422

a xis para meters 6-50filter pa ra meters 6-50measurements 6-52opening 6-14overview 6-14preferences, tiling 6-50print ing 6-27ru lers 6-52zooming 6-50

filter2 7-180filternrom 7-181filt ers 1-3

a na log 2-9, 2-12, 7-38, 7-64, 7-78a nt i-causa l 1-21a nt i-sym met ric 2-26averaging 1-15bandpass

Butterworth 7-70Ch ebysh ev Type I 7-79Chebyshev Type II 7-84

ellipt ic 7-162bandstop

Butterworth 7-70Ch ebysh ev Type I 7-79Chebyshev Type II 7-84ellipt ic 7-162

Butterworth 2-8, 7-65

generalized 2-15Ch ebyshev 2-8Type I 7-90Type II 7-95

coefficients 1-17, 1-33, 2-18, 6-34bit reversa l 7-47

Page 782: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 782/798

Index

I-10

converting to a utocorrelat ion sequence7-339

export to C hea der file 5-22export to text file 5-22export to w orkspa ce 5-21

convolution 1-15creat ing 2-8design 6-11

Filt er D esigner 6-11FI R 2-23genera lized 2-6

discretiza tion 2-42elliptic 2-8, 7-155equ iripple 2-23FIR 7-371

single ba nd 2-21frequency da ta , ident ificat ion from 7-255frequ ency doma in 1-23frequency t ra nsformat ion functions 2-39,

2-40highpass

Butterworth 7-70Chebyshev Type I 7-79

Chebyshev Type II 7-84elliptic 7-162

implement a tion 1-23, 7-174, 7-177initial conditions 1-18, 1-19inverse 7-255, 7-259la t t ice/la dd er 1-38linea r ph a se 2-17, 2-18linear t ime-invar iant digita l 1-3lowpass

Butterworth 7-70Chebyshev Type I 7-79Chebyshev Type II 7-84elliptic 7-162

measurements 6-52

median 7-292minim a x 2-23minim um ph a se 7-344na mes 1-16norm 7-181order 1-16, 2-8, 7-70, 7-79, 7-162, 7-167order estimation 2-8pha se, modula tion 4-27pred iction 4-14qua nt ized, sta te vectors 7-178Sa vitzky -G olay 7-400, 7-404Schur realizations 7-397second-order section form s 1-38, 1-44, 7-415specifications 2-8SP Tool 6-39

tr a nsposed direct form II stru cture 1-18two-dimensional 7-180t ypes 2-18zero-phase 1-21, 7-183See al so FIR filters, IIR filters, digita l filters,

analog filtersfiltfilt 1-20 , 1-21 , 2-5 , 7-183

exa mple 1-21filter , compa rison 1-22init ia l conditions 1-22

filtic 1-19, 7-184FI R filt ers 1-16, 2-17

decimation 7-253different iat ors 2-27, 7-200, 7-373equ iripple 2-17, 2-23, 2-24exa mple 6-20Filt er D esigner 6-11frequ ency doma in 1-20frequency response 7-190Hilbert tr a nsformers 2-26, 7-200, 7-373II R filter s, compa rison 2-17implement a tion 1-18, 7-177

Page 783: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 783/798

Index

I-11

FFT-based 1-23, 7-174overlap-a dd met hod 1-23, 7-174

int erpolat ion 7-253Ka iser window s 4-8la t t ice/la dd er 1-38least squares 2-17, 2-24, 7-199

constrained 2-17, 2-28equiripple, comparison 2-24linea r pha se 2-29mult iban d 2-29, 2-30w eight ed 2-31

linea r pha se 2-18, 2-23, 7-199, 7-371mult iban d 2-17, 2-22, 2-23order estimation, remez 7-378overlap-a dd met hod 7-174

Parks-McClellan method 2-23, 7-371ra ised cosine m eth od 2-17resa mpling 1-20respon ses 2-32

complex filt ers 2-17, 7-121dela ys, r educing 2-35nonlinea r ph a se 2-17, 7-121

sta nda rd ba nd 2-21

types 7-202, 7-376windowing method 2-17w indow s 2-19, 7-186

fir1 2-17, 2-21fir2 2-17, 2-21fircls 2-17 , 7-193fircls1 2-17 , 7-196firls 2-17 , 2-23 , 7-199

differentiators 2-27filter cha ra cterist ics 7-202remez , compar ison t o 2-24w eight vectors 2-26

firrcos 2-17 , 7-204fixed-point implementation, digital filters 1-38

fm 4-32FM. See frequency modulat ionfopen 1-14Fourier transforms. See discrete Fourier

tra nsforms, fast Fourier t ra nsformsfread 1-14freqs 1-27, 7-206freqspace 7-208freq uen cy 7-372

a na log xxvia ngula r 2-3carrier 4-31, 7-293, 7-469center 2-41cutoff 2-39digita l xxvi

estimationeigena na lysis 3-37eigenvector (EV) method 3-37multiple signa l classificat ion (MU SI C)

met hod 3-37norma lization 2-3Nyquist xxvi, 2-3prewarping 7-42

vectors 2-25, 7-190, 7-193, 7-481frequency analysis, time-dependent 7-416frequ ency demodula tion 7-143frequency doma in

dua lity w ith time-domain 1-23filt ers 1-23FI R filt ering 1-20transformation functions 2-39, 7-276, 7-279,

7-281, 7-283exa mple 2-41lowpass to bandpass 7-276lowpa ss t o band st op 7-279lowpa ss t o highpa ss 7-281

Page 784: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 784/798

Index

I-12

frequency doma in ba sed modeling. See parametric modeling

frequ ency modula tion 7-294frequency response 1-25, 2-14, 7-190

B essel filters 2-12Butterworth filters 2-9Ch ebyshev Type I filters 2-10Ch ebyshev Type II filters 2-11Chebyshev windows 4-10elliptic filt ers 2-11error minimization 2-23evaluating 1-25exa mple 1-26inverse 7-255Ka iser window 4-7

linea r pha se 2-18magnitude 1-27monot onic 2-9multiband 2-14pha se 1-27

unwrapping 1-28plott ing 1-26, 7-213sa mples, spa cing 7-208

sa mpling fr equency 1-25frequency vectors 7-372freqz 1-25, 7-209

sa mpling frequ encies 1-25sa mpling fr equency 1-25spa cing 7-208

freqzplot 7-213From Disk radio button 6-43fscanf 1-14

Ggains, scalar 1-34gauspuls 1-10, 1-11, 7-220

Gaussian monopulse 7-224G a uss-New ton m eth od 7-258, 7-261gausswin 4-3generalized B utt erwort h filters 2-15genera lized cosine wind ows 4-5genera lized filters 2-6Gibbs effect 2-20

reduced by w indow 4-3gmonopuls 7-224goertzel 7-226gra phica l user int erface (G U I) 1-4

See al so interactive tools, SPToolgrid lines 6-50group delay 1-29, 2-18, 7-231

exa mple 1-30

passband 2-12grpdelay 1-29, 7-231G U I-based t ools. See intera ctive tools

Hhamming 4-3, 7-234Ha mming w indows 2-20, 3-18, 4-5, 7-234

hann 4-3hann 7-236Ha nn w indows 7-236Ha nning w indows 4-5, 7-236hanning . See hannhigh pa ss filters 2-7, 7-71, 7-80, 7-85, 7-163

B essel 7-39Butterworth 7-66Chebyshev Type I 7-91Chebyshev Type II 7-95ellipt ic 7-156FIR 2-22, 7-188lowpa ss, tr a nsformat ion fr om 7-281

hilbert 2-27 , 4-40

Page 785: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 785/798

Index

I-13

exa mple 4-40Hilbert transformers 7-200, 7-373Hilbert transforms 4-36, 4-40, 7-238

analytic signals, of 2-27exa mple 4-40instantaneous attributes 4-41

homomorphic syst ems 4-25Hz 7-300, 7-305, 7-322, 7-360

Iicceps 4-25, 4-27 , 7-242

exa mple 4-28idct 4-38, 7-243idea l low pa ss filters 2-19

See al so low pass filtersifft 1-45, 7-244

samples, specifying 1-47ifft2 1-47 , 7-245II R filt ers 2-5, 2-6, 2-8, 2-9, 2-14

B essel 2-12Butterworth 2-8, 2-9B utt erwort h, generalized 2-15

Chebyshev 2-8, 2-10, 2-11Chebyshev Type I 2-10Chebyshev Type II 2-11desig n 2-7, 2-38elliptic 2-8, 2-11Filt er D esigner 6-11filter ty pes, compar ison 2-9FI R filters , compar ison to 2-5frequency response 2-14implement a tion 7-177

frequ ency doma in 1-23zero-phase 1-21

la t t ice/la dd er 1-38Levinson-Du rbin recursion 7-274

ma ximally fla t 2-15multiband 2-14order estimation 2-8plottin g responses 2-13P rony’s met hod 7-345specifications 2-8St eiglitz-McBr ide itera tion 7-433Yule-Wa lker 2-14, 7-481See al so direct design

image processing 1-47, 7-111impinvar 2-6, 2-42, 7-246Import dialog box

From Disk radio button 6-43Workspace C ontent s list 6-21

impulse inva ria nce 2-42, 7-246

limita tions 2-42impu lse res ponse 1-24, 7-248computing with filter 1-24computing with impz 1-24exa mple 1-24impulse inva ria nce 2-42lowpa ss filters, idea l 2-19

impz 7-248

exa mple 1-24ind exing 1-16inf-norm 7-181init ia l conditions 1-18, 1-19, 1-22, 7-184instantaneous attributes 4-41int era ctive t ools 1-4, 6-3

exa mple 6-20Filt er D esign a nd Analys is Tool 5-2Filt er D esigner 6-11, 7-421Filter Viewer 7-422Signal Browser 7-421Spectrum Viewer 6-17, 7-424SP Tool 7-420

interp 7-251

Page 786: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 786/798

Index

I-14

int erpolat ion 7-251ba ndlim ited 7-406FI R filters 7-253

interval notation xxviintfilt 7-253inverse cepstrum, complex 4-27inverse discret e cosine t ra nsforms 7-243

a ccura cy of signa l reconst ruction 4-40

inverse discrete Fourier transforms 1-45, 7-244ifft 1-45matrices 7-144two-dimensional 1-47, 7-245

inverse filters 7-259, 7-345analog 7-255digital 7-259

inverse Fourier t ra nsforms, continuous.

See sincinverse-sine pa ra meters

reflection coefficients, transformations from7-262

reflection coefficients, t ra nsformat ions to7-365

invfreqs 2-6, 4-13, 4-19, 7-255

invfreqz 2-6, 4-13, 4-19, 7-259is2rc 7-262

Kkaiser 4-3 , 7-263

exa mple 4-6Ka iser w indow 3-20Ka iser w indows 4-6, 7-263

beta pa ra meter 4-6, 7-263exa mple 4-6FI R filter s 4-8frequ ency r esponse 4-7

kaiserord 2-17, 7-265

Lladder filters. See la tt ice/la dder filtersLa gra nge int erpolat ion filter 7-253La place tra nsforms 1-42

sta te-spa ce form s 1-42lar2rc 7-270latc2tf 1-41, 1-43, 7-271latcfilt 1-20, 1-41, 7-272

la t t ice/la dd er filt ers 1-38, 1-39, 1-43coefficients 1-39latcfilt 1-41Schur algorithm 7-397tr a nsfer fun ctions, conversions fr om 7-438

least squa res meth od, FIR filters 7-199, 7-202levinson 4-13, 7-274, 7-387

parametric modeling 4-14Levinson-Durbin recursion 4-14, 7-274, 7-387line spectral frequencies

prediction polynomia l coefficients,transformation from 7-340

prediction polynomia l coefficients,tr an sforma tion t o 7-289

line s ty le, SP Tool 6-50

linear models. See modelslinea r ph a se 2-17, 2-18, 7-199

cha ra cterist ics 2-18filt ers 7-371

linear prediction coefficients 7-285linea r prediction m odeling 4-14linea r predictive coding 4-14linear system tra nsforma tions. See conversionsload 1-14log area ra t ion para meters

reflection coefficients, transformations from7-270

reflection coefficients , tr a nsform a tions t o 7-366lowpa ss filter s 2-7, 7-71, 7-80, 7-85, 7-163

Page 787: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 787/798

Index

I-15

B essel 7-39Butterworth 7-65Chebyshev Type I 7-90Chebyshev Type II 7-95cutoff frequency, t ra nsla tion of 7-283decimation 7-138elliptic 7-155FI R 2-22

idea l 2-19impulse inva ria nce 2-42impulse response 2-19int erpolat ion 7-251

lp2bp 2-6, 2-40, 7-276exa mple 2-41

lp2bs 2-6, 2-40, 7-279lp2hp 2-6, 2-40, 7-281lp2lp 2-6, 2-40, 7-283lpc 2-6, 4-13, 7-285

See al so linear predictive coding, Prony’smethod

L P C . See linea r prediction coefficient slse 7-224lsf2poly 7-289

Mmagni tude

Fourier transforms 1-46frequency response 1-27plots 6-49transfer functions 3-28vectors 2-25, 7-190, 7-193, 7-481

ma nufa cturing 4-12ma tch freq uency (for prewa rping) 7-42MAT-files

dpss.mat 3-26forma t, convertin g t o 1-14

importing 1-14SP Tool 6-43matrices

convolution 1-41, 7-113corr ela tion coefficient 7-115cova ria nce 7-119da ta 1-5, 1-8discrete Fourier t ra nsforms 7-144

inverse discrete Fourier t ra nsforms 7-144ma trix forms. See state-space formsmaxflat 2-6, 2-15, 7-290ma ximally fla t filters 2-15medfilt1 4-30, 7-292media n filt ers 4-30, 7-292ME X-files 1-14M-files 1-4minima x meth od, FIR filters 2-23

See al so P ar ks-McClellan m ethodminim um pha se 7-344models 1-33

a ut oregressive 7-30, 7-31, 7-32, 7-33B urg met hod 7-299, 7-303cova ria nce met hod 7-304

modified covaria nce met hod 7-321, 7-325Yule-Wa lker AR m eth od 7-359, 7-363

bilinear tra nsformat ions 2-44tr a nsforma tions, discrete/cont inuous 2-44

modified cova ria nce meth od 3-36exa mple 3-36

modulate 4-31, 4-32, 7-293exa mple 4-32met hod fla gs 4-31

modula tion 4-31, 7-293a mplitu de 4-31

See al so amplitude modulationexa mple 4-32frequency 4-32

Page 788: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 788/798

Index

I-16

pha se 4-32pulse position 4-32pulse w idt h 4-32quadrature amplitude 4-32resu lt s of 4-32signals 4-31, 7-293

moving average (MA) filters 1-16See al so FIR filters

MTM. See multi ta per m ethodmult iband f i lters

FI R 2-22FIR, w ith t ra nsition bands 2-23II R 2-14

multichannel data 1-8multiple signa l classificat ion met hod (MU SIC )

3-8, 3-9, 3-36, 7-331, 7-337corr elat ion ma tr ices 7-116eigenvector method 7-309, 7-314root mu sic 7-393

mult iplica tion, polynomia ls 7-110mult iplicity , of zeros a nd poles 6-47multirate filters 1-20

banks 1-20

multitaper method (MTM) 3-8, 3-9, 3-24a vera ge pow er, conserva tion of 3-26exa mple 3-25Welch’s method, comparison to 3-26

MUSIC a lgor i thm. See multiple signa lcla ssification method

Nnonrecursive filters. See FIR filtersnormalization 3-4

correlation 3-5, 7-473, 7-474power spectra l densit y 3-17, 3-18, 3-23

Nutt all w indows 7-296

nut ta l lwin 4-3 , 7-296Nyquist frequency xxvi, 2-3, 7-155Nyquist interval 7-155

Oorder

estim a tion 2-8, 7-378

Butterworth 7-70Ch ebysh ev Type I 7-79ellipt ic 7-162, 7-167

filt ers, of 1-16, 2-8oscillat ors, volta ge contr olled 7-469overlap-a dd method

FIR filter implement a tion 1-23FIR filters 7-174

PP an ner check box, Signa l B rowser 6-50pa ra met ric modeling 4-12, 7-259

a pplica tions 4-12frequency domain based 4-19

summa ry 2-6techniques 4-12tim e-doma in ba sed 4-14

Burg method 7-30cova ria nce met hod 7-31linear predictive coding 4-14, 4-15modified cova ria nce met hod 7-32St eiglitz-McBr ide met hod 4-17

Yule-Wa lker m eth od 7-33parent heses, indicating open interva l xxviP a rks-McClellan m eth od 2-23, 7-371partial fraction expansion 1-36, 1-42, 1-43, 7-384

determining w ith residue 1-42exa mple 1-36

Page 789: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 789/798

Index

I-17

pas sba nd 7-70, 7-79, 7-84, 7-162equ iripple 2-10, 2-11group d elay 2-12

pburg 3-9 , 3-34 , 7-299exa mple 3-34

P CM 7-459pcov 3-9 , 3-36, 7-304

exa mple 3-36

peig 3-36peig 7-309period, finding in a sequence 7-398periodic sin c funct ions 7-145

See al so Dirichlet functionsperiodogram 7-316periodograms 3-10, 7-316, 7-320phase

comput ing 7-29dela ys 1-29, 2-18, 7-231

exa mple 1-30demodula tion 7-143distortion

elimina tin g 1-20, 1-21FI R filt ers 1-21

II R filt ers 1-21Fourier transforms 1-46frequency response 1-27modulation 4-32, 7-294

filt ers 4-27tr a nsfer fun ctions, of 3-28unwrapping 1-28, 7-462

plotsa na log filter s 2-13cepstr um , complex 4-26coherence fun ction 3-29DFT 1-46frequency response 1-26fun ctions for 7-347

group delay 1-30ma gnit ude 1-27, 6-49pha se 1-27

delays 1-30st rip plot s 7-436transfer functions 3-28zero-pole 1-31, 7-489

plottin g functions 7-213

plug-ins 6-50pm 4-32pmcov 3-9 , 3-36 , 7-321

exa mple 3-36p-model. See parametric modelingpmtm 3-9 , 7-326

exa mple 3-25pmusic 3-9, 3-36 , 7-331P ole/Zero E dit or 6-46pole-zero filters. See IIR filterspoly 1-34 , 1-43poly2ac 7-339poly2lsf 7-340poly2rc 7-341polynomials

division 4-35, 7-141mult iplica tion 7-110roots 1-34, 1-43sca ling 7-344stability check 7-341sta bilizat ion 7-343

polyphas e filtering t echniques 1-20polyscale 7-343polystab 7-343 , 7-344power spectral density 3-6

bias 3-17, 3-18, 3-23confidence in ter va ls 3-27estimation

Burg method 3-9, 3-33, 7-299

Page 790: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 790/798

Index

I-18

cova ria nce met hod 3-9, 3-36, 7-304modified cova ria nce meth od 3-9, 7-321multitaper method 3-24, 7-326MU SI C method 3-37, 7-331root mu sic 7-390, 7-393Welch’s method 3-9, 3-20, 3-23Yule-Wa lker AR m eth od 3-9, 3-32, 7-359

multit a per method 3-9

MUS IC m ethod 3-9norma liza tion 3-17, 3-18, 3-23plot s 6-17Spectru m View er 6-17SP Tool 6-41un it s of 3-7

ppm 4-32prediction filters 4-14prediction polynomials

line spectra l frequencies, tra nsformat ionsfrom 7-289

line spectra l frequencies, tran sforma tions to7-340

P references menu it em 6-50prew a rping 7-42

P rint dia log box 6-28, 6-30P rint P review w indow

Signal Browser preferences 6-28Spectru m View er 6-30

print ing, S pectr um Viewer 6-53prolate-spheroidal windows 4-6prony 2-6, 4-13, 4-15, 7-345P rony’s met hod 4-15, 7-345

modelin g 4-15psdplot 7-347pseudospectrum 7-337

eigenvector method 7-309, 7-314MUS IC algorithm 7-337

pulse position d emodula tion 7-143

pulse position modula tion 4-32pulse tim e modula tion 7-294pulse train generator 7-349pulse t ra ins

genera tin g 1-11pulstran 1-11

pulse width demodulation 7-143pulse width modulation 4-32, 7-294

pulstran 1-11, 7-349pwelch 3-9 , 3-20 , 7-353pwm4-32pyulear 3-9, 3-32 , 7-359

exa mple 3-33, 3-34

Qqam 4-32qua dra tur e amplitude demodulat ion 7-143qua dra tur e amplitude modulat ion 4-32, 7-294quantization 7-181, 7-456, 7-459

P C M 7-459quantized filters 7-178

second-order sections

coefficients in a cell a rra y 7-408coefficients in a ma tr ix 7-77

Rra da r a pplicat ions 4-29raised cosine filters 7-204randn xxiv

ra ndom number, generat ion xxivrange notation xxvirc2ac 7-364rc2is 7-365rc2lar 7-366rc2poly 7-367

Page 791: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 791/798

Index

I-19

rceps 4-25, 4-27, 7-368rebuffering 7-55recta ngula r w indows 2-19, 4-3, 7-370rectpuls 7-369rectwin 4-3

exa mple 4-4rectwin 7-370recursive filters. See IIR filters

references 1-48, 3-39, 4-42reflect ion coefficients 1-38, 1-39

convert ing t o aut ocorrela tion seq uence 7-364filter coefficients, conversions from 7-341,

7-367inverse sine parameters, transformation from

7-365inverse sine para meters , t ra nsforma tion t o

7-262log a rea ra t io para meters , t ransformation from

7-366log area ra t io para meters , t ra nsforma tion to

7-270Schur algorithm 7-397

remez 2-17, 2-23, 7-371

differentiators 2-27filter cha ra cterist ics 7-376firls , compar ison t o 2-24Hilbert tr a nsformers 2-26order est ima tion 7-378w eight vectors 2-26

Remez exchan ge a lgorith m 2-23, 7-371remezord 2-17 , 7-378resample 7-381resampling 4-22, 7-381

FI R filt ers 1-20See al so decima tion, int erpolat ion

residue 1-42, 1-43, 1-43residue forms. See partial fraction expansion

residuez 1-43 , 7-384rlevinson 7-387root MU SI C 7-393

eigenvector method 7-390rooteig 7-390rootmusic 7-393roots 1-34, 1-43

polynomials 1-34

rulersposition ing 6-53Signa l B rowser 6-50Spectr um View er 6-50

Ssam pling frequency

changingnoninteger resampling factors 4-22, 7-381wi th upfirdn 1-20

decreasing 7-146decreasin g by int eger fa ctor 7-138FI R filt ers 1-20freqz 1-27

increasing 7-251, 7-467irregular ly spaced dat a 4-23Nyquist interval 7-155ra nge 1-27spa cing 1-27

saving da t aSpectr um View er 6-37

Sa vitzky -G olay filt ers 7-400, 7-404sawtooth 1-9, 7-390 , 7-396saw tooth w ave 1-9sca ling 7-343schur 7-397Schur algorithm 7-397schurrc 7-397

Page 792: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 792/798

Index

I-20

second-order section form s 1-38, 1-43filt ers 7-415ma tr ices 1-38SP Tool 6-40sta te-spa ce forms, conversions fr om 7-426sta te-spa ce forms, conversions t o 7-409tr a nsfer fu nctions, conversions from 7-411,

7-439

zero-pole-ga in for ms, conver sions fr om 7-483zero-pole-ga in for ms, conver sions t o 7-413

second-order sectionscoefficient s in cell a rr a ys 7-408coefficients in matrices 7-77

seqperiod 7-398sgolay 7-400 , 7-404sgolayfilt 7-404Signa l B rowser 6-8, 7-421

axis labels 6-50ma rkers , preferences 6-50opening 6-8overview 6-8P a nn er, preferences 6-50P rint P review w indow 6-28

printing 6-10, 6-26, 6-27, 6-53signals, measuring 6-52zooming, preferences 6-50

Signal Processing Toolbox 1-3signals 2-27

a ddin g noise 1-7a na lyt ic 4-40, 7-238a periodic 1-10a pplica tions 4-40ar ra y 6-8buffer ing 7-55car rier 4-31, 7-142chirp 1-10continuous (analog) 1-3

differentiators 2-27diric 1-13discrete (digital) 1-3generating 1-8linear swept-frequency cosine. See chirpmeasurements 6-52modulation 4-31, 7-293multichannel 3-5

periodic 1-9plotting 1-7propert ies 4-40pulstran 1-11rebuffering 7-55reconstruction

D CT coefficient s, fr om 4-39minim um pha se 4-27, 7-368

represent ing 1-5multichannel 1-5single cha nn el 1-5

sawtooth 1-9, 7-396exa mple 1-9

sinc 1-12sinusoidal 1-7, 1-10

pulse, Gaussian-modulated 1-10squa re w a ve 1-9, 7-425tr ia ngle 7-396

sinc 1-12, 7-406bandlimited interpolation example 7-406

sin c funct ions 1-12, 7-406basic example 1-12

Slepian sequences. See discrete prolat e spheroida lsequences

sona r a pplica tions 4-29sos2cell 7-408sos2ss 1-43, 7-409sos2tf 1-43, 7-411sos2zp 1-43, 7-413

Page 793: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 793/798

Index

I-21

sosfilt 7-415specgram 4-29, 7-416

exa mple 4-29, 7-469specifica tion lines. See Filter D esignerspecifica tions, filters 2-8spectra. See spectrumspectra l a na lysis 3-6

cross spectr a l densit y 3-27

power spectr um 3-6Spectr um View er 6-17See al so spectral estimation

spectral density 3-6measurements 6-52plottin g functions 7-347Spectr um View er 6-17units of 3-7See al so pow er spectr al density, cross spectra l

densityspectr a l densit y plots 6-17spectral estimation 3-10

Burg method 3-9, 3-33, 7-299, 7-300covariance method 7-304, 7-308eigenvector method 7-309, 7-310, 7-314

modified cova ria nce meth od 3-9, 7-321multit a per meth od 3-9, 7-326MU SIC a lgorith m 7-331, 7-337MU SIC method 3-9, 7-332nonparametric

multiple signal classifica tion meth od(MUSIC) 3-8

multitaper method (MTM) 3-8Welch’s method 3-8

parametr icBurg method 7-30cova ria nce met hod 7-31modified cova ria nce met hod 7-32Yule-Wa lker m eth od 7-33

periodograms 7-320root MU SI C 7-390, 7-393Welch’s me thod 3-8, 3-9, 3-20, 3-23, 3-27, 7-109,

7-131, 7-353, 7-357Yule-Wa lker AR met hod 2-14, 3-8, 3-9, 3-32,

3-33, 7-359, 7-360spectrogram 4-29, 7-416

exa mple 4-29, 7-469

Spectrum Viewer 6-17, 7-424activating 6-17a xis para meters 6-50ma rkers, preferences 6-50measurements 6-52opening 6-17overview 6-17P rint P review 6-30printing 6-17, 6-27, 6-53ru lers 6-52spectra structures 6-37spectr a l densit y plots 6-17w indow s 6-18zooming 6-50

speech pr ocessin g 4-12, 4-23

spline 4-23SP Tool 6-3, 7-420

colors, cust omizin g 6-50context-sensitive help 6-7customizing 6-50d a t a

entering 1-14objects 6-44selectin g 6-44

da ta stru ctures 6-3editing 6-45exa mple 6-20exporting data 1-14, 6-32filter design 6-22

Page 794: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 794/798

Index

I-22

filtering 6-24filt ers 6-39

coefficients 6-34importing 6-22, 6-39par a meters 6-34specificat ions 6-35

filters, sa ving 6-33help on 6-7

Im port d ia log 6-21importing 1-14, 6-20, 6-22, 6-39items, selecting 6-44line st yle, customizin g 6-50MAT-files 6-43MATLAB w orkspa ce 6-3mult iselection of item s 6-44operation 6-3P ole/Zero E dit or 6-46prefer ences 6-50P references menu it em 6-50P rint dia log box 6-28, 6-30print ing 6-27

filt ers 6-28spectra 6-28

right-click edit menu 6-45ru lers 6-52sa mple freq uency 6-34saving 6-32second-order section f orms 6-40Signa l B rowser 6-26signals

analysis 6-26measurements 6-52playing 6-27

sound 6-27spectra

a na lyzing 6-28importing 6-22

spectr al densitiesimporting 6-39, 6-41plot s 6-41

Spectr um View er 6-28sta te-spa ce form s 6-40transfer functions

export ing 6-34specifyin g 6-40

workspace 6-3zero-pole-ga in form s 6-40

sptool 7-420square 1-9 , 7-425squa re wa ve 1-9ss2sos 1-43 , 7-426ss2tf 1-43, 7-430ss2zp 1-43, 7-431st a bility check, polynomia ls 7-341st a bilizat ion 7-344sta nda rds, digita l audio tape 4-22sta rt up tr a nsients, reducing 1-22, 7-183st a te vectors 7-178state-space forms 1-35, 1-42, 1-43

scala r 1-35

second-order section forms, conversions from7-409

second-order section forms, conversions t o7-426

SP Tool 6-40tr a nsfer fun ctions, conversions t o 7-442zero-pole-ga in for ms , conversion s fr om 7-487zero-pole-gain forms, convertions to 7-431

sta tist ical operat ions 3-3See al so au tocorrelation sequences,

cross-corr elat ion s equences,cross-covariance

St eiglitz-McBr ide met hod 4-17, 7-433stmcb 2-6, 4-13, 4-17, 7-433

Page 795: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 795/798

Index

I-23

stopband 7-70, 7-79, 7-84, 7-162equ iripple 2-11

st rip plot s 7-436strips 7-436structures

convert ing 1-43, 5-15la t t ice/la dd er 1-38tr a nsposed direct form II 7-178

structures, digital filtersla t t ice/la dd er 1-38transposed direct form II 1-18

swept-frequency cosine generator. See chirpsystem identification 4-15system models. See models

Tta pers, P SD estima tes 3-24taps 2-18tf2latc 1-39 , 1-43 , 7-438tf2sos 7-439tf2ss 1-43 , 7-442tf2zp 1-43, 7-431, 7-444

tfe 3-9 , 3-28 , 7-447tiling preferences 6-50time series a tt ributes 4-41time-domain based modeling. See parametr ic

modelingtoolboxes

Control Systems Toolbox 1-36Signal Processing Toolbox 1-3S ym bolic Mat h Toolbox 7-38

tr a nsfer fun ctions 1-16, 1-33, 1-36, 1-43coefficients 1-16, 6-34estim a tion 7-447

usin g Welch’s met hod 3-28factoring 1-34

la tt ice forms , conversions t o 7-438second-order section forms, conversions from

7-411second-order section forms, conversions to

7-439SP Tool 6-40sta te-spa ce forms , conversions t o 7-442zero-pole-ga in forms 1-34

transformationsbilinea r 2-43, 7-42dis cret e/cont inuous 2-44freq uency 2-39, 7-276, 7-279, 7-281, 7-283models, bet w een 1-43

transforms 4-36chirp z -transforms (CZT) 4-36, 7-133discret e cosine 7-136discrete Fourier 1-45, 7-170Hilbert 4-40, 7-238inver se discret e cosin e 4-38, 7-243inverse discrete Fourier 7-244

transients, filters 1-23tra nsition ban d 2-23tr a nsposed direct form II 7-178

init ia l conditions 7-184triang 4-3, 7-451

exa mple 4-4tria ngula r w indows 7-451tripuls 7-453Tukey 7-454tukeywin 4-3 , 7-454tw o-dimensiona l operat ions

discrete Fourier t ra nsforms 1-47, 7-173inverse discrete Fourier t ra nsforms 1-47,

7-245See al so filters, tw o-dimensiona l

tw o-dimen sional s igna l processing 1-47typographical conventions (table) xxvii

Page 796: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 796/798

Index

I-24

Uudecode 7-456uencode 7-459uniform encoding 7-459un it circle 7-344unit impulse funct ion 1-8unit ra mp function 1-8unit sam ple, multichan nel represent at ion 1-8

unit step fun ction 1-8units of pow er spectr a l density (P SD ) 3-7unwrap 1-28, 7-462upfirdn 1-20, 4-23, 7-463upsample 7-467

Vvar ian ce, correlat ion sequence estima te 3-4vco 4-31, 4-34, 7-148 , 7-469vectors

da ta 1-5, 1-7freq uen cy 2-25, 7-190, 7-193, 7-372, 7-481indexing xxvi, 1-16ma gnit ude 2-25, 7-190, 7-193, 7-481

w eight ing 7-200volta ge contr olled oscillat ors 4-34, 7-469

Wwaveforms. See signalsWelch’s method 3-9, 3-20

bias 3-23

B urg m eth od, compar ison to 3-35MTM method, comparison to 3-26normalization 3-23power spectral density estimation 3-8, 3-23,

3-27, 7-109, 7-131, 7-357system identifica tion, nonpar a metric 3-28

Yule-Walker AR method, comparison to 3-33w hit e noise 1-7window 7-471windows

B ar tlett 4-4, 7-36Bartlett-Hanning 7-34B lackman 4-5, 7-49B lackman -Ha rris 7-51, 7-296

blackmanha rr is vs . nut ta l lwin 7-51 , 7-296Bohman 7-53boxcar 2-19Chebyshev 4-10, 7-89cosine, generalized 4-5filt ers 2-19FI R filt ers 2-19

ba ndpa ss 7-186bandstop 7-187highpass 7-187lowpa ss 7-186multiband filters 2-22single ba nd d esign 2-21

fir1 2-22generalized cosine 4-5

Hamming 2-20, 3-18, 4-5, 7-234H a nn 7-236Hanning 4-5, 7-236Kaiser 3-20, 4-6, 7-263Nut ta ll 7-296periodograms 3-12, 3-18prolat e-spheroida l 4-6rectangular 2-19, 7-370shapes 4-3triangular 7-451Tukey 7-454

Workspace Cont ent s list 6-21

Page 797: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 797/798

Index

I-25

Xxcorr 3-3 , 7-473parametric modeling 4-14

xcorr2 7-477xcov 3-3 , 7-478

Yyulewalk 2-6, 2-14, 7-481

exa mple 2-14Yule-Wa lker AR met hod 3-8, 3-9, 3-32, 7-481

exa mple 3-33, 3-34Welch’s method, comparison to 3-33

Yule-Walker equations 2-14

Zzero frequ ency component , centerin g 1-47zero-order hold. See averaging filterszero-phase filtering 7-183zero-pole an a lysis 7-489zer o-pole plot s 1-31, 7-489zero-pole-gain forms 1-34, 1-42, 1-43

exa mple 1-31second-order section forms, conversions from

7-413second-order section forms, conversions t o

7-483S P Tool 6-40st a te-spa ce forms , conversions from 7-431st a te-spa ce forms , conversions t o 7-487

zeros an d polesmultiplicity of 6-47transfer functions 1-34

zooming 6-50zp2sos 1-43, 7-483zp2ss 1-43, 7-487

zp2tf 1-43, 7-488zplane 1-31 , 7-489z -transforms 1-16, 1-33

chirp z -transforms (CZT) 4-36, 7-133discrete Fourier t ra nsforms 1-45, 7-170

Page 798: Matlab DSP Toolbox

7/27/2019 Matlab DSP Toolbox

http://slidepdf.com/reader/full/matlab-dsp-toolbox 798/798

Index

I-26