dsp toolbox

872
Computation Visualization Programming For Use with MATLAB ® U s er’s Guid e Ve rsio n5 Signal P r o cessing  T oolbox

Upload: kaankandemirrr

Post on 03-Apr-2018

223 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

Computation

Visualization

Programming

For Use with MATLAB®

User’s GuideVersion 5

Signal Processing Toolbox

Page 2: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

How to Contact The MathWorks:

508-647-7000 Phone

508-647-7001 Fax

The MathWorks, I nc. Mail

3 Apple Hill Drive

Natick, MA 01760-2098

ht t p: / / www. mat hworks. com Web

f t p. mathworks. com Anonymous F TP server

comp. sof t - sys. mat l ab Newsgroup

support @mat hwor ks. com Technical support

suggest @mat hwor ks. com Product enhancement suggestions

bugs@mat hwor ks. com Bug reports

doc@mat hwor ks. com Documentation error reportssubscr i be@mat hwor ks. com Subscribing user registration

ser vi ce@mat hwor ks. com Order status, license renewals, passcodes

i nf o@mat hwor ks. com Sales, pricing, and general information

Si gnal Processing Toolbox User’s Guide

© COPY RI GHT 1988 - 2000 by The MathWorks, I nc.

The software described in this document is furnished under a licenseagreement. The software may be used

or copied only under the terms of the li censeagreement. No part of this manual may bephotocopied or repro-duced in any form without prior wri tten consent from The MathWorks, Inc.

FE DERAL ACQUI SIT ION : This provision applies to all acquisitions of thePr ogram and Documentation byor for the federal government of the Uni ted States. By accepting delivery of the Pr ogram, the governmenthereby agrees that this software qualifies as "commercial" computer software within the meaning of FARPart 12.212, DFA RS Part 227.7202-1,DFA RS Part 227.7202-3, DFA RS Part 252.227-7013,and DFA RS Part252.227-7014. The terms and conditions of The MathWorks, I nc. Software LicenseA greement shall pertainto the government’s useand disclosure of the Program and Documentation, and shall supersede anyconflicting contractual terms or conditions. I f this licensefails to meet the government’s minimumneeds oris inconsistent i n any respect with federal procurement law, the government agrees to return the Programand Documentation, unused, to MathWorks.

MA TL AB, Simulink, Stateflow, HandleGr aphics, and Real-TimeWorkshop arer egisteredtrademarks, and Target L anguage Compiler is a trademark of T he MathWorks, I nc.

Other product or brand names are trademarks or registered trademarks of their respective holders.

PrintingH istory: J anuary 1997 First printing New for MATL AB 5.1 J anuary 1998 Second printingRevised for MAT L AB 5.2 J anuary 1999 (Online Only) Revised for Version 4.2 (Release 11)August 1999 (Online Only) Revised for Version 4.3 (Release 11)September 2000 Third printing Revised for Version 5.0 (Release 12)

Page 3: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

i

Contents

Preface

Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

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

R12 Related Products List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

How to Use This Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

I f You Are a New U ser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

If You Are an Experienced Toolbox User . . . . . . . . . . . . . . . . . . . 27

All Toolbox U sers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

Installing the Signal Processing Toolbox . . . . . . . . . . . . . . . . . 28

Technical Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

Typographical Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

1Signal Processing Basics

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

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

Filtering and F FTs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3

Signals and Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3

K ey Areas: Filter Design and Spectral Analysis . . . . . . . . . . . . 1-3

Interactive Tools: SPTool and FDATool . . . . . . . . . . . . . . . . . . . 1-4

Extensibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4

Page 4: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

ii Contents

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

Vector Representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5

Waveform Generation: Time Vectors and Sinusoids . . . . . . 1-7Common Sequences: Unit I mpulse, Unit Step, and Unit Ramp 1-8

Multichannel Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-8

Common P eri odic W aveforms . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9

Common Aperiodi c Waveforms . . . . . . . . . . . . . . . . . . . . . . . . . 1-10

The pulstran Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-11

The Sinc Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-12

The Dirichlet Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-13

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

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

Convolution and F iltering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-15

F il ters and T ransfer F unctions . . . . . . . . . . . . . . . . . . . . . . . . . 1-16

Filter Coefficients and Filter Names . . . . . . . . . . . . . . . . . . 1-16

F il tering wi th the fil ter F uncti on . . . . . . . . . . . . . . . . . . . . . . . 1-17

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

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

MultirateF ilter Bank Implementation . . . . . . . . . . . . . . . . . . 1-20

Anti-Causal, Zero-Phase Filter I mplementation . . . . . . . . . . . 1-21

Frequency Domain Filter Implementation . . . . . . . . . . . . . . . . 1-23

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

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

Digital Domain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-25

Analog Domain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-27

Magnitude and P hase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-27

Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-29

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

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

Di screte-T ime S ystem M odels . . . . . . . . . . . . . . . . . . . . . . . . . . 1-33

Page 5: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

iii

Transfer Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-33

Zero-Pole-Gain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-34

State-Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-35

Partial Fraction Expansion (Residue Form) . . . . . . . . . . . . 1-36Second-Order Sections (SOS) . . . . . . . . . . . . . . . . . . . . . . . . 1-38

L attice Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-38

Convolution Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-41

Continuous-Time System M odels . . . . . . . . . . . . . . . . . . . . . . . 1-42

Linear System Transformations . . . . . . . . . . . . . . . . . . . . . . . . 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-5

Classical I I R F ilter Design Using Analog Prototyping . . . . . . . 2-7

CompleteClassical II R Filter Design . . . . . . . . . . . . . . . . . . . 2-7Designing I I R Filters to Frequency Domain Specifications . 2-8

Comparison of Classical I IR Filter Types . . . . . . . . . . . . . . . . . . 2-9

Butterworth Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-9

Chebyshev T ype I F ilter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10

Chebyshev T ype I I F ilter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11

Elliptic Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11

Bessel Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-12Direct I I R F ilter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-14

Generalized Butterworth Filter Design . . . . . . . . . . . . . . . . 2-15

FIR Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-17

L inear Phase Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-18

Windowing M ethod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-19

Page 6: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

iv Contents

StandardB and F I R F ilter Design: fir1 . . . . . . . . . . . . . . . . 2-21

M ultiband F I R F ilter Desi gn: fi r2 . . . . . . . . . . . . . . . . . . . . 2-22

Multiband FI R Filter Design with Transition Bands . . . . . . . 2-23

Basic Configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-23 The Weight Vector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-26

Anti-Symmetric Filters / Hilbert Transformers . . . . . . . . . . 2-26

Differentiators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-27

Constrained Least Squares FI R F ilter Design . . . . . . . . . . . . . 2-28

Basic Lowpass and Highpass CLS Filter Design . . . . . . . . . 2-29

M ultiband CL S F ilter Design . . . . . . . . . . . . . . . . . . . . . . . . 2-30

Weighted CL S F ilter Design . . . . . . . . . . . . . . . . . . . . . . . . . 2-31

Arbitrary-Response F ilter Design . . . . . . . . . . . . . . . . . . . . . . . 2-32

Multiband F ilter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-33

Filter Design with Reduced Delay . . . . . . . . . . . . . . . . . . . . 2-35

Special Topics in IIR Filter Design . . . . . . . . . . . . . . . . . . . . 2-38

Analog P rototype Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-39

F requency T ransformation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-39

Filter Discretization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-42I mpulse I nvariance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-42

Bilinear T ransformation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-43

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

3Statistical Signal Processing

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

Correlation and Covariance . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3

Bias and N ormalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4

Multiple Channels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-5

Spectral Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-6

Spectral Estimation Method Overview . . . . . . . . . . . . . . . . . . . . 3-8

Nonparametric M ethods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-10

The Periodogram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-10

Page 7: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

v

Performance of the Periodogram 3-12

The Modified Periodogram . . . . . . . . . . . . . . . . . . . . . . . . . . 3-18

Welch’s M ethod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-20

Bias and Normalization in Welch’s Method . . . . . . . . . . . . . 3-23Multitaper Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-24

Cross-Spectral Density Function . . . . . . . . . . . . . . . . . . . . . 3-27

Confidence I ntervals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-27

Transfer Function E stimate . . . . . . . . . . . . . . . . . . . . . . . . . 3-28

Coherence F unction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-29

Parametric M ethods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-30

Yule-Walker AR Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-32

Burg Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-33Covariance and Modified Covariance Methods . . . . . . . . . . 3-36

MUSIC and Eigenvector Analysis Methods . . . . . . . . . . . . . 3-36

E igenanalysi s Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-37

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

4Special Topics

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

Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3Basic Shapes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3

General ized Cosi ne Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-5

K aiser Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-5

K aiser Windows in F I R Design . . . . . . . . . . . . . . . . . . . . . . . . 4-7

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

Parametric Modeling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-11

Time-Domain Based Modeling . . . . . . . . . . . . . . . . . . . . . . . . . 4-13

L inear Prediction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-13

P rony’s M ethod (ARM A Modeling) . . . . . . . . . . . . . . . . . . . . 4-14

Steiglitz-McBride Method (ARMA Modeling) . . . . . . . . . . . 4-16

Frequency-Domain Based Modeling . . . . . . . . . . . . . . . . . . . . . 4-18

Page 8: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

vi Contents

Resampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-21

Cepstrum Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-24

I nverse C omplex Cepstrum . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-26

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

Median Filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-29

Communications Applications . . . . . . . . . . . . . . . . . . . . . . . . . 4-30

Deconvolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-34

Specialized Transforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-35

Chirp z-Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-35

Discrete Cosi ne T ransform . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-37

Hilbert Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-39

Selected Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-41

5Filter Design and Analysis Tool

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

F ilter Design M ethods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2

Using the Filter Design and Analysis Tool . . . . . . . . . . . . . . . . . 5-3

Analyzing F i lter Responses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3

Filter Design and Analysis Tool Modes . . . . . . . . . . . . . . . . . . . 5-3

Getting Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4

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

Getting Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-6

Context-Sensitive Help: TheWhat’s This? Button . . . . . . . . . . 5-6

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

Page 9: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

vii

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

Setting the Filter Design Specifications . . . . . . . . . . . . . . . . . 5-9

Bandpass Filter Frequency Specifications . . . . . . . . . . . . . . . . . 5-9Bandpass Filter M agnitude Specifications . . . . . . . . . . . . . . . . 5-10

Filter Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-11

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

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

Converting the Filter Structure . . . . . . . . . . . . . . . . . . . . . . . 5-14

Importing a Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-16

Filter Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-17

Direct Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-17

Direct Form II (Second-Order Sections) . . . . . . . . . . . . . . . . 5-17

State-Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-18

Lattice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-18Quantized F ilter (Qfilt Object) . . . . . . . . . . . . . . . . . . . . . . . 5-18

Exporting a Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-19

Exporting Filter Coefficients tothe Workspace . . . . . . . . . . . . 5-19

Exporting Filter Coefficients to a Text File . . . . . . . . . . . . . . . 5-20

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

6SPTool: A Signal Processing GUI Suite

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

SPTool: An Interactive Signal Processing Environment . . 6-3

SP Tool Data Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4

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

Page 10: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

viii Contents

Overview of the Signal Browser: Signal Analysis . . . . . . . . . 6-6

Opening the Signal Browser . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-6

Overview of the Filter Designer: Filter Design . . . . . . . . . . . 6-8Filter Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-8

FI R Filter Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-8

I IR Filter Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-8

Pole/Zero E ditor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-9

Spectral Overlay F eature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-9

Opening the F ilter Designer . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-9

Overview of the Filter Viewer: Filter Analysis . . . . . . . . . . 6-11

Opening the F ilter Viewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-11

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

Opening the Spectrum V iewer . . . . . . . . . . . . . . . . . . . . . . . . . 6-14

Getting Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-17

Context-Sensitive Help: The What’s This? Button . . . . . . . . . 6-17

Using SPTool: Filtering and Analysis of Noise . . . . . . . . . . 6-18

Importing a Signal into SPTool . . . . . . . . . . . . . . . . . . . . . . . . 6-19

Designing a Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-22

Opening the F ilter Designer . . . . . . . . . . . . . . . . . . . . . . . . . . .6-22

Speci fyi ng the B andpass F il ter . . . . . . . . . . . . . . . . . . . . . . . . . 6-22

Applying a Filter to a Signal . . . . . . . . . . . . . . . . . . . . . . . . . . 6-24

Analyzing Signals: Opening the Signal Browser . . . . . . . . . 6-26

Playing a Signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-27

Printing a Signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-28

Spectral Analysis in the Spectrum Viewer . . . . . . . . . . . . . . 6-29

Creating a P SD Object F rom a Signal . . . . . . . . . . . . . . . . . . . 6-29

Opening the Spectrum Viewer with Two Spectra . . . . . . . . . . 6-30

Printing the Spectra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-31

Page 11: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

ix

Exporting Signals, Filters, and Spectra . . . . . . . . . . . . . . . . 6-32

Opening the E xport Dialog Box . . . . . . . . . . . . . . . . . . . . . . . . . 6-32

Exporting a Filter to the MATLAB Workspace . . . . . . . . . . 6-33

Designing a Filter with the Pole/Zero Editor . . . . . . . . . . . . 6-34

Positioning P oles and Zeros . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-35

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

Accessing Filter Parameters in a Saved Filter . . . . . . . . . . 6-38

The tf F ield: Accessing Filter Coefficients . . . . . . . . . . . . . . . . 6-38

The Fs F ield: Accessing Filter Sample Frequency . . . . . . . . . . 6-38

The specs Field: Accessing other Filter Parameters . . . . . . . . 6-39

Accessing Parameters in a Saved Spectrum . . . . . . . . . . . . 6-42

Importing Filters and Spectra into SPTool . . . . . . . . . . . . . 6-43

I mporting F ilters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-43

I mporting Spectra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-45

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

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

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

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

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

7

Function Reference

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

abs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-16

ac2poly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-17

Page 12: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

x Contents

ac2rc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-18

angle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-19

arburg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-20

arcov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-21armcov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-22

aryule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-23

bartlett . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-24

besselap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-26

besself . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-27

bilinear . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-31

blackman . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-36

boxcar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-38buffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-39

buttap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-48

butter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-49

buttord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-54

cceps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-59

cell2sos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-61

cheb1ap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-62

cheb1ord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-63

cheb2ap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-67

cheb2ord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-68

chebwin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-73

cheby1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-75

cheby2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-80

chirp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-85

cohere . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-88conv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-92

conv2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-93

convmtx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-95

corrcoef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-97

corrmtx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-98

cov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-101

cplxpair . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-102

cremez . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-103

csd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-111

czt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-116

dct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-119

decimate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-121

deconv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-124

Page 13: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

xi

demod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-125

dftmtx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-127

diric . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-128

dpss . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-129

dpssclear . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-132

dpssdir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-133

dpssload . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-134

dpsssave . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-135

ellip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-136

ellipap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-142

ellipord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-143

eqtflength . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-148fdatool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-149

fft . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-151

fft2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-154

fftfilt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-155

fftshift . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-157

filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-158

filter2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-161

filtfilt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-162

filtic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-163

fir1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-165

fir2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-169

fircls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-172

fircls1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-175

firls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-178

firrcos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-183freqs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-185

freqspace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-188

freqz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-189

freqzplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-193

gauspuls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-196

gmonopuls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-198

grpdelay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-200

hamming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-203

hann . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-205

hilbert . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-207

icceps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-210

idct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-211

ifft . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-213

Page 14: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

xii Contents

ifft2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-214

impinvar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-215

impz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-217

interp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-220

intfilt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-223

invfreqs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-226

invfreqz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-230

is2rc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-233

kaiser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-234

kaiserord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-236

lar2rc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-241

latc2tf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-242latcfilt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-243

levinson . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-245

lp2bp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-247

lp2bs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-250

lp2hp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-252

lp2lp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-254

lpc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-256

lsf2poly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-260

maxflat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-261

medfilt1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-263

modulate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-264

pburg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-267

pcov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-273

peig . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-279

periodogram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-287pmcov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-293

pmtm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-299

pmusic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-305

poly2ac . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-314

poly2lsf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-315

poly2rc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-316

polyscale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-318

polystab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-319

prony . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-320

psdplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-322

pulstran . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-324

pwelch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-328

pyulear . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-335

Page 15: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

xiii

rc2ac . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-341

rc2is . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-342

rc2lar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-343

rc2poly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-344

rceps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-346

rectpuls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-347

remez . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-348

remezord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-356

resample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-359

residuez . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-362

rlevinson . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-365

rooteig . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-368rootmusic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-371

sawtooth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-374

schurrc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-375

seqperiod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-376

sgolay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-378

sgolayfilt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-380

sinc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-382

sos2cell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-384

sos2ss . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-385

sos2tf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-387

sos2zp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-389

sosfilt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-391

specgram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-392

sptool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-396

square . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-402ss2sos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-403

ss2tf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-407

ss2zp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-409

stmcb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-412

strips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-415

tf2latc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-417

tf2sos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-418

tf2ss . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-422

tf2zp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-424

tfe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-427

triang . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-431

tripuls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-433

udecode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-434

Page 16: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

xiv Contents

uencode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-437

unwrap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-440

upfirdn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-441

vco . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-445

xcorr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-447

xcorr2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-451

xcov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-452

yulewalk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-455

zp2sos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-458

zp2ss . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-462

zp2tf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-464

zplane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-466

8Filter Design and Analysis Tool Reference

Filter Design and Analysis GUI Overview . . . . . . . . . . . . . . . 8-2

Display Region . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-3

Display Region: Filter Specifications . . . . . . . . . . . . . . . . . . . 8-4

Display Region: Magnitude Response . . . . . . . . . . . . . . . . . . . 8-5

Display Region:Phase Response . . . . . . . . . . . . . . . . . . . . . . . 8-6

Display Region: Magnitude and Phase Response . . . . . . . . . 8-7

Display Region: Group Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-8

Display Region: Impulse Response . . . . . . . . . . . . . . . . . . . . . . 8-9

Display Region: Step Response . . . . . . . . . . . . . . . . . . . . . . . . 8-10

Display Region:Pole/Zero Plot . . . . . . . . . . . . . . . . . . . . . . . . 8-11

Page 17: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

xv

Display Region: Filter Coefficients . . . . . . . . . . . . . . . . . . . . 8-12

Filter Type Region . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-13

Lowpass F ilters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-13

Highpass F ilters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-14

Bandpass F ilters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-14

Bandstop F ilters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-15

Differentiator F ilters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-15

H ilbert T ransformer F ilters . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-15

Multiband F ilters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-15

Arbitrary M agni tude F ilters . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-16

Arbitrary Group Delay F ilters . . . . . . . . . . . . . . . . . . . . . . . . . . 8-16

Design Method Region . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-17

Current Filter Information Region . . . . . . . . . . . . . . . . . . . . 8-18

Convert Structure Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-19

Quantization Region . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-20

Frequency Specifications Region . . . . . . . . . . . . . . . . . . . . . . 8-21

Frequency Specifications Region: Lowpass Butterworth 8-23

Frequency Specifications Region:

Lowpass Chebyshev Type I . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-24

Frequency Specifications Region:

Lowpass Chebyshev Type II . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-25

Frequency Specifications Region: Lowpass Elliptic . . . . . 8-26

Frequency Specifications Region: Lowpass Equiripple . . 8-27

Frequency Specifications Region: Lowpass Least-Squares 8-28

Frequency Specifications Region: Lowpass Window . . . . . 8-29

Page 18: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

xvi Contents

Frequency Specifications Region: Highpass Butterworth 8-30

Frequency Specifications Region:

Highpass Chebyshev Type I. . . . . . . . . . . . . . . . . . . . . . . . . . .

8-31

Frequency Specifications Region:

Highpass Chebyshev Type II . . . . . . . . . . . . . . . . . . . . . . . . . . 8-32

Frequency Specifications Region: Highpass Elliptic . . . . . 8-33

Frequency Specifications Region:Highpass Equiripple . . 8-34

Frequency Specifications Region: Highpass Least-Squares 8-35

Frequency Specifications Region: Highpass Window . . . . 8-36

Frequency Specifications Region: Bandpass Butterworth 8-37

Frequency Specifications Region:Bandpass Chebyshev Type I . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-38

Frequency Specifications Region:

Bandpass Chebyshev Type II . . . . . . . . . . . . . . . . . . . . . . . . . . 8-39

Frequency Specifications Region: Bandpass Elliptic . . . . 8-40

Frequency Specifications Region: Bandpass Equiripple . 8-41

Frequency Specifications Region: Bandpass Least-Squares 8-42

Frequency Specifications Region: Bandpass Window . . . . 8-43

Frequency Specifications Region: Bandstop Butterworth 8-44

Frequency Specifications Region:

Bandstop Chebyshev Type I . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-45

Frequency Specifications Region:

Bandstop Chebyshev Type II . . . . . . . . . . . . . . . . . . . . . . . . . . 8-46

Page 19: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

xvii

Frequency Specifications Region: Bandstop Elliptic . . . . 8-47

Frequency Specifications Region: Bandstop Equiripple . 8-48

Frequency Specifications Region: Bandstop Least-Squares 8-49

Frequency Specifications Region: Bandstop Window . . . . 8-50

Magnitude Specifications Region . . . . . . . . . . . . . . . . . . . . . . 8-51

Magnitude Specifications Region: Lowpass Butterworth 8-53

Magnitude Specifications Region:

Lowpass Chebyshev Type I . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-54

Magnitude Specifications Region:

Lowpass Chebyshev Type II . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-55

Magnitude Specifications Region:Lowpass Elliptic . . . . . 8-56

Magnitude Specifications Region:Lowpass Equiripple . . 8-57

Magnitude Specifications Region: Lowpass Least-Squares 8-58

Magnitude Specifications Region: Lowpass Window . . . . . 8-59

Magnitude Specifications Region: Highpass Butterworth 8-60

Magnitude Specifications Region:

Highpass Chebyshev Type I . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-61

Magnitude Specifications Region:

Highpass Chebyshev Type II . . . . . . . . . . . . . . . . . . . . . . . . . . 8-62

Magnitude Specifications Region:Highpass Elliptic . . . . . 8-63

Magnitude Specifications Region: Highpass Equiripple . 8-64

Magnitude Specifications Region: Highpass Least-Squares 8-65

Page 20: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

xviii Contents

Magnitude Specifications Region: Highpass Window . . . . 8-66

Magnitude Specifications Region: Bandpass Butterworth 8-67

Magnitude Specifications Region:

Bandpass Chebyshev Type I . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-68

Magnitude Specifications Region:

Bandpass Chebyshev Type II . . . . . . . . . . . . . . . . . . . . . . . . . . 8-69

Magnitude Specifications Region:Bandpass Elliptic . . . . 8-70

Magnitude Specifications Region: Bandpass Equiripple . 8-71

Magnitude Specifications Region: Bandpass Least-Squares 8-72

Magnitude Specifications Region: Bandpass Window . . . . 8-73

Magnitude Specifications Region: Bandstop Butterworth 8-74

Magnitude Specifications Region:

Bandstop Chebyshev Type I . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-75

Magnitude Specifications Region:

Bandstop Chebyshev Type II . . . . . . . . . . . . . . . . . . . . . . . . . . 8-76

Magnitude Specifications Region:Bandstop Elliptic . . . . 8-77

Magnitude Specifications Region:Bandstop Equiripple . 8-78

Magnitude Specifications Region: Bandstop Least-Squares 8-79

Magnitude Specifications Region: Bandstop Window . . . . 8-80

Frequency and Magnitude Specifications Region:

Differentiator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-81

Frequency and Magnitude Specifications Region:

Hilbert Transformer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-82

Page 21: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

xix

Frequency and Magnitude Specifications Region:

Multiband . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-83

Frequency and Magnitude Specifications Region:

Arbitrary Magnitude . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-84

Frequency and Magnitude Specifications Region:

Arbitrary Group Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-85

Filter Order Region . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-86

Window Specification Region . . . . . . . . . . . . . . . . . . . . . . . . . 8-87

Import Filter Tab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-88

Import Filter Coefficients Region . . . . . . . . . . . . . . . . . . . . . . 8-89

Import Filter Coefficients: Direct Form . . . . . . . . . . . . . . . . 8-90

Import Filter Coefficients:

Direct Form II (Second-Order Sections) . . . . . . . . . . . . . . . . 8-91

Import Filter Coefficients: State-Space . . . . . . . . . . . . . . . . . 8-92

Import Filter Coefficients: Lattice . . . . . . . . . . . . . . . . . . . . . 8-93

Import Filter Coefficients: Quantized Filter (Qfilt Object) 8-94

Design Filter Tab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-95

Import Filter Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-96

Design Filter Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-97

Page 22: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

xx Contents

Page 23: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

Preface

Overview . . . . . . . . . . . . . . . . . . . . . 5-22

What Is the Signal Processing Toolbox? . . . . . . . 5-23

R12 Related Products List . . . . . . . . . . . . . . 5-24

How to Use This Manual . . . . . . . . . . . . . . 5-26I f You Are a N ew User . . . . . . . . . . . . . . . . 5-26If You Arean Experienced Toolbox User . . . . . . . . . 5-27All Toolbox U sers . . . . . . . . . . . . . . . . . . 5-27

Installing the Signal Processing Toolbox . . . . . . . 5-28

Technical Conventions . . . . . . . . . . . . . . . 5-29

Typographical Conventions . . . . . . . . . . . . . 5-30

Preface

Page 24: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

Preface

-22

Overview This chapter provides an introduction totheSignal Processing Toolbox and thedocumentation. I t contains the following sections:

• “What I s the Signal P rocessing Toolbox?”

• “R12 Related Products L ist”

• “How to Use This Manual”

•“I nstall ing the Signal Processing Toolbox”

• “Technical Conventions”

• “Typographical Conventions”

What Is the Signal Processing Toolbox?

Page 25: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

What Is the Signal Processing Toolbox?

-23

What Is the Signal Processing Toolbox? The Signal Processing Toolbox is a collection of tools built on the MATL AB®

numeric computing environment. The toolbox supports a wide range of signalprocessing operations, from waveform generation to filter design andimplementation, parametric modeling, and spectral analysis. The toolboxprovides two categori es of tools:

• Signal processing command line functions

• A suite of graphical user interfaces for:

- I nteractive filter design

- Signal plotting and analysis

- Spectral analysis

- F iltering signals

- Analyzing fil ter designs

Preface

Page 26: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

-24

R12 Related Products List The MathWorks provides several products that are especially relevant to thekinds of tasks you can perform with the Signal Processing Toolbox.

For more information about any of these products, see either:

• The online documentation for that product if it is installed or if you arereading the documentation from the CD

•The MathWorks Web site, at ht t p: / / www. mathworks. com; seethe “products”section

Note The toolboxes listed below all include functions that extend MATL AB’scapabiliti es. The blocksets all include blocks that extend Simulink’scapabilities.

Product Description

CommunicationsBlockset

Simulink block libraries for modeling thephysical layer of communications systems

Communications Toolbox MATLAB functions for modeling the physicallayer of communications systems

Data Acquisition Toolbox MATL AB functions for direct access to live,measured data from MATL AB

Database Toolbox Tool for connecting to, and interacting with,most ODBC/J DBC databases from withinMATLAB

DSP Blockset Simulink block libraries for the design,

simulation, and prototyping of digital signalprocessing systems

Fuzzy L ogic Toolbox Tool to help master fuzzy logic techniques andtheir application to practical control problems

R12 Related Products List

Page 27: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

R12 Related Products List

-25

I mage Processing

Toolbox

Complete suite of digital image processing and

analysis tools for MATL AB

Neural Network Toolbox Comprehensive environment for neuralnetwork research, design, and simulationwithin M ATL AB

Optimization Toolbox Tool for general and large-scaleoptimization of nonlinear problems, as well as for l inear

programming, quadratic programming,nonlinear least squares, and solving nonlinearequations

Simulink Interactive, graphical environment formodeling, simulating, and prototypingdynamic systems

Statistics Toolbox Tool for analyzing historical data, modelingsystems, developing statistical algorithms, andlearning and teaching statistics

System I dentification Toolbox

Tool for building accurate, simplified models of complex systems from noisy time-series data

Wavelet Toolbox Tool for signal and image analysis,

compression, and de-noising

Product Description

Preface

Page 28: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

-26

How to Use This Manual This sectionexplains how tousethedocumentation toget help about theSignalProcessing Toolbox. Read the topic that best fits your skill level:

• “I f Y ou Are a New User”

• “I f Y ou Are an E xperienced Toolbox User”

• “All Toolbox Users”

If You Are a New UserBegin with Chapter 1, “Signal Processing Basics.”This chapter introduces theMAT L AB signal processing environment through the toolbox functions. I tdescribes the basic functions of the Signal Processing Toolbox, reviewing itsusein basic waveform generation, filter implementation and analysis, impulseand frequency response, zero-pole analysis, linear system models, and thediscrete Fourier transform.

When you feel comfortable with the basic functions, moveon to Chapter 2 andChapter 3 for a more in-depth introduction to using the Signal Processing Toolbox:

• Chapter 2, “F ilter Design,” for a detailed explanation of using the Signal

Processing Toolbox in infinite impulse response (I I R) and finite impulseresponse (FI R) filter design and implementation, including special topics inIIR filter design.

• Chapter 3, “Statistical Signal P rocessing,” for how to use the correlation,covariance, and spectral analysis tools to estimate important functions of discrete random signals.

Once you understand the general principles and applications of the toolbox,learn how to use the interactive tools:

• Chapter 5, “F ilter Design and Analysis Tool,” and Chapter 6, “SPT ool: A

Signal Processing GUI Suite,” for an overview of the interactive GUIenvironments and examples of how to usethem for signal exploration, filterdesign and implementation, and spectral analysis.

Finally, see the following chapter:

How to Use This Manual

Page 29: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

-27

• Chapter 4, “Special Topics,” for specialized functions, including filter

windows, parametric modeling, resampling, cepstrum analysis,time-dependent F ouri er transforms and spectrograms, median fi lteri ng,communications applications, deconvolution, and specialized transforms.

If You Are an Experienced Toolbox UserSee Chapter 5, “Filter Design and Analysis Tool,” and Chapter 6, “SPT ool: ASignal Processing GUI Suite,” for an overview of the interactive GUI

environments and examples of how to usethem for signal viewing, filter designand implementation, and spectral analysis.

All Toolbox UsersUse Chapter 7, “Function Reference,” for locating information on specificfunctions. Referencedescriptions includea synopsis of thefunction’s syntax, aswell as a complete explanation of options and operations. Many reference

descriptions also include helpful examples, a description of the function’salgorithm, and references to additional reading material.

Use this manual in conjunction with the software to learn about the powerfulfeatures that MAT LAB provides. Each chapter provides numerous examplesthat apply the toolbox to representative signal processing tasks.

Some examples useMAT L AB’s random number generation function r andn. I nthese cases, to duplicatethe results in the example, type

r andn( ' state' , 0)

before running the example.

Preface

Page 30: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

-28

Installing the Signal Processing Toolbox To determineif theSignal Processing Toolbox is installed on your system, typethis command at the MATL AB prompt.

ver

When you enter this command, MAT LAB displays information about theversion of MATL AB you are running, including a list of all toolboxes installedon your system and their version numbers.

For information about installing the toolbox, see the MATLAB InstallationGuidefor your platform.

Technical Conventions

Page 31: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

-29

Technical Conventions

This manual and the Signal Processing Toolbox functions use the followingtechnical notations.

Nyquist frequency One-half the sampling frequency. Sometoolbox functions normalize this value to 1.

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

Ω or w Analog frequency in radians per second.

ω or w Digital frequency in radians per sample.

f Digital frequency in hertz.

[x, y) The interval from x to y, including x but not

including y.

. . . Ellipses in the argument list for a givensyntax on a function reference pageindicate all possible argument lists for thatfunction appearing prior to the givensyntax are valid.

Preface

Page 32: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

-30

Typographical Conventions

This manual uses some or all of theseconventions.

Item Convention to Use Example

Example code Monospace font To assign the value 5 to A,enter

A = 5

Function names/syntax Monospace font The cos function finds thecosine of each array element.

Syntax line example is

MLGet Var ML_ var _name

K eys Boldface with an initial

capital letter

Press the Return key.

L iteral strings (in syntaxdescri ptions in Referencechapters)

Monospacebol dfor literals f = f r eqspace( n, ' whol e' )

Mathematical expressions Italics for variables

Standard text font for

functions, operators, andconstants

This vector represents thepolynomial

MATLAB output Monospace font M ATL AB responds with

A =

5

Menu names, menu items, andcontrols

Boldface with an initialcapital letter

Choose the File menu.

New terms Italics An array is an orderedcollection of information.

String variables (from a finitelist)

Monospace i t al i cs sysc = d2c(sysd, ' met hod' )

p x2

2x 3+ +=

1

Page 33: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

Signal Processing Basics

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

Representing Signals . . . . . . . . . . . . . . . . 1-4

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

Working with Data . . . . . . . . . . . . . . . . . 1-13

Filter Implementation and Analysis . . . . . . . . . 1-14

The filter Function . . . . . . . . . . . . . . . . . 1-17

Other Functions for Filtering . . . . . . . . . . . . 1-19

Impulse Response . . . . . . . . . . . . . . . . . 1-23

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

Zero-Pole Analysis . . . . . . . . . . . . . . . . . 1-30

Linear System Models . . . . . . . . . . . . . . . 1-32

Discrete Fourier Transform . . . . . . . . . . . . . 1-44

Selected Bibliography . . . . . . . . . . . . . . . 1-47

1 Signal Processing Basics

Page 34: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-2

Overview

This chapter describes how to begin using MATL AB and theSignal Processing Toolbox for your signal processing applications. I t assumes a basic knowledgeand understanding of signals and systems, including such topics as filter andlinear system theory and basic Fourier analysis. The chapter covers thefollowing topics:

• “Signal Processing Toolbox Central F eatures”

• “Representing Signals”• “Waveform Generation: Ti me Vectors and Sinusoids”

• “Working with Data”

• “Filter I mplementation and Analysis”

• “The filter Function”

• “Other F unctions for F iltering”

• “I mpulse Response”

• “F requency Response”

• “Zero-Pole Analysis”

• “L inear System Models”

• “Discrete Fourier Transform”

• “Selected Bi bliography”

Many examples throughout the chapter demonstrate how to apply toolboxfunctions. I f you are not already familiar with M ATL AB’s signal processingcapabilities, use this chapter in conjunction with the software to try examplesand learn about the powerful features available to you.

Signal Processing Toolbox Central Features

Page 35: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-3

Signal Processing Toolbox Central Features

The Signal Processing Toolbox functions are algorithms, expressed mostly inM-files, that implement a variety of signal processing tasks. These toolboxfunctions are a speciali zed extension of the MAT L AB computational andgraphical environment.

Filtering and FFTs

Two of themost important functions for signal processing arenot in theSignalProcessing Toolbox at all, but are built-in MATL AB functions:

• f i l t er applies a digital filter to a data sequence.

• f f t calculates the discrete Fourier transform of a sequence.

The operations these functions perform are the main computationalworkhorses of classical signal processing. Both are described in this chapter. The Signal Processing Toolbox uses many other standard MATL AB functions

and language features, including polynomial root finding, complex arithmetic,matrix inversion and manipulation, and graphics tools.

Signals and Systems The basic entities that toolbox functions work with are signals and systems. The functions emphasize digital, or discrete, signals and filters, as opposed toanalog, or continuous, signals. The principal filter type the toolbox supports is

thelinear, time-invariant digital filter with a single input and a single output. You can represent l inear time-invariant systems using one of several models(such as transfer function, state-space, zero-pole-gain, and second-ordersection) and convert between representations.

Key Areas: Filter Design and Spectral AnalysisI n addition toits core functions, thetoolbox provides rich, customizablesupportfor the key areas of filter design and spectral analysis. I t is easy to implementa design technique that suits your application, design digital filters directly, orcreate analog prototypes and discretize them. Toolbox functions also estimatepower spectral density and cross spectral density, using either parametric ornonparametric techniques. “Filter Design” on page 2-1 and “Statistical SignalProcessing”on page 3-1 respectively detail toolbox functions for filter designand spectral analysis.

1 Signal Processing Basics

Page 36: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-4

There are functions for computation and graphical display of frequency

response, as well as functions for system identification; generating signals;discrete cosine, chirp-z, and Hilbert transforms; lattice filters; resampling;time-frequency analysis; and basic communication systems simulation.

Interactive Tools: SPTool and FDATool The power of the Signal Processing Toolbox is greatly enhanced by itseasy-to-useinteractive tools. SPTool provides a rich graphical environment for

signal viewing, filter design, and spectral analysis. The Filter Design andAnalysis Tool (FDAT ool) provides a more comprehensivecollection of featuresfor addressing the problem of filter design. The FDATool also offers seamlessaccess to the additional filter design methods and quantization features of theFilter Design Toolbox when that product is installed.

ExtensibilityPerhaps the most important feature of the MATL AB environment is that it is

extensible: MAT LAB lets you create your own M-fil es to meet numericcomputation needs for research, design, or engineering of signal processingsystems. Simply copy the M-files provided with the Signal Processing Toolboxandmodify them asneeded, or createnew functionstoexpandthefunctionalityof the toolbox.

Representing Signals

Page 37: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-5

Representing Signals

The central data construct in MATL AB is the numeric array, an orderedcollection of real or complex numeric data with two or more dimensions. Thebasic data objects of signal processing (one-dimensional signals or sequences,multichannel signals, and two-dimensional signals) are all naturally suited toarray representation.

Vector RepresentationMAT L AB represents ordinary one-dimensional sampled data signals, orsequences, as vectors. Vectors are 1-by-n or n-by-1 arrays, where n is thenumber of samples in the sequence. One way to introduce a sequence intoMATL AB is to enter it as a list of elements at the command prompt. Thestatement

x = [ 4 3 7 - 9 1]

creates a simple five-element real sequence in a row vector. Transpositionturns the sequence into a column vector

x = x'

resulting in

x =

4

3

7

- 9

1

Column orientation is preferable for single channel signals because it extendsnaturally to the multichannel case. For multichannel data, each column of amatrix represents one channel. Each row of such a matrix then corresponds toa sample point. A three-channel signal that consists of x, 2x, and x/π is

y = [ x 2*x x/ pi ]

1 Signal Processing Basics

Page 38: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-6

This results in

y =

4. 0000 8. 0000 1. 2732

3. 0000 6. 0000 0. 9549

7. 0000 14. 0000 2. 2282

- 9. 0000 - 18. 0000 - 2. 8648

1. 0000 2. 0000 0. 3183

Waveform Generation: Time Vectors and Sinusoids

Page 39: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-7

Waveform Generation: Time Vectors and Sinusoids

A variety of toolbox functions generate waveforms. Most require you to beginwith a vector representing a time base. Consider generating data with a 1000Hz sample frequency, for example. An appropriate time vector is

t = ( 0: 0. 001: 1) ' ;

where MAT L AB ’s colon operator creates a 1001-element row vector thatrepresents time running from zero to one second in steps of one millisecond.

The transpose operator ( ' ) changes the row vector into a column; thesemicolon (; ) tells MATL AB to compute but not display the result.

Given t you can create a sample signal y consisting of twosinusoids, one at 50Hz and one at 120 Hz with twice the amplitude.

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

The new variable y, formed from vector t , is also1001 elements long. You can

add normally distributed white noise to the signal and graph the first fiftypoints using

randn( ' state ' , 0) ;

yn = y + 0. 5*r andn( si ze( t ) ) ;

pl ot ( t ( 1: 50) , yn( 1: 50) )

0 0.01 0.02 0.03 0.04 0.05−3

−2

−1

0

1

2

3

4

1 Signal Processing Basics

Page 40: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-8

Common Sequences: Unit Impulse, Unit Step, and

Unit RampSince MATL AB is a programming language, an endless variety of differentsignals is possible. Here are some statements that generate several commonlyused sequences, including theunit impulse, unit step, and unit ramp functions.

t = ( 0: 0. 001: 1) ' ;

y = [1; zeros(99, 1) ] ; % i mpul se

y = ones( 100, 1) ; % st ep ( f i l t er assumes 0 i ni t i al cond. )

y = t ; % r ampy = t . 2;

y = square( 4*t ) ;

All of these sequences are column vectors. The last three inherit their shapesfrom t .

Multichannel Signals

Use standard MA TL AB array syntax to work with multichannel signals. Forexample, a multi channel signal consisting of the last three signals generatedabove is

z = [ t t . 2 squar e( 4*t ) ] ;

You can generatea multichannel unit sample function using theouter productoperator. For example, a six-element column vector whosefirst element is one,and whose remaining five elements are zeros, is

a = [ 1 zer os( 1, 5) ] ' ;

To duplicatecolumn vector a into a matrix without performing anymultiplication, use MATL AB’s colon operator and the ones function.

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

Page 41: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1 Signal Processing Basics

Page 42: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-10

Common Aperiodic Waveforms The toolbox also provides functions for generating several widely usedaperiodic waveforms:

• gauspul s generates a Gaussian-modulated sinusoidal pulse with a specifiedtime, center frequency, and fractional bandwidth. Optional parameters

return in-phase and quadrature pulses, the RF signal envelope, and thecutoff time for the trail ing pulse envelope.

• chi rp generates a linear swept-frequency cosine signal. An optional

parameter specifies alternative sweep methods. An optional parameter phi

allows initial phase to be specified in degrees.

To compute 2 seconds of a linear chirp signal with a sample rateof 1 kHz, thatstarts at DC and crosses 150 Hz at 1 second, use

t = 0: 1/ 1000: 2;

y = chi r p( t , 0, 1, 150) ;

To plot the spectrogram, use

specgr am( y, 256, 1000, 256, 250)

Time

F r e q u e n c y

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.60

50

100

150

200

250

300

350

400

450

500

Waveform Generation: Time Vectors and Sinusoids

Page 43: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-11

The pulstran Function The pul str an function generates pulse trains from either continuous orsampled prototype pulses. The following example generates a pulse trainconsisting of the sum of multiple delayed interpolations of a Gaussian pulse. The pulsetrain is defined to have a sample rateof 50 kHz, a pulse train lengthof 10 ms, and a pulserepetition rateof 1 kHz;Dspecifies thedelay toeach pulserepetition in column 1 and an optional attenuation for each repetition incolumn 2. The pulse train is constructed by passing the name of thegauspul s

function to pul st ran, along with additional parameters that specify a 10 kHz

Gaussian pulse with 50%bandwidth.

T = 0: 1/ 50E3: 10E- 3;

D = [ 0: 1/ 1E3: 10E- 3; 0. 8. ( 0: 10) ] ' ;

Y = pul st r an(T, D, ' gauspul s' , 10E3, 0. 5) ;

pl ot ( T, Y)

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

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

1 Signal Processing Basics

Page 44: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-12

The Sinc Function The s i nc function computes the mathematical sinc function for an input vectoror matrix x. The sinc function is the continuous inverse Fourier transform of the rectangular pulse of width and height 1.

The sinc function has a value of 1 where x is zero, and a value of

for all other elements of x.

To plot the sinc function for a linearly spaced vector with values ranging from-5 to 5, use the following commands.

x = l i nspace( - 5, 5) ;

y = si nc( x) ;

pl ot ( x, y)

π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

Waveform Generation: Time Vectors and Sinusoids

Page 45: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-13

The Dirichlet Function The toolbox function di r i c computes the Dirichlet function, sometimes calledthe periodic sinc or aliased sinc function, for an input vector or matrix x. TheDirichlet function is

where n is a user-specified positive integer. For n odd, the Dirichlet functionhas a period of ; for n even, its period is . The magnitude of this functionis (1/n) times the magnitude of the discrete-time F ourier transform of then-point rectangular window.

To plot the Dirichlet function over the range 0 to 4π for n =7 and n =8, use

x = l i nspace( 0, 4*pi , 300) ;

pl ot ( x, di r i c(x ,7) )pl ot ( x, di r i c(x ,8) )

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

nx 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 46: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-14

Working with Data

The examples in the preceding sections obtain data in one of two ways:

• By direct input, that is, entering the data manually at the keyboard

• By usinga MATL AB or toolbox function, such as si n, cos , sawt oot h, square,or s i nc

Some applications, however, may need to import data from outside MATL AB.Depending on your data format, you can do this in the following ways:

• Load data from an ASCII file or MAT -file with MAT LAB’s l oad command.

• Read thedata intoM ATL AB with a low-level file I /O function, such as f open,f r ead, and f scanf .

• Develop a ME X-file to read the data.

Other resources are also useful, such as a high-level language program (inFortran or C, for example) that converts your data into MAT -file format – seethe “MAT LAB External I nterfaces/AP I Reference” for details. MATL AB readssuch files using the l oad command.

Similar techniques are available for exporting data generated withinMATL AB. See theMATL AB documentation for more details on importing andexporting data.

Filter Implementation and Analysis

Page 47: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-15

Filter Implementation and Analysis

This section describes how to filter discrete signals using MATL AB’s f i l t er

function and other functions in theSignal Processing Toolbox. I t also discusseshow to use the toolbox functions to analyze filter characteristics, includingimpulse response, magnitude and phase response, group delay, and zero-polelocations.

Convolution and Filtering The mathematical foundation of filtering is convolution. MATL AB’s conv

function performs standard one-dimensional convolution, convolving onevector with another.

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

ans =

1 2 3 2 1

Note Convolve rectangular matrices for two-dimensional signal processingusing theconv2 function.

A digital filter’s output y(n) is related to its input x(n) by convolution with itsimpulse response h(n).

I f a digital filter’s impulse response h(n) is finite length, and the input x(n) isalsofinite length, you can implement thefilter using conv. Store x(n) in a vectorx, h(n) in a vector h, and convolve the two.

x = r andn( 5, 1) ; % A r andom vect or of l engt h 5

h = [ 1 1 1 1] / 4; % Lengt h 4 aver agi ng f i l t er

y = conv( h, x) ;

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

m ∞–=

å= =

1 Signal Processing Basics

Page 48: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-16

Filters and Transfer Functions

I n general, the z-transform Y(z) of a digital filter’s output y(n) is related tothez-transform X(z) of the input by

where H(z) is the filter’s transfer function. Here, theconstants b(i) and a(i) arethe filter coefficients and the order of the filter is the maximum of na and nb.

Note The filter coefficients start with subscript 1, rather than 0. This reflectsMAT L AB’s standard indexing scheme for vectors.

MATL AB stores the coefficients in twovectors, one for the numerator and onefor the denominator. By convention, MAT LAB uses row vectors for filtercoefficients.

Filter Coefficients and Filter Names

Many standard names for filters reflect the number of a and b coefficientspresent:

• When nb =0 (that is, b is a scalar), thefilter is an I nfiniteI mpulse Response(II R), all-pole, recursive, or autoregressive (AR) filter.

When na =0 (that is, a is a scalar), the filter is a Finite I mpulse Response(FI R), all-zero, nonrecursive, or moving average (MA) filter.

• If both na and nb are greater than zero, the filter is an II R, pole-zero,recursive, or autoregressive moving average (ARM A) filter.

The acronyms AR, MA, and ARMA are usually applied to filters associatedwith filtered stochastic processes.

Y z( ) H z( )X z( )b 1( ) b 2( )z 1–

L b n b 1+( )z nb–+ + +

a 1( ) a 2( )z 1–L a na 1+( )z na–+ + +

------------------------------------------------------------------------------------------- -X z( )= =

Filter Implementation and Analysis

Page 49: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-17

Filtering with the filter Function

I t is simpleto work back to a difference equation from thez-transform relationshown earlier. Assume that a(1) =1. Move the denominator to the left-handside and take the inverse z-transform.

I n terms of current and past inputs, and past outputs, y(n) is

This is the standard time-domain representation of a digital filter, computedstarting with y(1) and assuming zero initial conditions. This representation’sprogression is

A filter in this form is easy to implement with the f i l t er function. Forexample, a simple single-pole filter (lowpass) is

b = 1; % Numer at or

a = [ 1 - 0. 9] ; % Denomi nat or

where the vectors b and a represent the coefficients of a filter in transferfunction form. To apply this filter to your data, use

y = f i l ter ( b, a, x) ;

f i l t er gives you as many output samples as there are input samples, that is,the length of y is the same as the length of x. I f the first element of a is not 1,f i l t er divides the coefficients by a(1) before implementing the difference

equation.

y n( ) a2y n 1–( ) L ana 1+y n na–( )+ + + b1x n( ) b2x n 1–( ) L bnb 1+

x n nb–( )+ + +=

y n( ) b1x n( ) b2x n 1–( )L

bnb 1+ x n nb–( ) a2y n 1–( )L

– ana 1+ y n na–( )––+ + +=

y 1( ) b1x 1( )=

y 2( ) b1x 2( ) b2x 1( ) a2y 1( )–+=

y 3( ) b1x 3( ) b2x 2( ) b3x 1( ) a2y 2( ) a3y 1( )––+ +=

=

1 Signal Processing Basics

Page 50: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-18

The filter Function

f i l t er is implemented asthetransposed direct-form I I structure shown below,where n-1 is the filter order. This is a canonical form that has the minimumnumber of delay elements.

At sample m, f i l t er computes the difference equations

I n its most basic form, f i l t er initializes the delay outputs zi(1), i =1, ..., n-1

to 0. This is equivalent to assuming both past inputs and outputs are zero. Setthe initial delay outputs using a fourth input parameter to f i l t er , or accessthe final delay outputs using a second output parameter.

[ y, zf ] = f i l t er ( b, a, x, zi )

Access to initial and final conditions is useful for fi ltering data in sections,especially if memory limitations are a consideration. Suppose you havecoll ected data in two segments of 5000 points each.

x1 = r andn( 5000, 1) ; % Generate t wo r andom dat a sequences.

x2 = r andn( 5000, 1) ;

Perhaps the first sequence, x1, corresponds to thefirst 10 minutes of data andthesecond, x2, toan additional 10minutes. The whole sequenceis x =[ x1; x2] .I f there is not sufficient memory to hold the combined sequence, filter the

Σ Σ Σ z -1 z -1

x(m)

y(m)

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

– a(3) –a(2)

z1(m) z2(m)

Σ z -1

b(n)

–a(n)

zn -1(m)

...

...

...

y m( ) b 1( )x m( ) z1

m 1–( )+=

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

=

zn 2–m( ) b n 1–( )x m( ) zn 1–

m 1–( ) a n 1–( )y m( )–+=

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

The filter Function

Page 51: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-19

subsequences x1 and x2 one at a time. To ensure continuity of the filtered

sequences, use the final conditions from x1 as initial conditions to filter x2.[ y1, z f ] = f i l ter ( b, a, x1) ;

y2 = f i l t er( b, a, x2, zf ) ;

The f i l t i c function generates initial conditions for f i l t er . f i l t i c computesthe delay vector to make the behavior of the filter reflect past inputs andoutputs that you specify. To obtain the same output delay values zf as aboveusing f i l t i c, use

z f = f i l t i c(b, a, f l i pud(y1) , f l i pud(x1) ) ;

This can be useful when fi ltering short data sequences, as appropriate initialconditions help reduce transient startup effects.

1 Signal Processing Basics

Page 52: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-20

Other Functions for Filtering

I n addition tof i l t er , several other functions in the Signal P rocessing Toolboxperform the basic filtering operation. These functions include upf i r dn, whichperforms FI R filtering with resampling, f i l t f i l t , which eliminates phasedistortion in the filtering process, f f t f i l t , which performs the FI R filteringoperation in the frequency domain, and l at cf i l t , which filters using a latticeimplementation.

Multirate Filter Bank Implementation The function upf i rdn alters the sampling rate of a signal by an integer ratioP/Q. I t computes the result of a cascade of three systems that performs thefollowing tasks:

• Upsampling (zero insertion) by integer factor p

• Filtering by FI R filter h

• Downsampling by integer factor q

For example, tochangethesample rateof a signal from 44.1 kHz to48 kHz, wefirst find the smallest integer conversion ratio p/ q. Set

d = gcd(48000, 44100) ;

p = 48000/ d;

q = 44100/ d;

I n this example, p =160 and q =147. Sample rate conversion is thenaccomplished by typing

y = upf i rdn(x, h, p, q)

This cascade of operations is implemented in an efficient manner usingpolyphasefiltering techniques, and it is a central concept of multirate filtering(see reference[1] for details on multiratefilter theory). Note that thequality of the resampling result relies on the quality of the FI R filter h.

Px(n) y(n)FIRH Q

Other Functions for Filtering

Page 53: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-21

Filter banks may be implemented using upf i r dn by allowing the filter h to be

a matrix, with one F I R fi lter per column. A signal vector is passedindependently through each FI R filter, resulting in a matrix of output signals.

Other functions that perform multirate filtering (with fixed filter) includer esampl e, i nterp, and deci mat e.

Anti-Causal, Zero-Phase Filter ImplementationI n thecase of FI R filters, it is possible to design linear phase filters that, when

applied to data (using f i l t er or conv), simply delay the output by a fixednumber of samples. For I I R filters, however, the phase distortion i s usuallyhighly nonlinear. The f i l t f i l t function uses the information in the signal atpoints before and after the current point, in essence “looking into the future,”to eliminate phase distortion.

To see how f i l t f i l t does this, recall that if thez-transform of a real sequencex(n) is X(z), the z-transform of the time reversed sequence x(n) is X(1/z).Consider the processing scheme

When | z| =1, that is z =e jω, the output reduces to X(e jω)| H(e jω)| 2. Given allthe samples of the sequence x(n), a doubly filtered version of x that haszero-phase distortion is possible.

F or example, a 1-second duration signal sampled at 100 Hz, composed of twosinusoidal components at 3 Hz and 40 Hz, is

f s = 100;

t = 0: 1/ f s: 1;

x = si n( 2*pi *t *3) +. 25*si n( 2*pi *t *40) ;

H ( z) X ( z)

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

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

ReverseTime

Reverse

Page 54: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

Other Functions for Filtering

Page 55: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-23

Frequency Domain Filter Implementation

Duality between the timedomain and the frequency domain makes it possibleto perform any operation in either domain. Usually one domain or the other ismore convenient for a particular operation, but you can always accomplish agiven operation in either domain.

To implement general I I R filtering in the frequency domain, multiply thediscreteFourier transform (DF T) of theinput sequencewith thequotient of theDFT of the filter.

n = l engt h( x) ;y = i f f t ( f f t ( x) . *f f t ( b, n) . / f f t ( a, n) ) ;

This computes results that are identical to f i l t er , but with different startuptransients (edge effects). For long sequences, this computation is veryinefficient because of the large zero-padded FFT operations on the filtercoefficients, and because the FF T algorithm becomes less efficient as thenumber of points n increases.

For FI R filters, however, it is possible to break longer sequences into shorter,computationally efficient FFT lengths. The function

y = f f t f i l t ( b, x)

uses the overlap add method (see reference [1] at the end of this chapter) tofilter a long sequence with multiple medium-length FF Ts. I ts output isequivalent to f i l t er ( b, 1, x) .

1 Signal Processing Basics

Page 56: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-24

Impulse Response

The impulse response of a digital filter is the output arising from the unitimpulse input sequence defined as

I n MAT L AB, you can generate an impulse sequence a number of ways; one

straightforward way isi mp = [ 1; zeros( 49, 1) ] ;

The impulse response of the simple filter b =1 and a =[ 1 - 0. 9] is

h = f i l t er( b, a, i mp) ;

The i mpz function in thetoolbox simplifiesthis operation, choosing thenumberof points to generate and then making a stem plot (using the stemfunction).

i mpz( b, a)

The plot shows the exponential 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

.1

.2

.3

.4

.5

.6

.7

.8

.9

1

Frequency Response

Page 57: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-25

Frequency Response

The Signal Processing Toolbox enables you to perform frequency domainanalysis of both analog and digital filters.

Digital Domainf r eqz uses an FF T-based algorithm to calculate the z-transform frequencyresponse of a digital filter. Specifically, the statement

[ h, w] = f r eqz( b, a, n)

returns the n-point complex frequency response, , of the digital filter.

I n its simplest form, f r eqz accepts the filter coefficient vectors b and a, and aninteger n specifying the number of points at which to calculate the frequency

response. f r eqz returns the complex frequency response in vector h, and theactual frequency points in vector win rad/s.

f r eqz can accept other parameters, such as a sampling frequency or a vector of arbitrary frequency points. The example below finds the 256-point frequencyresponse for a 12th-order Chebyshev type I filter. The call to f r eqz specifies asampling frequency f s of 1000 Hz.

[ b, a] = cheby1( 12, 0. 5, 200/ 500) ;

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

Because the parameter li st includes a sampling frequency, f r eqz returns avector f that contains the 256 frequency points between 0 andf s / 2 used in thefrequency response calculation.

H e j ω

( )

H e j ω( )b 1( ) b 2( )e j– ω

L b nb 1+( )e j– ω nb( )+ + +

a 1( ) a 2( )e j– ωL a na 1+( )e j– ω na( )+ + +

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

1 Signal Processing Basics

Page 58: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-26

Frequency Normalization This toolbox uses the convention that unitfrequency is the Nyquist frequency, defined as half the sampling frequency. The cutoff frequency parameter for all basic filter design functions isnormalized by the Nyquist frequency. For a system with a 1000 Hz samplingfrequency, for example, 300 Hz is 300/500 =0.6. To convert normalizedfrequency to angular frequency around the unit circle, multiply by π. Toconvert normalized frequency back to hertz, multiply by half the samplefrequency.

If you call f r eqz with no output arguments, it automatically plots bothmagnitude versus frequency and phase versus frequency. For example, aninth-order Butterworth lowpass filter with a cutoff frequency of 400 Hz, basedon a 2000 Hz sampling frequency, is

[ b, a] = but t er ( 9, 400/ 1000) ;

Now calculatethe256-point complex frequency responsefor this filter, and plotthe magnitude and phasewith a call to f r eqz.

f r eqz( b, a, 256, 2000)

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

-800

-600

-400

-200

0

Frequency (Hertz)

P h a s e ( d

e g r e e s )

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

-300

-200

-100

0

100

Frequency (Hertz)

M a g n i t u d e R

e s p o n s e ( d B )

Frequency Response

f r eq can also accept a vector of arbitrary frequency points for use in the

Page 59: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-27

f r eqz can also accept a vector of arbitrary frequency points for use in the

frequency response calculation. For example,w = l i nspace( 0, pi ) ;

h = f r eqz( b, a, w) ;

calculates the complex frequency responseat the frequency points in wfor thefilter defined by vectors b and a. Thefrequency points can range from 0 to . To specify a frequency vector that ranges from zero toyour sampling frequency,include both thefrequency vector and the sampling frequency value in the

parameter list.

Analog Domainf r eqs evaluates frequency response for an analog filter defined by two inputcoefficient vectors, b and a. I ts operation is similar to that of f r eqz; you canspecify a number of frequency points to use, supply a vector of arbitraryfrequency points, and plot the magnitude and phase response of the filter.

Magnitude and PhaseMATL AB provides functions to extract magnitudeand phase from a frequencyresponse vector h. The function abs returns the magnitude of the response;angl e returns the phase angle in radians. To extract and plot the magnitudeand phase of a Butterworth filter.

[ b, a] = but t er ( 6, 300/ 500) ;

[ h, w] = f r eqz( b, a, 512, 1000) ;

m = abs( h) ; p = angl e(h) ;

semi l ogy( w, m) ; t i t l e( ' Magni t ude' ) ;

f i gure; pl ot ( w, p*180/ pi ) ; t i t l e( ' Phase' ) ;

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

The unwr ap function is also useful in frequency analysis unwr ap unwraps the

Page 60: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-28

The unwr ap function is also useful in frequency analysis. unwr ap unwraps the

phase to make it continuous across 360° phase discontinuities by addingmultiples of ±360°, as needed. To see how unwr ap is useful, design a 25th-orderlowpass FI R filter.

h = f i r 1( 25, 0. 4) ;

Obtain the filter’s frequency response with f r eqz, and plot the phase indegrees.

[ H, f ] = f r eqz( h, 1, 512, 2) ;

pl ot ( f , angl e( H) *180/ pi ) ; gr i d

I t is difficult to distinguish the 360° jumps (an artifact of the arctangentfunction insideangl e) from the180° jumps that signify zeros in the frequencyresponse.

Useunwr ap to eliminate the 360° jumps.

pl ot ( f , unwr ap( angl e( H) ) *180/ pi ) ; gr i d

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

-150

-100

-50

0

50

100

150

200

Frequency Response

Page 61: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-29

Delay The group delay of a filter is a measure of the average delay of the filter as afunction of frequency. I t is defined as the negative first derivative of a filter’sphase response. I f the complex frequency response of a filter is , thenthe group delay is

where θ is the phase angle of . Compute group delay with

[ gd, w] = gr pdel ay( b, a, n)

which returns then-point group delay, , of the digital filter specified by b

and a, evaluated at the frequencies in vector w.

The phase delay of a filter is the negative of phase divided by frequency

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

-1200

-1000

-800

-600

-400

-200

0

H e j ω

( )

τg ω( )dθ ω( )

dω---------------–=

H e j ω

( )

τg ω( )

τp ω( ) θ ω( )

ω-----------–=

1 Signal Processing Basics

To plot both the group and phase delays of a system on the same graph, type

Page 62: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-30

To plot both the group and phase delays of a system on the same graph, type

[ b, a] = but t er ( 10, 200/ 1000) ;gd = gr pdel ay( b, a, 128) ;

[ h, f ] = f r eqz( b, a, 128, 2000) ;

pd = - unwr ap( angl e( h) ) *( 2000/ ( 2*pi ) ) . / f ;

pl ot ( f , gd, ' - ' , f , pd, ' - - ' )

axi s( [ 0 1000 - 30 30] )

l egend( ' Gr oup Del ay' , ' Phase Del ay' )

0 200 400 600 800 1000−30

−20

−10

0

10

20

30Group DelayPhase Delay

Zero-Pole Analysis

Zero-Pole Analysis

Page 63: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-31

Zero Pole Analysis

The zpl ane function plots poles and zeros of a linear system. For example, asimple filter with a zero at -1/2 and a complex pole pair at and

is

zer = - 0. 5;

pol = 0. 9*exp( j *2*pi *[ - 0. 3 0. 3] ' ) ;

The zero-pole plot for the filter is

zpl ane( zer , pol )

For a system in zero-pole form, supply column vector arguments z and p tozpl ane.

zpl ane( z, p)

For a system in transfer function form, supply row vectors b and a asarguments to zpl ane.

zpl ane( b, a)

0.9e j 2π 0.3( )

0.9e j– 2π 0.3( )

-1 -0.5 0 0.5 1

-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

Real part

I m a g i n a r y p a r t

1 Signal Processing Basics

I n this casezpl ane finds theroots of b and a usingthe roots function and plots

Page 64: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-32

the resulting zeros and poles.

See “Linear System Models” on page 1-33for details on zero-pole and transferfunction representation of systems.

Linear System Models

Linear System Models

Page 65: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-33

y

The Signal Processing Toolbox provides several models for representing lineartime-invariant systems. This flexibility lets you choose the representationalscheme that best suits your application and, within the bounds of numericstability, convert freely to and from most other models. This section provides abrief overview of supported linear system models and describes how to workwith these models in M ATL AB.

Discrete-Time System Models The discrete-time system models are representational schemes for digitalfilters. MAT L AB supports several discrete-time system models, which aredescribed in the following sections:

• “Transfer Function”

• “Zero-Pole-Gain”

• “State-Space”

• “Partial Fraction E xpansion (Residue Form)”

• “Second-Order Sections (SOS)”

• “LatticeStructure”

• “Convolution Matrix”

Transfer Function

The transfer function is a basic z-domain representation of a digital filter,expressing the filter as a ratio of two polynomials. I t is the principaldiscrete-time model for this toolbox. The transfer function model descriptionfor the z-transform of a digital filter’s difference equation is

Here, the constants b(i) and a(i) are the filter coefficients, and the order of the

filter is themaximum of na and nb. I n MATL AB, you store these coefficients intwo vectors (row vectors by convention), one row vector for the numerator andone for the denominator. See“Filters and Transfer F unctions” on page 1-16formore details on the transfer function form.

Y z( )b 1( ) b 2( )z 1–

L b nb 1+( )z nb–+ + +

a 1( ) a 2( )z 1–L a na 1+( )z na–+ + +

-------------------------------------------------------------------------------------------- X z( )=

1 Signal Processing Basics

Zero-Pole-Gain

Page 66: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-34

The factored or zero-pole-gain form of a transfer function is

By convention, MAT L AB stores polynomial coefficients in row vectors andpolynomial roots in column vectors. I n zero-pole-gain form, therefore, the zeroand pole locations for the numerator and denominator of a transfer functionreside in column vectors. The factored transfer function gain k isa M ATLAB

scalar.

The pol y and roots functions convert between polynomial and zero-pole-gainrepresentations. For example, a simple I I R fi lter is

b = [ 2 3 4] ;

a = [ 1 3 3 1] ;

The zeros and poles of this filter are

q = r oot s( b)

q =

- 0. 7500 + 1. 1990i

- 0. 7500 - 1. 1990i

p = r oot s( a)

p =

- 1. 0000- 1. 0000 + 0. 0000i

- 1. 0000 - 0. 0000i

k = b( 1) / a( 1)

k =

2

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

bb =

2. 0000 3. 0000 4. 0000

H z( )q z( )

p z( )---------- k

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

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

Linear System Models

aa = pol y( p)

Page 67: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-35

aa =1. 0000 3. 0000 3. 0000 1. 0000

Note that b and a in this case represent the transfer function

For b =[ 2 3 4] , the roots function misses the zero for z equal to 0. I n fact, it

misses poles and zeros for z equal to0 whenever theinput transfer function hasmore poles than zeros, or vice versa. This is acceptable in most cases. Tocircumvent theproblem, however, simply append zerosto makethevectors thesame length before using the roots function; for example, b =[ b 0] .

State-Space

I t is always possible to represent a digital filter, or a system of differenceequations, as a set of first-order difference equations. I n matrix or state-spaceform, you can write the equations as

where u is the input, x is the state vector, and y is the output. F orsingle-channel systems, A is an m-by-mmatrix where mis theorder of thefilter,B is a column vector, C is a row vector, and D is a scalar. State-space notation is

especially convenient for multichannel systems where input u and output ybecome vectors, and B, C, and Dbecome matri ces.

State-space representation extends easily to the MAT L AB environment. I nMATLAB, A, B, C, and Dare rectangular arrays; MA TL AB treats them asindividual variables.

Taking thez-transform of thestate-spaceequations andcombiningthem showsthe equivalence of state-space and transfer function forms.

Don’t be concerned if you are not familiar with the state-space representationof l inear systems. Some of the filter design algorithms use state-space forminternally but donot requireany knowledgeof state-spaceconceptsto usethem

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

1 3z 1– 3z 2– z 3–+ + +------------------------------------------------------

2z3 3z2 4z+ +

z3 3z2 3z 1+ + +--------------------------------------------= =

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

y n( ) Cx n( ) Du n( )+=

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

1 Signal Processing Basics

successfully. I f your applications use state-space based signal processingextensively however consult theContr ol System Toolbox for a comprehensive

Page 68: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-36

extensively, however, consult theContr ol System Toolbox for a comprehensivelibrary of state-space tools.

Partial Fraction Expansion (Residue Form)

Each transfer function also has a corresponding partial fraction expansion orresidue form representation, given by

provided H(z) has no repeated poles. Here, n is the degree of the denominatorpolynomial of therational transfer function b(z)/a(z).If r is a pole of multiplicitysr, then H(z) has terms of theform

The r esi duez function in the Signal Processing Toolbox converts transferfunctions toand from thepartial fraction expansion form. The “z”on theend of r esi duez stands for z-domain, or discrete domain. r esi duez returns the polesin a column vector p, the residues corresponding to the poles in a columnvector r , and any improper part of the original transfer function in a rowvector k. r esi duez determines that twopoles are the same if the magnitudeof their difference is smaller than 0.1 percent of either of the poles’ magnitudes.

Partial fraction expansion arises in signal processing as one method of finding

theinversez-transform of a transfer function. For example, thepartial fractionexpansion of

is

b = [ - 4 8] ;

a = [ 1 6 8] ;[ r , p, k] = r esi duez( b, a)

b z( )

a z( )----------

r 1( )

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

r n( )

1 p n( )z 1––----------------------------- k 1( ) k 2( )z 1–

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

r j( )

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

r j 1+( )

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

r j sr 1–+( )

1 p j( )z 1––( )sr

------------------------------------+ + +

H z( )4– 8z 1–+

1 6z 1– 8z 2–+ +----------------------------------------=

Linear System Models

r =

- 12

Page 69: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-37

8

p =

- 4

- 2

k =

[ ]

which corresponds to

To find theinversez-transform of H(z), find thesum of theinversez-transformsof the two addends of H(z), giving the causal impulse response

To verify this in MATLAB, type

i mp = [ 1 0 0 0 0] ;

r espt f = f i l t er ( b, a, i mp)

r espt f =

- 4 32 - 160 704 - 2944

respres = f i l t er( r ( 1) , [ 1 - p( 1) ] , i mp) + f i l t er( r ( 2) , [ 1 - p( 2) ] , i mp)

respres =

- 4 32 - 160 704 - 2944

H z( )12–

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

8

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

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

1 Signal Processing Basics

Second-Order Sections (SOS)

Page 70: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-38

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

where L is the number of second-order sections that describe the system.MAT L AB represents thesecond-order section form of a discrete-timesystem asan L -by-6 array sos . Each row of sos contains a single second-order section,

where the row elements are the three numerator and three denominatorcoefficients that describe the second-order section.

There are an uncountable number of ways to represent a filter in second-ordersection form. Through careful pairing of thepole and zero pairs, orderingof thesections in the cascade, and multiplicative scaling of the sections, it is possibleto reduce quantization noise gain and avoid overflow in some fixed-point filterimplementations. The functions zp2sos and ss2sos, described in “L inearSystem Transformations” on page 1-43, perform pole-zero pairing, sectionscaling, and section ordering.

Note I n the Signal P rocessing Toolbox, all second-order sectiontransformations apply only to digital filters.

Lattice Structure

For a discrete Nth order all-pole or all-zero filter described by the polynomialcoefficients a(n), n =1, 2, …, N+1, there are N corresponding lattice structurecoefficients k(n), n =1, 2, …, N. The parameters k(n) are also called thereflection coefficients of the filter. Given these reflection coefficients, you canimplement a discrete filter as shown below.

H z( ) H k z( )

k 1=

L

∏b0k b1kz 1– b2kz 2–+ +

a0k a1kz 1– a2kz 2–+ +----------------------------------------------------------

k 1=

L

∏= =

sos

b01 b11 b21 a01 a11 a21

b02 b12 b22 a02 a12 a22

M M M M M M

b0

L b1

L b2

L a0

L a1

L a2

L

=

Linear System Models

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

Page 71: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-39

For a general pole-zero I I R filter described by polynomial coefficients a and b,there are both lattice coefficients k(n) for the denominator a and laddercoefficients v(n) for the numerator b. The lattice/ladder filter may beimplemented as

The toolbox function t f 2l at c accepts an F I R or I I R filter in polynomial form

and returns the corresponding reflection coefficients. An example FI R 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

FI R Lattice Fi lter

x(m)

Σ

Σ y(m)

k(1)

–k(1) Σ

k(n)

–k(n) . . .

. . . z -1 Σ z -1

I IR Lattice Fi lter

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)ARMAoutput

1 Signal Processing Basics

This filter’s lattice (reflection coefficient) representation is

Page 72: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-40

k = t f 2l at c( b)

k =

0. 3090

0. 9801

0. 0031

0. 0081

- 0. 0082

For I I R filters, the magnitude of the reflection coefficients provides an easystability check. I f all the reflection coefficients corresponding to a polynomialhave magnitudeless than 1, all of that polynomial’s roots are inside the unitcircle. For example, consider an I I R fi lter with numerator polynomial b fromabove and denominator polynomial

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

The filter’s lattice representation i s

[ k, v] = t f 2l at c(b, a)

k =

0. 3750

0. 3333

0

0

0

v =

0. 6252

0. 1212

0. 9879

- 0. 0009

0. 0072

- 0. 0082

Because abs( k) <1 for all reflection coefficients in k, the filter is stable.

Linear System Models

The function l atc2t f calculates the polynomial coefficients for a filter fromitslattice (reflection) coefficients. Given the reflection coefficient vector k( above),

th di l i l f i

Page 73: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-41

the corresponding polynomial form is

b = l at c2t f ( k)

b =

1. 0000 0. 6149 0. 9899 - 0. 0000 0. 0031 - 0. 0082

The lattice or lattice/ladder coefficients can be used to implement the filterusing the function l at cf i l t .

Convolution Matrix

I n signal processing, convolving two vectors or matrices is equivalent tofiltering one of the input operands by the other. This relationship permits therepresentation of a digital fil ter as a convolution matri x.

Given anyvector, the toolbox function convmt x generates a matrix whosei nnerproduct with another vector is equivalent to the convolution of the two vectors.

The generated matrix represents a digital filter that you can apply to anyvector of appropriate length; the inner dimension of the operands must agreeto compute the inner product.

The convolution matrix for a vector b, representing the numerator coefficientsfor a digital filter, is

b = [ 1 2 3] ; x = r andn( 3, 1) ;

C = convmt x( b' , 3)

C =

1 0 0

2 1 0

3 2 1

0 3 2

0 0 3

Two equivalent ways to convolve b with x are as follows.

y1 = C*x;

y2 = conv( b, x) ;

1 Signal Processing Basics

Continuous-Time System Models

The continuous time system models are representational schemes for analog

Page 74: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-42

The continuous-time system models are representational schemes for analogfilters. Many of the discrete-time system models described earlier are alsoappropriate for the representation of continuous-time systems:

• State-space form

• Partial fraction expansion

• Transfer function

• Zero-pole-gain form

I t is possible to represent any system of linear time-invariant differentialequations as a set of first-order differential equations. I n matrix or state-space

form, you can express the equations as

whereu is a vector of nu inputs, x isan nx-element statevector, and y is a vector

of ny outputs. I n MATL AB, store A, B, C, and D in separate rectangular arrays.

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

where

For single-input, single-output systems, this form is given by

Given the coefficients of a L aplace transform transfer function, r esi due

determines the partial fraction expansion of the system. See the description of

r esi due in the MATL AB documentation for details.

The factored zero-pole-gain form is

x· Ax B u+=

y Cx Du+=

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

H s( ) C sI A–( ) 1–

B D+=

H s( )b s( )

a s( )----------

b 1( )snb b 2( )snb 1– b n b 1+( )+ + +

a 1( )sna a 2( )sna 1– a na 1+( )+ + +-------------------------------------------------------------------------------------------------= =

H s( )z s( )

p s( )---------- k

s z 1( )–( ) s z 2( )–( ) s z n( )–( )s p 1( )–( ) s p 2( )–( ) s p n( )–( )

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

Linear System Models

As in the discrete-time case, MATL AB stores polynomial coefficients in rowvectors in descending powers of s. MATL AB stores polynomial roots, or zeros

and poles in column vectors

Page 75: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-43

and poles, in column vectors.

Linear System Transformations The Signal Processing Toolbox provides a number of functions that convertbetween the various li near system models; see Chapter 7, “FunctionReference,” for a complete description of each. You can use the following chartto find an appropriate transfer function: find the row of the model to convert

from on the left side of the chart and the column of the model to convert to onthetopof thechart and readthefunction name(s) at theintersection of therowand column.

Many of the toolbox filter design functions use these functions internally. For

example, the zp2ss function converts the poles and zeros of an analogprototype into the state-space form required for creation of a Butterworth,Chebyshev, or elliptic filter. Once in state-spaceform, thefilter design functionperforms any required frequency transformation, that is, it transforms theinitial lowpass design into a bandpass, highpass, or bandstop filter, or alowpass filter with the desired cutoff frequency. See the descriptions of the

Transfer

function

State-

space

Zero-pole-

gain

Partial

fraction

Lattice

filter

Second-order

sections

Convolution

matrix

Transfer

function

t f 2ss t f 2zp

roots

r esi duez

r esi due

t f 2l at c convmt x

State-space ss2t f ss2zp ss2sos

Zero-pole-gain

zp2t f

pol y

zp2ss zp2sos

Partial

fraction

r esi duez

r esi due

Lattice filter l at c2t f

SOS sos2t f sos2ss sos2zp

Convolution

matrix

1 Signal Processing Basics

individual filter design functions in Chapter 7, “Function Reference,” for moredetails.

Page 76: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-44

Note I n the Signal P rocessing Toolbox, all second-order sectiontransformations apply only to digital filters.

Discrete Fourier Transform

Discrete Fourier Transform

The discrete Fourier transform, or DF T, is the primary tool of digital signal

Page 77: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-45

The discrete Fourier transform, or DF T, is the primary tool of digital signalprocessing. The foundation of theSignal Processing Toolbox is thefast Fouriertransform (FF T), a method for computing the DFT with reduced executiontime. Many of the toolbox functions (including z-domain frequency response,spectrum and cepstrum analysis, and some filter design and implementationfunctions) incorporate the FFT.

MATL AB provides the functions f f t and i f f t to computethe discreteFourier

transform and its inverse, respectively. For the input sequence x and itstransformed version X (the discrete-time F ourier transform at equally spacedfrequencies around the unit circle), the two functions implement therelationships

I n these equations, the series subscripts begin with 1 instead of 0 because of MAT L AB’s vector indexing scheme, and

Note MATL AB uses a negative j for the f f t function. This is an engineeringconvention; physics and pure mathematics typically use a positive j.

f f t, with a single input argument

x, computes the DF T of the input vector ormatrix. I f x is a vector, f f t computes theDFT of thevector; if x is a rectangular

array, f f t computes the DF T of each array column.

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

n 0=

N 1–

å=

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

kn–

k 0=

N 1–

å=

WN e j–

N-------

è ø

=

1 Signal Processing Basics

For example, create a time vector and signal.

t = ( 0: 1/ 99: 1) ; % Ti me vect orx = s i n( 2*pi *15* t ) + s i n( 2*pi *40* t ) ; % Si gnal

Page 78: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-46

( ) ;x = s i n( 2*pi *15* t ) + s i n( 2*pi *40* t ) ; % Si gnal

The DF T of the signal, and the magnitude and phase of the transformedsequence, are then

y = f f t ( x) ; % Comput e DFT of x

m = abs( y) ; p = unwr ap( angl e( y) ) ; % Magni t ude and phase

To plot the magnitude and phase, type the following commands.

f = ( 0: l engt h( y)- 1) *99/ l engt h( y) ; % Frequency vect or

pl ot ( f , m) ; t i t l e( ' Magni tude' ) ;

set ( gca, ' XTi ck' , [ 15 40 60 85] ) ;

f i gure; pl ot ( f , p*180/ pi ) ; t i t l e( ' Phase' ) ;

set ( gca, ' XTi ck' , [ 15 40 60 85] ) ;

A second argument to f f t specifies a number of points n for the transform,representing DF T length.

y = f f t ( x, n) ;

I n this case, f f t pads the input sequence with zeros if it is shorter than n, or

truncates the sequence if it is longer than n. I f n is not specified, it defaults tothe length of the input sequence. Execution time for f f t depends on thelength, n, of the DFT it performs; see the f f t reference page in the MATL ABdocumentation for details about the algorithm.

15 40 60 850

5

10

15

20

25

30

35

40

45

50Magnitude

15 40 60 85−1200

−1000

−800

−600

−400

−200

0Phase

Discrete Fourier Transform

The inverse discrete Fourier transform function i f f t also accepts an inputsequence and, optionally, the number of desired points for the transform. Try

the example below; the ori ginal sequencex and the reconstructed sequence are

Page 79: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-47

p g q qidentical (within rounding error).

t = ( 0: 1/ 255: 1) ;

x = si n( 2*pi *120*t ) ;

y = r eal ( i f f t ( f f t ( x) ) ) ;

This toolbox also includes functions for the two-dimensional FFT and itsinverse, f f t 2 and i f f t 2. These functionsare useful for two-dimensional signal

or image processing; see the descriptions in Chapter 7, “Function Reference,”for details.

I t is sometimes convenient to rearrange the output of the f f t or f f t 2 functionsothe zero frequency component is at thecenter of thesequence. The MATL ABfunction f f t shi f t moves the zero frequency component to the center of a vectoror matrix.

1 Signal Processing Basics

Selected Bibliography

Algorithm development for the Signal Processing Toolbox has drawn heavily

Page 80: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

1-48

upon thereferences li sted below. All are recommended to the interested readerwho needs to know more about signal processing than is covered in thismanual.

[1] Crochiere, R.E., and L .R. Rabiner. Multi-RateSignal Processing.Englewood Cliffs, NJ : Prentice Hall, 1983. Pgs. 88-91.

[2]IEEE. Pr ograms for Digital Signal Pr ocessing. I EE E Press. New Y ork: J ohn

Wiley & Sons, 1979.

[3] J ackson, L.B. Digital Fil ters and Signal Processing. Third Ed. Boston:K luwer Academic Publi shers, 1989.

[4] K ay, S.M. Modern Spectral Estimation. Englewood Cliffs,NJ : PrenticeH all,1988.

[5] Oppenheim, A.V., and R.W. Schafer. Discrete-TimeSi gnal Processing.

Englewood Cliffs, NJ : Prentice Hall, 1989.[6] Parks, T.W., and C.S. Burrus. Digital Filter Design. New York: J ohn Wiley& Sons, 1987.

[7] Pratt,W.K . Digital I mage Processing. New Y ork: J ohn Wiley & Sons, 1991.

[8] Percival, D.B., and A.T. Walden. Spectral Analysis for PhysicalApplications: Multitaper and Conventional UnivariateTechniques. Cambridge:Cambridge University Press, 1993.

[9] Proakis, J .G., and D.G. Manolakis. Digital Signal Processing: Pri nciples,Algori thms, and Applications. Upper Saddle River, NJ : Prentice Hall, 1996.

[10] Rabiner, L.R., and B. Gold. Theory and Appli cation of Digital SignalProcessing. Englewood Cliffs, NJ : Prentice Hall, 1975.

[11] Welch, P.D. “The Use of Fast Fourier Transform for the Estimation of Power Spectra: A Method Based on Ti me Averaging Over Short, Modified

Periodograms.” I EE E Trans. Audio E lectroacoust. Vol. AU-15 (J une 1967).Pgs. 70-73.

2

Filter Design

Page 81: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

Filter Design

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

IIR Filter Design . . . . . . . . . . . . . . . . . . 2-4

Classical II R Filter Design Using Analog Prototyping . . . . 2-6Comparison of Classical II R Filter Types . . . . . . . . . 2-8

FIR Filter Design . . . . . . . . . . . . . . . . . . 2-16L inear Phase F ilters . . . . . . . . . . . . . . . . . 2-17Windowing M ethod . . . . . . . . . . . . . . . . . . 2-18Multiband FI R Filter Design with Transition Bands . . . . 2-22Constrained L east Squares FI R Filter Design . . . . . . . 2-27

Arbitrary-Response Filter Design . . . . . . . . . . . . 2-31

Special Topics in IIR Filter Design . . . . . . . . . . 2-37Analog P rototype D esi gn . . . . . . . . . . . . . . . 2-38Frequency Transformation . . . . . . . . . . . . . . . 2-38F ilter Discretization . . . . . . . . . . . . . . . . . 2-41

Selected Bibliography . . . . . . . . . . . . . . . 2-45

2 Filter Design

Overview

The Signal Processing Toolbox provides functions that support a range of filterdesign methodologies The following sections explain how to apply the filter

Page 82: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

2-2

design methodologies. The following sections explain how to apply the filterdesign tools to I nfinite I mpulseResponse (II R) and F ini teI mpulseR esponse

(FI R) filter design problems:

• “Filter Requirements and Specification”

• “IIR Filter Design”

• “FIR Filter Design”

• “Special Topics in I I R Filter Design”

• “Selected Bi bliography”

Filter Requirements and Specification

Filter Requirements and Specification

The goal of filter design is to perform frequency dependent alteration of a datasequence A possible requirement might be to remove noise above 30 Hz from

Page 83: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

2-3

sequence. A possible requirement might be to remove noise above 30 Hz froma data sequencesampled at 100 Hz. A more rigorousspecification might call fora specific amount of passband ripple, stopband attenuation, or transitionwidth. A very precise specification could ask to achieve the performance goalswith the minimum filter order, or it could call for an arbitrary magnitudeshape, or i t might require an FI R fi lter.

Filter design methods differ primarily in how performance is specified. F or“loosely specified” requirements, as in the first case above, a Butterworth II Rfilter is often sufficient. To design a fifth-order 30 Hz lowpass Butterworthfilter and apply it to the data in vector x,

[ b, a] = but t er ( 5, 30/ 50) ;

y = f i l ter ( b, a, x) ;

The second input argument to but t er specifies the cutoff frequency,

normalized to half the sampling frequency (the Nyquist frequency).

Frequency Normalization in the Signal Processing Toolbox All of thefilter design functions operate with normalized frequencies, so they do notrequire the system sampling rate as an extra input argument. This toolboxuses the convention that unit frequency is the Nyquist frequency, defined ashalf the sampling frequency. The normali zed frequency, therefore, is always inthe interval 0 ≤ f ≤ 1. For a system with a 1000 Hz sampling frequency, 300 Hzis 300/500 =0.6. To convert normalized frequency to angular frequencyaround the unit circle, multiply by π. To convert normalized frequency back tohertz, multiply by half the sample frequency.

More rigorous filter requirements traditionally includepassband ripple (Rp, indecibels), stopband attenuation (Rs, in decibels), and transition width (Ws- Wp,in hertz).

2 Filter Design

1

Page 84: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

2-4

You can design Butterworth, Chebyshev type I , Chebyshev typeI I , and ellipticfilters that meet this type of performance specification. The toolbox orderselection functions estimate the minimum fil ter order that meets a given set of requirements.

To meet specifications with more rigid constraints like linear phase orarbitrary filter shape, use the FI R and direct II R filter design routines.

10-1

100

1010

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 Design

The primary advantage of I I R filters over FI R filters is that they typically meeta given set of specifications with a much lower filter order than a corresponding

Page 85: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

2-5

a g e se o spec ca o s a uc o e e o de a a co espo d gFI R filter. Although II R filters have nonlinear phase, data processing withinMATL AB is commonly performed “off-line,”that is, the entire data sequence isavailable prior to filtering. This allows for a noncausal, zero-phase filteringapproach (via the f i l t f i l t function), which eliminates the nonlinear phasedistortion of an IIR filter.

The classical I I R filters, Butterworth, Chebyshev types I and I I , elliptic, andBessel, all approximate the ideal “brick wall” filter in different ways. Thistoolbox provides functions tocreateall thesetypes of classical I I R filters in boththe analog and digital domains (except Bessel, for which only the analog caseis supported), and in lowpass, highpass, bandpass, and bandstopconfigurations. For most filter types, you can also find the lowest filter orderthat fits a given filter specification in terms of passband and stopbandattenuation, and transition width(s).

The direct filter design function yul ewal k finds a filter with magnituderesponse approximating a desired function. This is one way to create amultiband bandpass filter.

You can also use theparametric modeling or system identification functions todesign II R filters. These functions are discussed in “Parametric Modeli ng” onpage 4-11.

The generalized Butterworth design function maxf l at is discussed in the

section “Generalized Butterworth Fil ter Design” on page 2-14. The following table summarizes the various filter methods in the toolbox andli sts the functions available to implement these methods.

2 Filter Design

Method Description Functions

A l U i th l d f C l t d i f ti

Page 86: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

2-6

AnalogPrototyping

Using thepoles and zeros of a classical lowpassprototype fil ter in thecontinuous (Laplace)domain, obtain a digitalfilter through frequency

transformation and filterdiscretization.

Complete design functions:

bessel f , but t er , cheby1, cheby2, el l i p

Order estimation functions:

but t or d, cheb1or d, cheb2ord, el l i por d

L owpass analog prototype functions:

bessel ap, but t ap, cheb1ap, cheb2ap,el l i pap

Frequency transformation functions:

l p2bp, l p2bs, l p2hp, l p2l p

Filter discretization functions:

bi l i near , i mpi nvar

Direct Design Design digital filter directlyin the discrete time-domainby approximating apiecewise linear magnitude

response.

yul ewal k

GeneralizedButterworthDesign

Design lowpassButterworth filters withmore zeros than poles.

maxf l at

ParametricModeling

Fi nd a digital filter thatapproximates a prescribed

time or frequency domain

response. (See the SystemI dentification Toolbox for anextensive collection of parametric modeli ng tools.)

Time-domain modeling functions:

l pc, prony, st mcb

Frequency-domain modeling functions:

i nvf r eqs, i nvf r eqz

IIR Filter Design

Classical IIR Filter Design Using Analog Prototyping The principal I I R digital filter design technique this toolbox provides is basedon the conversion of classical lowpass analogfilters to their digital equivalents.The following sections describe how to design filters and summarize the

Page 87: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

2-7

The following sections describe how to design filters and summarize thecharacteristics of the supported filter types. See “Special Topics in I I R F ilterDesign” on page 2-38 for detailed steps on the filter design process.

Complete Classical IIR Filter Design

You can easily create a filter of any order with a lowpass, highpass, bandpass,

or bandstop configuration using the filter design functions.

By default, each of these functions returns a lowpass filter; you need onlyspecify the desired cutoff frequency Wn in normalized frequency (Nyquist

frequency =1 Hz). For a highpass filter, append the string ' hi gh' to thefunction’s parameter list. For a bandpass or bandstop filter, specify Wn as atwo-element vector containing the passband edge frequencies, appending thestring ' stop' for the bandstop configuration.

Filter Type Design Function

Bessel (analog only) [ b, a] = bessel f ( n, Wn, opt i ons)

[ z , p, k] = bessel f ( n, Wn, opt i ons)

[ A, B, C, D] = bessel f ( n, Wn, opt i ons)

Butterworth [ b, a] = butt er( n, Wn, opt i ons)

[ z , p, k] = but t er ( n, Wn, opt i ons)

[ A, B, C, D] = but t er ( n, Wn, opt i ons)

Chebyshev type I [ b, a] = cheby1( n, Rp, Wn, opt i ons)

[ z, p, k] = cheby1( n, Rp, Wn, opt i ons)

[ A, B, C, D] = cheby1( n, Rp, Wn, opt i ons)

Chebyshev type I I [ b, a] = cheby2( n, Rs, Wn, opt i ons)

[ z, p, k] = cheby2( n, Rs, Wn, opt i ons)

[ A, B, C, D] = cheby2( n, Rs, Wn, opt i ons)

Elliptic [ b, a] = el l i p(n, Rp, Rs , Wn, opt i ons)

[ z , p, k] = el l i p(n, Rp, Rs , Wn, opt i ons)

[ A, B, C, D] = el l i p( n, Rp, Rs, Wn, opt i ons)

2 Filter Design

Here are some example digital filters.

[ b, a] = but t er ( 5, 0. 4) ; % Lowpass But t er wor t h

[ b, a] = cheby1( 4, 1, [ 0. 4 0. 7] ) ; % Bandpass Chebyshev type I

[ b, a] = cheby2( 6, 60, 0. 8, ' hi gh' ) ; % Hi ghpass Chebyshev type I I

Page 88: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

2-8

[ , ] y ( , , , g ) ; g p y yp

[ b, a] = el l i p( 3, 1, 60, [ 0. 4 0. 7] , ' st op' ) ; % Bandst op el l i pt i c

To design an analog filter, perhaps for simulation, use a trailing ' s' andspecify cutoff frequencies in rad/s.

[ b, a] = but t er ( 5, . 4, ' s ' ) ; % Anal og But t erwort h f i l t er

All filter design functions return a filter in the transfer function,zero-pole-gain, or state-space linear system model representation, dependingon how many output arguments are present.

Note All classical I I R lowpass filters are ill-conditioned for extremely lowcut-off frequencies. Therefore, instead of designing a lowpass I I R filter with avery narrow passband, it can be better to design a wider passband and

decimate the input signal.

Designing IIR Filters to Frequency Domain Specifications

This toolbox provides order selection functions that calculate the minimumfilter order that meets a given set of requirements.

These are useful in conjunction with the filter design functions. Suppose youwant a bandpass filter with a passband from 1000 to 2000 Hz, stopbandsstarting500 Hz away on either side, a 10 kHz samplingfrequency, at most 1 dB

Filter Type Order Estimation Function

Butterworth [ n, Wn] = but t or d( Wp, Ws, Rp, Rs)

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

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

Elliptic [ n, Wn] = el l i pord( Wp, Ws, Rp, Rs)

IIR Filter Design

of passband ripple, and at least 60 dB of stopband attenuation. You can meetthesespecifications by using the but t er function as follows.

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

Page 89: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

2-9

n =

12

Wn =

0. 1951 0. 4080

[ b, a] = but t er ( n, Wn) ;

An elliptic filter that meets the same requirements is given by

[ n, Wn] = el l i pord( [ 1000 2000] / 5000, [ 500 2500] / 5000, 1, 60)

n =

5

Wn =

0. 2000 0. 4000

[ b, a] = el l i p( n, 1, 60, Wn) ;

Thesefunctions alsowork with theother standard band configurations, aswellas for analog filters; see Chapter 7, “Function Reference,” for details.

Comparison of Classical IIR Filter Types The toolbox provides fivedifferent types of classical I I R filters, each optimal insome way. This section shows the basic analog prototype form for each and

summarizes major characteristics.

Butterworth Filter

The Butterworth filter provides the best Taylor Series approximation to theideal lowpass filter response at analog frequencies and ; for anyorder N, the magnitude squared response has 2N-1 zero derivatives at theselocations(maximallyflat at and ). Responseismonotonicoverall,decreasing smoothly from to . at .

Ω 0= Ω ∞=

Ω 0= Ω ∞=

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

2 Filter Design

0.8

1

Page 90: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

2-10

Chebyshev Type I Filter

The Chebyshev type I filter minimizes the absolute difference between theideal and actual frequency responseover the entire passband by incorporatingan equal ripple of Rp dB in thepassband. Stopband response is maximally flat. The transition from passband to stopband is more rapid than for theButterworth filter. at .

10-1

100

101

0

0.2

0.4

0.6

Frequency(rad/sec)

M a g n i t u d e

H jΩ( ) 10R p 20 ⁄ –

= Ω 1=

10-1

100

101

0

0.2

0.4

0.6

0.8

1

Frequency(rad/sec)

a g n i t u d e

IIR Filter Design

Chebyshev Type II Filter

The Chebyshev type I I filter minimizes the absolute difference between the

ideal and actual frequency response over the entire stopband by incorporatingan equal ripple of Rs dB in the stopband. Passband response is maximally flat.

Page 91: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

2-11

The stopband does not approach zero as quickly as the type I filter (and doesnot approach zero at all for even-valued filter order n). The absence of ripple inthe passband, however, is often an important advantage.at .

Elliptic Filter

Elliptic filters are equiripple in both the passband and stopband. Theygenerally meet filter requirements with thelowest order of any supportedfiltertype. Given a filter order n, passband ripple Rp in decibels, and stopband rippleRsindecibels, ellipticfiltersminimizetransition width. at

.

H jΩ( ) 10R s 20 ⁄ –

=

Ω 1=

10-1

100

101

0

0.2

0.4

0.6

0.8

1

Frequency(rad/sec)

M

a g n i t u d e

H jΩ( ) 10R p 20 ⁄ –

=

Ω 1=

2 Filter Design

0.8

1

Page 92: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

2-12

Bessel Filter

Analog Bessel lowpass filters have maximally flat group delay at zerofrequency and retain nearly constant group delay across the entire passband.Filtered signals therefore maintain their waveshapes in the passbandfrequency range. Frequency mapped and digital Bessel fil ters, however, donothave this maximally flat property; this toolbox supports only the analog casefor the complete Bessel filter design function.

Bessel filters generally require a higher filter order than other fil ters for

satisfactorystopband attenuation. at and decreases asfilter order n increases.

10-1

100

101

0

0.2

0.4

0.6

Frequency(rad/sec)

M a g n i t u d e

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

IIR Filter Design

0.8

1

Page 93: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

2-13

Note The lowpass filters shown above were created with the analogprototype functions bessel ap, but t ap, cheb1ap, cheb2ap, and el l i pap. Thesefunctions find the zeros, poles, and gain of an order n analog filter of theappropriate type with cutoff frequency of 1 rad/s. The complete filter designfunctions (bessel f , but t er, cheby1, cheby2, and el l i p) call the prototypingfunctions as a first step in thedesign process. See “Special Topics in I I R F ilterDesign” on page 2-37 for details.

To create similar plots, use n =5 and, as needed, Rp =0. 5 and Rs =20. Forexample, to create the elliptic filter plot:

[ z , p, k] = el l i pap(5, 0. 5, 20) ;

w = l ogspace( - 1, 1, 1000) ;

h = f reqs(k*pol y( z ) , pol y( p) , w) ;

semi l ogx( w, abs( h) ) , gr i d

10-1

100

101

0

0.2

0.4

0.6

Frequency(rad/sec)

M a g n i t u d e

2 Filter Design

Direct IIR Filter Design

This toolbox uses theterm direct methods to describetechniques for I I R design

that find a filter based on specifications in the discrete domain. Unlike theanalog prototyping method, direct design methods are not constrained to thestandard lowpass, highpass, bandpass, or bandstop configurations. Rather,

Page 94: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

2-14

p g p p p gthese functions design filters with an arbitrary, perhaps multiband, frequencyresponse. This section discusses the yul ewal k function, which is intendedspecifically for filter design; “Parametric Modeling” on page 4-11 discussesother methods that may also be considered direct, such as Prony’s method,L inear Prediction, the Steiglitz-McBride method, and inverse frequency

design.

The yul ewal k function designs recursiveI I R digital filters by fitting a specifiedfrequency response. yul ewal k’s name reflects its method for findingthe filter’sdenominator coefficients: it finds the inverse FFT of the ideal desired powerspectrum and solves the “modified Yule-Walker equations”using the resultingautocorrelation function samples. The statement

[ b, a] = yul ewal k(n, f , m)

returns row vectors b and a containing the n+1 numerator and denominatorcoefficients of the order n I I R fi lter whose frequency-magnitudecharacteristicsapproximate those given in vectors f and m. f is a vector of frequency pointsranging from 0 to 1, where 1 represents the Nyquist frequency. mis a vectorcontaining the desired magnitude response at the points in f . f and mcandescribe any piecewise linear shape magnitude response, including amultiband response. The FI R counterpart of this function is f i r 2, which alsodesigns a filter based on an arbitrary piecewiselinear magnituderesponse. See“FIR Filter Design” on page 2-16 for details.

Notethat yul ewal k does not accept phase information, and no statements aremade about the optimality of the resulting filter.

Design a multiband filter with yul ewal k, and plot the desired and actualfrequency response.

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

f = [ 0 0. 1 0. 2 0. 3 0. 4 0. 5 0. 6 0. 7 0. 8 1] ;[ b, a] = yul ewal k(10, f , m) ;

[ h, w] = f r eqz( b, a, 128) ;

pl ot ( f , m, w/ pi , abs( h) )

IIR Filter Design

1

1.2

Page 95: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

2-15

Generalized Butterworth Filter Design

The toolbox function maxf l at enables you to design generalized Butterworthfilters, that is, Butterworth filters with differing numbers of zeros and poles. This is desirable in some implementations where poles are more expensivecomputationally than zeros. maxf l at is just like the but t er function, exceptthat it you can specify two orders (one for the numerator and one for thedenominator) instead of just one. Thesefilters are maximally flat. This meansthat the resulting fil ter is optimal for any numerator and denominator orders,with themaximumnumber of derivatives at 0 and theN yquist frequency ω =πboth set to 0.

F or example, when thetwoorders arethesame, maxf l at is thesameas but t er .

[ b, a] = maxf l at ( 3, 3, 0. 25)

b =

0. 0317 0. 0951 0. 0951 0. 0317

a =

1. 0000 - 1. 4590 0. 9104 - 0. 1978

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

0.2

0.4

0.6

0.8

2 Filter Design

[ b, a] = but t er ( 3, 0. 25)

b =

0. 0317 0. 0951 0. 0951 0. 0317

a =

Page 96: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

2-16

1. 0000 - 1. 4590 0. 9104 - 0. 1978

However, maxf l at is more versatile becauseit allows you todesign a filter withmore zeros than poles.

[ b, a] = maxf l at ( 3, 1, 0. 25)

b =

0. 0950 0. 2849 0. 2849 0. 0950

a =

1. 0000 - 0. 2402

The third input to maxflat is the half-power frequency, a frequency between0 and 1 with a desired magnitude response of .

You can also design linear phasefilters that have the maximally flat propertyusing the ' sym' option.

maxf l at ( 4, ' sym' , 0. 3)

ans =

0. 0331 0. 2500 0. 4337 0. 2500 0. 0331

For complete details of the maxf l at algorithm, see Selesnick and Burrus [2].

1 2 ⁄

FIR Filter Design

FIR Filter Design

Digital filters with finite-duration impulse response (all-zero, or FI R filters)have both advantages and disadvantages compared to infinite-durationimpulse response (I I R) filters.

Page 97: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

2-17

FI R filters have the following primary advantages:

• They can haveexactly linear phase.

• They are always stable.

The design methods are generally linear.• They can be realized efficiently in hardware.

• The filter startup transients have finite duration.

The primary disadvantage of FI R filters is that they often require a muchhigher filter order than I I R filters to achieve a given level of performance.Correspondingly, the delay of these filters is often much greater than for anequal performance I I R filter.

Method Description Functions

Windowing Apply window totruncatedinverse Fourier transform of desired “brick wall” filter

f i r 1, f i r 2,kai ser or d

Multiband with

TransitionBands

Equiripple or least squares

approach over sub-bands of thefrequency range

f i r l s, r emez ,

r emezor d

ConstrainedL east Squares

Mi nimize squared integralerror over entire frequencyrange subject to maximumerror constraints

f i r c l s, f i r c l s 1

Arbitrary

Response

Arbitrary responses, including

nonlinear phase and complexfilters

cr emez

Raised Cosine L owpass response withsmooth, sinusoidal transition

f i r r c os

2 Filter Design

Linear Phase FiltersExcept for cr emez , all of the FI R filter design functions design l inear phase

filters only. The filter coefficients, or “taps,”of such filters obey either an evenor odd symmetry relation. Depending on this symmetry, and on whether theorder n of the filter is even or odd, a linear phase filter (stored in length n+1

t b) h t i i h t t i ti it f

Page 98: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

2-18

vector b) has certain inherent restrictions on its frequency response.

The phase delay and group delay of linear phase FI R filters are equal and

constant over the frequency band. For an order n linear phaseFI R filter, thegroup delay is n/2, and the filtered signal is simply delayed by n/2 time steps(and the magnitudeof its Fourier transform is scaled by thefilter’s magnituderesponse). This property preserves the waveshapeof signals in the passband;that is, there is no phase distortion.

The functions f i r 1, f i r 2, f i r l s, r emez , f i r c l s, f i r c l s 1, and f i r r c os alldesign typeI and I I linear phaseF I R filters by default. Both f i r l s and r emez

design typeI I I and I V linear phaseFI R filters given a ' hi l ber t ' or' di f f erent i ator ' flag. cr emez can design any type of linear phase filter, andnonlinear phase filters as well.

Note Becausethe frequency response of a type I I fi lter is zero at the Nyquistfrequency (“high” frequency), f i r 1 does not design type I I highpass andbandstop filters. For odd-valued n in these cases, f i r 1 adds 1 to the order andreturns a type I filter.

Linear Phase

Filter Type

Filter

Order Symmetry of Coefficients

Response H(f),

f = 0

Response H(f),

f = 1 (Nyquist)

Type I Even even: No restriction No restriction

Type I I Odd No restriction H(1) = 0

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

Type I V Odd H(0) = 0 No restriction

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 theideal, or “brick wall,”digital lowpass filter with a cutoff frequency

of ω0 rad/s. This filter has magnitude 1 at all frequencies with magnitude lessthan ω0, and magnitude0 at frequencies with magnitude between ω0 and π. I t simpulse response sequence h(n) is

Page 99: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

2-19

This filter is not implementable since its impulse response is infinite and

noncausal. To create a finite-duration impulse response, truncate it byapplying a window. By retaining thecentral section of impulseresponse in thistruncation, you obtain a linear phaseF I R filter. For example, a length 51 filterwith a lowpass cutoff frequency ω0 of rad/s i s

b = 0. 4*si nc( 0. 4*( - 25: 25) ) ;

The window applied here is a simple rectangular or “boxcar” window. ByParseval’s theorem, this is thelength 51 filter that best approximates theideal

lowpass filter, in the integrated least squares sense. The following commandsdisplay the filter’s frequency response.

[ H, w] = f r eqz( b, 1, 512, 2) ;

s. xuni t s = ' r ad/ sampl e' ;

s. yuni t s = ' squar ed' ;

s. pl ot = ' mag' ; % Pl ot magni t ude onl y.

f r eqzpl ot ( H, w, s)

t i t l e( ' Tr uncat ed Si nc Lowpass FI R Fi l t er ' ) ;

h n( )1

2π------ H ω( )e j ωn ωd

π–

π

ò 1

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

ω0–

ω0

ò ω0

π-------sinc

ω0

π-------n( )= = =

0.4π

2 Filter Design

1

1.2

1.4

d

Truncated Sinc Lowpass FIR Filter

Page 100: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 100/870

2-20

Notethe ringing and ripples in the response, especially near the band edge. This “Gibbs effect” does not vanish as the filter length increases, but a

nonrectangular window reduces its magnitude. Multiplication by a window inthe time domain causes a convolution or smoothing in the frequency domain.Apply a length 51 Hamming window to the filter.

b = 0. 4*si nc( 0. 4*( - 25: 25) ) ;

b = b. *hammi ng( 51) ' ;

[ H, w] = f r eqz( b, 1, 512, 2) ;

s. xuni t s = ' r ad/ sampl e' ;

s. yuni t s = ' squar ed' ;

s. pl ot = ' mag' ;

f r eqzpl ot ( H, w, s)

t i t l e( ' Hammi ng- Wi ndowed Tr uncat ed Si nc LP FI R Fi l t er ' ) ;

0 0.05 0.1 0.15 0.2 0.25 0.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

FIR Filter Design

1

1.2

1.4

d

Hamming−Windowed Truncated Sinc LP FIR Filter

Page 101: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 101/870

2-21

As you can see, this greatly reduces the ringing. This improvement is at theexpense of transition width (the windowed version takes longer to ramp from

passband to stopband) and optimali ty (the windowed version does notminimize the integrated squared error).

The functions f i r 1 and f i r 2 are based on this windowing process. Given afilter order and description of an ideal desired fil ter, these functions return awindowed inverse F ourier transform of that ideal filter. Both use a Hammingwindow by default, but they accept any window function. See “Overview” onpage 4-2 for an overview of windows and their properties.

Standard Band FIR Filter Design: fir1

f i r 1 implements the classical method of windowed linear phase FI R digitalfilter design. I t resembles theI I R filter design functions in that it is formulatedto design filters in standard band configurations: lowpass, bandpass, highpass,and bandstop.

The statements

n = 50;Wn = 0. 4;

b = f i r 1( 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

create row vector b containing the coefficients of the order n

Hamming-windowed filter. This is a lowpass, linear phaseFI R filter with cutoff

frequency Wn. Wn is a number between 0 and 1, where 1 corresponds to theNyquist frequency, half the sampling frequency. (Unlike other methods, hereWn corresponds to the 6 dB point.) F or a highpass filter, simply append thestring ' hi gh' to the function’s parameter list. For a bandpass or bandstopfilt if W t l t t t i i th b d d

Page 102: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 102/870

2-22

filter, specify Wn as a two-element vector containing the passband edgefrequencies; append the string ' stop' for the bandstop configuration.

b = f i r 1( n, Wn, wi ndow) uses thewindow specified in column vector wi ndowforthe design. The vector wi ndowmust ben+1 elements long. I f you donot specify

a window, f i r 1 applies a Hamming window.

Kaiser Window Order Estimation. The kai ser or d function estimates the filterorder, cutoff frequency, and K aiser window beta parameter needed to meet agiven set of specifications. Given a vector of frequency band edges and acorresponding vector of magnitudes, as well as maximum allowable ripple,kai ser or d returns appropriate input parameters for the f i r 1 function.

Multiband FIR Filter Design: fir2 The f i r 2 function also designs windowed FI R fi lters, but with an arbitrarilyshaped piecewise linear frequency response. This is in contrast to f i r 1, whichonly designs filters in standard lowpass, highpass, bandpass, and bandstopconfigurations.

The commands

n = 50;

f = [ 0 . 4 . 5 1] ;m = [ 1 1 0 0] ;

b = f i r 2( n, f , m) ;

return row vector b containing the n+1 coefficients of the order n FIR filterwhose frequency-magnitude characteristics match those given by vectors f

and m. f is a vector of frequency points ranging from 0 to 1, where 1 representsthe Nyquist frequency. mis a vector containing the desired magnituderesponseat the points specified in f . (The I I R counterpart of this function is yul ewal k,which also designs filters based on arbitrary piecewise linear magnituderesponses. See “I I R Filter Design” on page 2-5 for details.)

FIR Filter Design

Multiband FIR Filter Design with Transition Bands The f i r l s and r emez functions providea more general means of specifying the

ideal desired filter than the f i r 1 and f i r 2 functions. These functions designHilbert transformers, differentiators, and other filters with odd symmetriccoefficients (type I I I and type I V linear phase). They also let you includetransition or “don’t care”regions in which the error is not minimized, and

Page 103: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 103/870

2-23

gperform band dependent weighting of the minimization.

The f i r l s function is an extension of the f i r 1 and f i r 2 functions in that itminimizes theintegral of thesquareof theerror between thedesiredfrequencyresponse and the actual frequency response.

The r emez function implements the Parks-McClellan algorithm, which usesthe Remez exchange algori thm and Chebyshev approximation theory to designfilters with optimal fits between the desired and actual frequency responses. The filters are optimal in the sense that they minimize the maximum errorbetween the desired frequency response and the actual frequency response;they are sometimes called minimax filters. Filters designed in this way exhibitan equiripple behavior in their frequency response, and hence are also known

as equiripple filters. The Parks-McClellan FI R filter design algorithm isperhaps the most popular and widely used FI R filter design methodology.

The syntax for f i r l s and r emez is the same; the only difference is theirmini mization schemes. The next example shows how filters designed withf i r l s and r emez reflect these different schemes.

Basic Configurations

The default mode of operation of f i r l s and r emez is to design type I or type I Ilinear phasefil ters, depending on whether the order you desire is even or odd,respectively. A lowpass example with approximate amplitude 1 from 0 to0.4 Hz, and approximate amplitude 0 from 0.5 to 1.0 Hz is

n = 20; % Fi l t er or der

f = [0 0. 4 0. 5 1] ; % Frequency band edges

a = [ 1 1 0 0] ; % Desi r ed ampl i t udes

b = r emez( n, f , a) ;

From 0.4 to 0.5 Hz, r emez performs no error minimization; this is a transitionband or “don’t care” region. A transition band minimizes the error more in thebands that you do careabout, at theexpense of a slower transition rate. I n this

2 Filter Design

way, these types of filters have an inherent trade-off similar to FI R design bywindowing.

To compare least squares to equiri pple filter design, use f i r l s to create asimilar filter. Type

bb = f i r l s (n, f , a) ;

Page 104: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 104/870

2-24

and compare their frequency responses.

[ H, w] = f r eqz( b) ;

[ HH, w] = f r eqz( bb) ;

pl ot ( w/ pi , abs(H) , w/ pi , abs(HH) , ' - - ' ) , gr i d

You can see that the filter designed with r emez exhibits equiripple behavior.Also note that thef i r l s filter has a better responseover most of the passbandand stopband, but at the band edges (f =0. 4 and f =0. 5), the response isfurther away from the ideal than ther emez filter. This shows that the r emez

filter’s maximum error over the passband and stopband is smaller and, in fact,it is the smallest possible for this band edge configuration and 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 bands as lines over short frequency intervals. r emez andf i r l s usethis scheme to represent any piecewise linear desired function with

any transition bands. f i r l s and r emez design lowpass, highpass, bandpass,and bandstop filters; a bandpass example is

f = [ 0 0. 3 0. 4 0. 7 0. 8 1] ; % Band edges i n pai r s

a = [ 0 0 1 1 0 0] ; % Bandpass f i l t er ampl i t ude

Page 105: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 105/870

2-25

Technically, these f and a vectors define five bands:

• Two stopbands, from 0.0 to 0.3 and from 0.8 to 1.0

A passband from 0.4 to 0.7• Two transition bands, from 0.3 to 0.4 and from 0.7 to 0.8

Example highpass and bandstop filters are

f = [ 0 0. 7 0. 8 1] ; % Band edges i n pai r s

a = [ 0 0 1 1] ; % Hi ghpass f i l t er ampl i t ude

f = [ 0 0. 3 0. 4 0. 5 0. 8 1] ; % Band edges i n pai r s

a = [ 1 1 0 0 1 1] ; % Bandst op f i l t er ampl i t ude

An example multiband bandpass filter is

f = [ 0 0. 1 0. 15 0. 25 0. 3 0. 4 0. 45 0. 55 0. 6 0. 7 0. 75 0. 85 0. 9 1] ;

a = [ 1 1 0 0 1 1 0 0 1 1 0 0 1 1] ;

Another possibility is a filter that has as a transition region theli neconnectingthe passband with the stopband; this can help control “runaway” magnituderesponse in wide transition regions.

f = [ 0 0. 4 0. 42 0. 48 0. 5 1] ;

a = [ 1 1 0. 8 0. 2 0 0] ; %Passband, l i near t r ansi t i on, st opband

2 Filter Design

The Weight Vector

Both f i r l s and r emez allow you to place more or less emphasis on minimizing

the error in certain frequency bands relative to others. To do this, specify aweight vector following the frequency and amplitude vectors. An examplelowpass equiripple filter with 10 times less ripple in the stopband than thepassband is

Page 106: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 106/870

2-26

n = 20; % Fi l t er or der

f = [ 0 0. 4 0. 5 1] ; % Fr equency band edges

a = [ 1 1 0 0] ; % Desi r ed ampl i t udes

w = [ 1 10] ; % Wei ght vect or

b = r emez(n, f , a, w) ;

A legal weight vector is always half thelength of thef and a vectors; there mustbe exactly one weight per band.

Anti-Symmetric Filters / Hilbert Transformers

When called with a traili ng ' h' or ' Hi l ber t ' option, r emez and f i r l s designFI R filters with odd symmetry, that is, typeI I I (for even order) or type I V (for

odd order) linear phase filters. An ideal Hilbert transformer has thisanti-symmetry property and an amplitude of 1 across the entire frequencyrange. Try the following approximateHilbert transformers.

b = r emez( 21, [ 0. 05 1] , [ 1 1] , ' h' ) ; % Hi ghpass Hi l ber t

bb = r emez( 20, [ 0. 05 0. 95] , [ 1 1] , ' h' ) ; % Bandpass Hi l ber t

0 0.25 0.5 0.75 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 the delayed Hilbert transform of a signal x by passing it throughthese filters.

f s = 1000; % Sampl i ng f r equencyt = ( 0: 1/ f s: 2) ' ; % Two second t i me vect or

x = si n(2*pi *300*t ) ; % 300 Hz si ne wave exampl e si gnal

xh = f i l t er( bb, 1, x) ; % Hi l bert t ransf orm of x

Page 107: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 107/870

2-27

The analytic signal corresponding to x is the complex signal that has x as itsreal part and the Hilbert transform of x as its imaginary part. For this FI Rmethod (an alternative to the hi l bert function), you must delay x by half the

filter order to create the analytic signal.xd = [ zer os( 10, 1) ; x(1: l engt h( x)- 10) ] ; % Del ay 10 sampl es

xa = xd + j *xh; % Anal yt i c si gnal

This method does not work directly for filters of odd order, which require anoninteger delay. I n this case, the hi l bert function, described in “Specialized Transforms” on page 4-35, estimates theanalytic signal. Alternatively, use ther esampl e function to delay the signal by a noninteger number of samples.

Differentiators

Differentiation of a signal in thetimedomain is equivalent to multiplication of the signal’s Fourier transform by an imaginary ramp function. That i s, todifferentiate a signal, pass it through a filter that has a response H(ω) = jω.Approximate the ideal differentiator (with a delay) using r emez or f i r l s witha ' d' or ' di f f erent i ator ' option.

b = r emez( 21, [ 0 1] , [ 0 pi *f s] , ' d' ) ;

To obtain thecorrect derivative, scaleby pi * f s rad/s, where f s is thesamplingfrequency in hertz. For a type I I I filter, the differentiation band should stopshort of the Nyquist frequency, and the amplitude vector must reflect thatchange to ensure the correct slope.

bb = r emez( 20, [ 0 0. 9] , [ 0 0. 9*pi *f s] , ' d' ) ;

Inthe ' d' mode, r emez weights theerror by 1/ω in nonzero amplitudebands to

minimize the maximum relative error. f i r l s weights the error by (1/ω)2 innonzero amplitude bands in the ' d' mode.

2 Filter Design

The following plots show the magnituderesponse for the differentiators above.

3000

3500

Differentiator, odd order

3000

3500

Differentiator, even order

Page 108: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 108/870

2-28

Constrained Least Squares FIR Filter Design The Constrained L east Squares (CLS) F I R filter design functions implement atechnique that enables you to design FI R filters without explicitly defining thetransition bands for the magnitude response. The ability to omit thespecification of transition bands is useful in several situations. For example, itmay not be clear where a rigidly defined transition band should appear if noiseandsignal information appear together in the same frequency band. Similarly,it may make sense to omit the specification of transition bands if they appearonly to control the results of Gibbs phenomena that appear in the filter’sresponse. See Selesnick, L ang, and Burrus [2] for discussion of this method.

I nstead of defining passbands, stopbands, and transition regions, the CL Smethod accepts a cutoff frequency (for the highpass, lowpass, bandpass, orbandstopcases), or passband and stopband edges (for multiband cases), for thedesired response. I n this way, the CL S method defines transition regionsimplicitly, rather than explicitly.

The key feature of the CL S method is that it enables you to define upper andlower thresholds that contain themaximum allowable ripple in themagnituderesponse. Given this constraint, the technique applies the least square errorminimization technique over the frequency range of the filter’s response,instead of over specific bands. The error minimization includes any areas 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

discontinuity in the ideal, “brick wall” response. An additional benefit is thatthe technique enables you to specify arbitrarily small peaks resulting from

Gibbs’ phenomena. There are two toolbox functions that i mplement this design technique.

Description Function

Page 109: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 109/870

2-29

For details on the calling syntax for these functions, see their referencedescriptions in Chapter 7, “Function Reference.”

Basic Lowpass and Highpass CLS Filter Design

The most basic of the CL S design functions, f i r c l s 1, uses this technique todesign lowpass and highpass F I R filters. As an example, consider designing afilter with order 61 impulse responseand cutoff frequency of 0.3 (normalized).Further, define the upper and lower bounds that constrain the design processas:

• Maximum passband deviation from 1 (passband ripple) of 0.02.

• Maximum stopband deviation from 0 (stopband ripple) of 0.008.

To approach this design problem using f i r c l s 1, use the following commands.

n = 61;

wo = 0. 3;

dp = 0. 02;

ds = 0. 008;

h = f i rc l s1( n, wo, dp, ds, ' pl ot ' ) ;

Constrained least square multiband FI R filter design f i r c l s

Constrained least square filter design for lowpass and

highpass linear phase filters

f i r c l s 1

0 ds = 0. 0081dp = 0. 02

2 Filter Design

0.6

0.8

1

Page 110: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 110/870

2-30

Multiband CLS Filter Design

f i r c l s uses the same technique to design FI R filters with a desired piecewiseconstant magnitude response. I n this case, you can specify a vector of bandedges and a corresponding vector of band amplitudes. I n addition, you canspecify the maximum amount of ripple for each band.

For example, assume the specifications for a fil ter call for:

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

• From 0.3 to 0.5: amplitude 0.5, upper bound 0.51, lower bound 0.49• From 0.5 to 0.7: amplitude 0, upper bound 0.03, lower bound -0.03

• From 0.7 to 0.9: amplitude 1, upper bound 1.02, lower bound 0.98

• From 0.9 to 1: amplitude 0, upper bound 0.05, lower bound -0.05

Design a CL S filter with i mpulse response order 129 that meets thesespecifications.

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

FIR Filter Design

l o = [ - 0. 005 0. 49 - 0. 03 0. 98 - 0. 05] ;

h = f i r c l s (n, f , a, up, l o, ' pl ot ' ) ;

1

1.2

Page 111: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 111/870

2-31

Weighted CLS Filter Design

Weighted CL S filter design lets you design lowpassor highpassFI R filters withrelative weighting of the error minimization in each band. The f i r c l s 1

function enables you to specify the passband and stopband edges for the leastsquares weighting function, as well as a constant k that specifies the ratio of the stopband to passband weighting.

For example, consider specifications that call for an FI R filter with impulseresponse order of 55 and cutoff frequency of 0.3 (normalized). Also assumemaximumallowablepassband ripple of 0.02 andmaximum allowable stopbandripple of 0.004. I n addition, add weighting requirements:

• Passband edge for the weight function of 0.28 (normalized)

• Stopband edge for the weight function of 0.32

• Weight error minimization 10 times as much in the stopband as 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 this using f i r c l s 1, type

n = 55;

wo = 0. 3;dp = 0. 02;

ds = 0. 004;

wp = 0. 28;

ws = 0. 32;

Page 112: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 112/870

2-32

k = 10;

h = f i r cl s1( n, wo, dp, ds, wp, ws, k, ' pl ot ' ) ;

Arbitrary-Response Filter Design The cr emez filter design function provides a tool for designing F I R filters witharbitrary complex responses. I t differs from theother filter design functions inhow the frequency response of the filter is specified: it accepts the name of afunction which returns thefilter response calculated over a grid of frequencies. This capability makes cr emez a highly versatile and powerful technique forfilter design.

This design technique may be used to produce nonlinear-phase FI R filters,asymmetric frequency-response filters (with complex coefficients), or moresymmetric filters with custom 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 algorithm optimizes the Chebyshev (or minimax) error using anextended Remez-exchange algorithm for an initial estimate. I f this exchangemethod fails to obtain the optimal filter, the algorithm switches to anascent-descent algori thm that takes over to finish the convergence to theoptimal solution.

For details on the syntax for cr emez , see the description in Chapter 7,“Function Reference.”

Page 113: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 113/870

2-33

Multiband Filter Design

Consider a multiband filter with the following special frequency-domain

characteristics.

A linear-phase multiband filter may be designed using the predefinedfrequency-response function mul t i band, as follows.

b = cremez( 38, [ - 1 - 0. 5 - 0. 4 0. 3 0. 4 0. 8] , . . .

' mul t i band' , [ 5 1 2 2 2 1] , [ 1 10 5] ) ;

For thespecific case of a multiband filter, wecan use a shorthand filter designnotation similar to the syntax for r emez .

b = cremez( 38, [ - 1 - 0. 5 - 0. 4 0. 3 0. 4 0. 8] , . . .

[ 5 1 2 2 2 1] , [ 1 10 5] ) ;

As with r emez, a vector of band edges is passed to cr emez. This vector definesthe frequency bands over which optimization is performed; note that there aretwo transition bands, from -0.5 to -0.4 and 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

I n either case, the frequency response is obtained and plotted using linearscale.

[ h, w] = f r eqz( b, 1, 512, ' whol e' ) ;pl ot ( w/ pi - 1, f f t shi f t ( abs(h) ) ) ; gr i d;

xl abel ( ' Nor mal i zed Fr equency' ) ;

yl abel ( ' Magni t ude Response' ) ;

Note that the frequency response has been calculated over the entire

Page 114: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 114/870

2-34

Note that the frequency response has been calculated over the entirenormalized frequency range [-1 +1] by passing the option ' whol e' to f r eqz. I norder to plot thenegative frequency information in a natural way, theresponsehas been “wrapped,” just as FFT data is, using f f t shi f t .

The filter response for this multiband filter is complex, which is expectedbecause of the asymmetry 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

R e a l P a r t

Page 115: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 115/870

2-35

Filter Design with Reduced Delay

Consider thedesign of a 62-tap lowpass filter with a half-Nyquist cutoff. I f wespecify a negative offset value to the l owpass filter design function, the groupdelay offset for thedesign is significantly lessthan that obtained for a standardlinear-phase design. This filter design may be computed as follows.

b = cr emez( 61, [ 0 0. 5 0. 55 1] , ' l owpass' , - 16) ;

The resulting magnitude response is

[ h, w] = f r eqz( b, 1, 512, ' whol e' ) ;

pl ot ( w/ pi - 1, f f t shi f t ( abs(h) ) ) ; gr i d;

xl abel ( ' Nor mal i zed Frequency' ) ;

yl abel ( ' Magni t ude Response' ) ;

0 5 10 15 20 25 30 35 40-0.5

0

0.5

R

0 5 10 15 20 25 30 35 40-0.2

0

0.2

I m a g P a r t

Page 116: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 116/870

FIR Filter Design

I f we compare this nonlinear-phase filter to a linear-phase filter that hasexactly 14.5 samples of group delay, theresultingfilter is of order 2*14.5, or 29.Using b = cremez( 29, [ 0 0. 5 0. 55 1] , ' l owpass' ) , the passband andstopband ripple is much greater for the order 29 filter. These comparisons canassist you in deciding which filter is more appropriatefor a specific application.

Page 117: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 117/870

2-37

2 Filter Design

Special Topics in IIR Filter Design

The classicI I R filter design techniquefinds an analog lowpass filter with cutoff frequency of 1, translates this “prototype” filter to the desired bandconfiguration, then transforms the filter to the digital domain. The toolboxprovides functions for each step of this process.

Classical IIR Filter Design

Page 118: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 118/870

2-38

The but t er , cheby1, cheby2, and el l i p functions are sufficient for manydesign problems, and the lower level functions are generall y not needed. But if you do have an application where you need to transform the band edges of ananalog filter, or discretize a rational transfer function, this section describesthe tools with which to do so.

Classical IIR Filter Design

Analog Lowpass Prototype Creation Frequency Transformation Discretization

but t apel l i pap cheb1apcheb2ap bessel ap l p2l pl p2bp l p2hpl p2bs bi l i neari mpi nvar

but t er cheby1 cheby2 el l i p bessel f

Minimum Order Computation for Classical IIR Filter Design

but t or d cheb1or d cheb2or d el l i por d

Complete Design

Special Topics in IIR Filter Design

Analog Prototype Design This toolbox provides a number of functions tocreate lowpass analog prototype

filters with cutoff frequency of 1, thefirst step in the classical approach to I I Rfilter design. The table below summarizes the analog prototype designfunctions for each supported filter type; plots for each type are shown in “IIRFilter Design” on page 2-5.

Filter Type Analog Prototype Function

Page 119: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 119/870

2-39

Frequency Transformation The second step in the analog prototyping design technique is the frequencytransformation of a lowpass prototype. The toolbox provides a set of functionsto transform analog lowpass prototypes (with cutoff frequency of 1 rad/s) intobandpass, highpass, bandstop, and lowpass filters of the desired cutoff frequency.

Filter Type Analog Prototype Function

Bessel [ z , p, k] = bessel ap( n)

Butterworth [ z , p, k] = but t ap(n)

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

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

Elliptic [ z , p, k] = el l i pap(n, Rp, Rs )

2 Filter Design

Freq. Transformation Transformation Function

Lowpass to lowpass [ numt , dent ] = l p2l p( num, den, Wo)

[ At , Bt , Ct , Dt ] = l p2l p( A, B, C, D, Wo)

Lowpass to highpass [ numt , dent ] = l p2hp( num, den, Wo)

[ At , Bt , Ct , Dt ] = l p2hp( A, B, C, D, Wo)

s' s ω0 ⁄ =

s'ω0

s-------=

Page 120: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 120/870

2-40

As shown, all of the frequency transformation functions can accept two linearsystem models: transfer function and state-space form. For the bandpass andbandstop cases

and

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

The frequency transformation functions perform frequency variablesubstitution. I n the case of l p2bp and l p2bs, this is a second-ordersubstitution, sothe output fil ter is twice theorder of theinput. F or l p2l p andl p2hp, the output filter is the same order as the input.

To begin designing an order 10 bandpass Chebyshev type I filter with a valueof 3 dB for passband ripple, enter

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

Lowpass to bandpass [ numt , dent ] = l p2bp( num, den, Wo, Bw)

[ At , Bt , Ct , Dt ] = l p2bp( A, B, C, D, Wo, Bw)

Lowpass to bandstop [ numt , dent ] = l p2bs( num, den, Wo, Bw)

[ At , Bt , Ct , Dt ] = l p2bs(A, B, C, D, Wo, Bw)

s'ω

0Bω-------

s ω0

⁄ ( )2 1+

s ω0 ⁄ -------------------------------=

s'Bω

ω0-------

s ω0 ⁄

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

ω0 ω1ω2=

Bω ω2 ω1–=

Special Topics in IIR Filter Design

Outputs z, p, and k contain thezeros, poles, and gain of a lowpass analog filterwith cutoff frequency Ωc equal to 1 rad/s. Use thel p2bp function to transformthis lowpass prototype to a bandpass analog filter with band edges

and . First, convert the filter tostate-space form so the l p2bp functioncan accept it.

[ A, B, C, D] = zp2ss( z, p, k) ; % Conver t t o st at e- space f or m.

Now, find the bandwidth and center frequency, and call l p2bp.

Ω1

π 5 ⁄ =

Ω2 π=

Page 121: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 121/870

2-41

u1 = 0. 1*2*pi ; u2 = 0. 5*2*pi ; % I n r adi ans per second

Bw = u2- u1;

Wo = sqr t ( u1*u2) ;[ At , Bt , Ct , Dt ] = l p2bp( A, B, C, D, Wo, Bw) ;

Finally, calculate the frequency response and plot its magnitude.

[ b, a] = ss2t f ( At , Bt , Ct , Dt ) ; % Conver t t o TF f or m.

w = l i nspace( 0. 01, 1, 500) *2*pi ; % Generate f requency vector .

h = f r eqs( b, a, w) ; % Comput e f requency r esponse.

semi l ogy(w/ 2/ pi , abs(h) ) , gr i d %Pl ot l og magni tude vs. f r eq.

xl abel ( ' 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 Discretization The third step in theanalog prototyping technique is thetransformation of the

filter to the discrete-time domain. The toolbox provides two methods for this:theimpulseinvariant and bilinear transformations. The filter design functionsbut t er , cheby1, cheby2, and el l i p use the bilinear transformation fordiscretization in this step.

Analog to Digital Transformation Function

Page 122: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 122/870

2-42

Impulse Invariance

The toolbox function i mpi nvar creates a digital filter whose impulse response

is the samples of the continuous impulse response of an analog filter. Thisfunction works only on filters in transfer function form. For best results, theanalogfilter should have negligible frequency content abovehalf the samplingfrequency, because such high frequency content is aliased into lower bandsupon sampling. I mpulse invariance works for some lowpass and bandpassfilters, but i s not appropriate for highpass and bandstop filters.

Design a Chebyshev type I filter and plot its frequency response.

[ bz , az] = i mpi nvar ( b, a, 2) ;[ H, w] = f r eqz( bz, az) ;

f r eqzpl ot ( H, w)

g gTransformation

I mpulse invariance [ numd, dend] = i mpi nvar ( num, den, f s)

Bilinear transform [ zd, pd, kd] = bi l i near ( z ,p, k, f s, Fp)

[ numd, dend] = bi l i near ( num, den, f s, Fp)

[ Ad, Bd, Cd, Dd] = bi l i near( At , Bt , Ct , Dt , f s , Fp)

Special Topics in IIR Filter Design

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 123: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 123/870

2-43

I mpulse invariance retains the cutoff frequencies of 0.1 Hz and 0.5 Hz.

Bilinear Transformation

The bilinear transformation is a nonlinear mapping of the continuous domainto the discrete domain; it maps the s-plane into the z-plane by

Bilinear transformation mapsthe -axis of thecontinuous domain totheunitcircle of the discrete domain according to

The toolbox function bi l i near implements this operation, where the frequencywarping constant k is equal to twice the sampling frequency (2*f s) by default,and equal to if you give bi l i near a trailing argument thatrepresents a “match” frequency Fp. I f a match frequency Fp (in hertz) ispresent, bi l i near maps the frequency (in rad/s) to the samefrequency in the discrete domain, normalized to the sampling rate:

(also in rad/s).

0 0.2 0.4 0.6 0.8 1−800

−600

−400

−200

0

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

=

ω 2tan 1– Ωk----è ø

=

2πf p πf p f s ⁄ ( )tan ⁄

Ω 2πf p

=

ω 2πf p f s ⁄ =

2 Filter Design

The bi l i near function can perform this transformation on three differentlinear system representations: zero-pole-gain, transfer function, andstate-space form. Try calling bi l i near with the state-space matrices that

describethe Chebyshev typeI filter fromtheprevious section, usinga samplingfrequency of 2 Hz, and retaining the lower band edge of 0.1 Hz.

[ Ad, Bd, Cd, Dd] = bi l i near ( At , Bt , Ct , Dt , 2, 0. 1) ;

The frequency response of the resulting digital filter is

[ bz az] = ss2t f ( Ad Bd Cd Dd) ; % conver t t o TF

Page 124: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 124/870

2-44

[ bz, az] = ss2t f ( Ad, Bd, Cd, Dd) ; % conver t t o TF

f r eqz( bz, az)

The lower band edge is at 0.1 Hz as expected. Notice, however, that the upper

band edge is slightly less than 0.5 Hz, although in the analog domain it wasexactly 0.5 Hz. This illustrates the nonlinear nature of the bilineartransformation. To counteract this nonlinearity, it is necessary tocreateanalogdomain fil ters with “prewarped”band edges, which maptothecorrect locationsupon bilinear transformation. Here the prewarped frequencies u1 and u2

generate Bwand Wo for the l p2bp function.

f s = 2; % Sampl i ng f r equency ( her t z)

u1 = 2*f s*tan( 0. 1*( 2*pi / f s)/ 2) ; % Lower band edge ( r ad/ s)

u2 = 2*f s*tan( 0. 5*( 2*pi / f s)/ 2) ; % Upper band edge ( r ad/ s)

Bw = u2 - u1; % Bandwi dt h

Wo = sqr t ( u1*u2) ; % Cent er f r equency

[ At , Bt , Ct , Dt ] = l p2bp( A, B, C, D, Wo, Bw) ;

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

-500

0

500

Normalized frequency (Nyquist == 1)

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

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

-200

-100

0

Normalized frequency (Nyquist == 1)

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

Special Topics in IIR Filter Design

A digital bandpass filter with correct band edges 0.1 and 0.5 times theNyquistfrequency is

[ Ad, Bd, Cd, Dd] = bi l i near ( At , Bt , Ct , Dt , f s) ;

The example bandpass filters from the last two sections could also be createdin one statement using the complete I I R design function cheby1. For instance,an analog version of the example Chebyshev filter is

[ b, a] = cheby1( 5, 3, [ 0. 1 0. 5] *2*pi , ' s ' ) ;

Page 125: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 125/870

2-45

Note that the band edges are in rad/s for analog filters, whereas for the digitalcase, frequency is normalized (the Nyquist frequency is equal to 1 Hz).

[ bz, az] = cheby1( 5, 3, [ 0. 1 0. 5] ) ;

All of thecompletedesign functions call bi l i near internally. They prewarp theband edges as needed to obtain the correct digital filter. See Chapter 7,“Function Reference,” for more on these functions.

2 Filter Design

Selected Bibliography

[1] K aram, L .J ., and J .H. McClellan. “Complex Chebyshev Approximation forFIR Filter Design.” I EE E Trans. on Ci rcuits and Systems I I . March 1995.

[2] Selesnick, I .W., and C.S. Burrus. “Generalized Digital Butterworth FilterDesign.”Proceedings of theI EE E Int. Conf. Acoust., Speech, Signal Processing.Vol. 3 (May 1996).

[3] Selesnick, I .W., M. L ang, and C.S. Burrus. “Constrained L east SquareD i f FI R Filt ith t S ifi d T iti B d ” P di f th

Page 126: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 126/870

2-46

Design of FI R Filters without Specified Transition Bands.” Proceedings of theI E EE I nt. Conf. Acoust., Speech, Signal Processing. Vol. 2 (May 1995).

Pgs. 1260-1263.

3Statistical Signal

Processing

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

Correlation and Covariance 3-3

Page 127: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 127/870

Correlation and Covariance . . . . . . . . . . . . . 3-3Bias and N ormalizati on . . . . . . . . . . . . . . . . 3-4

Multiple Channels . . . . . . . . . . . . . . . . . . 3-5

Spectral Analysis . . . . . . . . . . . . . . . . . . 3-6Spectral Estimation Method Overview . . . . . . . . . . 3-8N onparametric M ethods . . . . . . . . . . . . . . . . 3-10Parametric M ethods . . . . . . . . . . . . . . . . . 3-30

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

3 Statistical Signal Processing

Overview

The Signal Processing Toolbox provides tools for estimating important

functions of random signals. I n particular, there are tools to estimatecorrelation and covari ance sequences and spectral density functions of discretesignals. The foll owing sectionsexplain thecorrelation and covariancefunctionsand discuss the mathematically related functions for estimating the powerspectrum:

• “Correlation and Covariance”

Page 128: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 128/870

3-2

• “Spectral Analysis”

• “Selected Bi bliography”

Correlation and Covariance

Correlation and Covariance

The functions xcor r and xcov estimate the cross-correlation and

cross-covariance sequences of random processes. They also handleautocorrelation and autocovariance as special cases.

The true cross-correlation sequence is a statistical quantity defined as

where x and y arestationary random processes and E is the

R xy m( ) E xn m+y*n E xny*n m– ==

n

Page 129: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 129/870

3-3

where xn and yn arestationary random processes, , and E ⋅is the

expected value operator. The covariance sequence is the mean-removedcross-correlation sequence

or, in terms of the cross-correlation,

I n practice, you must estimate thesesequences, becauseit is possible to accessonly a finitesegment of theinfinite-length random process. A common estimatebased on N samples of xn and yn is the determini stic cross-correlation sequence(also called the time-ambiguity function)

where we assume for this discussion that xn and yn are indexed from 0 to N-1,and from -(N-1) toN-1. Thexcor r function evaluates this sum with anefficient FFT-based algorithm, given inputs xn and yn stored in length N

vectors x and y. I ts operation is equivalent to convolution with one of the twosubsequences reversed in time.

For example,

x = [ 1 1 1 1 1] ' ;

y = x;

∞– n ∞< <

Cxy m( ) E xn m+µx–( ) yn µy–( )

*=

Cxy m( ) R xy m( ) µxµ*y–=

xy m( )

xn m+yn

*

n 0=

N m– 1–

å m 0≥

yx*

m–( ) m 0<î

=

xy m( )

3 Statistical Signal Processing

xyc = xcor r ( x, y)

xyc =

1. 0000

2. 0000

3. 0000

4. 0000

5. 0000

4. 0000

3. 0000

Page 130: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 130/870

3-4

3 0000

2. 0000

1. 0000

Notice that the resulting sequence length is one less than twice the length of the input sequence. Thus, the Nth element is the correlation at lag 0. Alsonotice the triangular pulse of the output that results when convolving twosquare pulses.

The xcov function estimates autocovariance and cross-covariance sequences. This function has the same options and evaluates the same sum as xcorr , butfirst removes the means of x and y.

Bias and NormalizationAn estimate of a quantity is biased if its expected value is not equal to thequantity it estimates. The expected value of the output of xcor r is

xcor r provides the unbiased estimate, dividing by N-| m| , when you specify an' unbi ased' flag after the input sequences.

xcor r( x, y, ' unbi ased' )

Although this estimate is unbiased, the end points (near -(N-1) and N-1) sufferfrom largevariancebecausexcor r computes them usingonly a few data points.

A possible trade-off is to simply divide by N using the ' bi ased' flag.

xcorr ( x, y, ' bi ased' )

E

xy m( )

E

xn m+

y*n

n 0=

– –

åN m–( )R

xym( )= =

Correlation and Covariance

With this scheme, only thesampleof thecorrelation at zero lag(theNth outputelement) is unbiased. This estimateis often more desirable than the unbiasedone because it avoids random large variations at the end points of the

correlation sequence.

xcorr provides one other normalization scheme. The syntax

xcorr ( x, y, ' coef f ' )

divides the output by nor m( x) *norm( y) so that, for autocorrelations, thesample at zero lag is 1.

Page 131: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 131/870

3-5

Multiple ChannelsFor a multichannel signal, xcor r and xcov estimate the autocorrelation andcross-correlation and covari ance sequences for all of the channels at once. I f Sis an M-by-N signal matrix representing N channels in its columns, xcor r ( S)

returnsa (2M-1)-by-N2 matrix with theautocorrelationsandcross-correlationsof the channels of S in its N2 columns. I f S is a three-channel signal

S = [ s1 s2 s3]

then the result of xcor r ( S) is organized as

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

Two related functions, cov and cor r coef , are available in the standardMAT L AB environment. They estimate covariance and normalized covariancerespectively between the different channels at lag 0 and arrange them in asquare matrix.

3 Statistical Signal Processing

Spectral Analysis

The goal of spectral estimation is to describe the distribution (over frequency)

of the power contained in a signal, based on a finite set of data. Estimation of power spectra is useful in a variety of applications, including the detection of signals buried in wide-band noise.

The power spectrum of a stationary random process xn is mathematicallyrelated to the correlation sequence by the discrete-time Fourier transform. I nterms of normalized frequency, this is given by

Page 132: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 132/870

3-6

This can be written asa function of physical frequency f (e.g., in hertz) by usingthe relation ω =2πf /f s, where f s is the sampling frequency.

The correlation sequence can bederived from thepower spectrum byuse of theinverse discrete-time Fourier transform.

The average power of the sequence xn over the entire Nyquist interval isrepresented by

Sxx ω( ) Rxx m( )e j ωm–

m ∞–=

å=

Sxx f ( ) R xx m( )e 2π j fm– f s ⁄

m ∞–=

å=

R xx m( )Sxx ω( )e j ωm

2π------------------------------ ωd

π–

πSxx f ( )e2π j fm f s ⁄

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

f s 2 ⁄ –

f s 2 ⁄

= =

R xx 0( )Sxx ω( )

2π----------------- ωd

π–

πSxx f ( )

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

f s 2 ⁄ –

f s 2 ⁄

= =

Spectral Analysis

The quantities

from the above expression are defined as the power spectral density (PSD) of the stationary random signal xn.

The average power of a signal over a particular frequency band ,, can be found by integrating the PSD over that band.

P xx ω( )

Sxx ω( )

2π-----------------=P

xxf ( )

Sxx f ( )

f s---------------=and

ω1 ω2[ , ]

0 ω1 ω2 π≤<≤

Page 133: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 133/870

3-7

You can seefrom theaboveexpression that Pxx(ω) represents the power contentof a signal in an infinitesimal frequency band, which is whywecall it thepowerspectral density.

The units of the PSD are power (e.g., watts) per unit of frequency. I n the case

of Pxx(ω), this is watts/rad/sample or simply watts/rad. I n thecase of Pxx(f ), theunits are watts/hertz. I ntegration of the PSD with respect to frequency yieldsunits of watts, as expected for the average power .

For real signals, theP SD is symmetric about DC, and thus Pxx(ω) foris sufficient to completely characterize the PSD. However, in order to obtainthe average power over theentire Nyquist interval it is necessary to introducethe concept of the one-sided PSD.

The one-sided PSD is given by

Theaveragepower of a signal over thefrequency band , ,can be computed using the one-sided PSD as

P ω1 ω2,[ ] P xx ω( ) ωd

ω1

ω2

P xx ω( ) ωd

ω– 2

ω– 1

+=

P ω1 ω2,[ ]

0 ω π<≤

P onesi ded ω( )0 -π ω≤ 0<,

2P xx ω( ) 0 ω≤ π<,î

=

ω1 ω2[ , ] 0 ω1 ω2 π≤<≤

P ω1 ω2,[ ] P onesi ded ω( ) ωd

ω1

ω2

=

3 Statistical Signal Processing

Spectral Estimation Method Overview The various methodsof spectrum estimation available in theSignal Processing Toolbox can be categorized as follows:

• Nonparametric methods

• Parametric methods

• Subspace methods

Nonparametric methods are those in which the estimate of the PSD is madedirectly from the signal itself. The simplest such method is the periodogram.A i d i f th i d i W l h’ th d [8] A d

Page 134: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 134/870

3-8

An improved version of the periodogram is Welch’s method [8]. A more modern

nonparametri c technique is the multitaper method (MTM).

Parametric methods are those in which the signal whosePSD we want toestimate is assumed to be output of a linear system driven by white noise.Examples are the Yule-Walker autoregressive(AR) method and the Burgmethod. These methods estimate the PSD by first estimating the parameters(coefficients) of the linear system that hypothetically “generates” the signal. They tend to produce better results than classical nonparametric methods

when the data length of the available signal is relatively short.Subspacemethods, also known as high-resolution methods or super-resolutionmethods, generate frequency component estimates for a signal based on aneigenanalysis or eigendecompositi on of the correlation matrix. Examples arethe multiplesignal classification (MUSIC) method or the eigenvector (EV)method. These methods are best suited for l ine spectra – that is, spectra of sinusoidal signals – and are effective in the detection of sinusoids buried innoise, especially when the signal to noise ratios are low.

All three categories of methods are listed in the table below with thecorresponding toolbox function names. The number below each method nameindicates thepage that describes the method in greater detail. See“ParametricModeli ng” on page 4-11 for details about l pc and other parametric estimationfunctions.

Spectral Analysis

Method Description Functions

Periodogram

(3-10)

Power spectral density estimate peri odogr am

Welch(3-20)

Averaged periodograms of overlapped, windowed signal sections

pwel ch, csd,t f e, cohere

Multitaper(3-24)

Spectral estimate from combinationof multiple orthogonal windows (or“tapers”)

pmt m

Page 135: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 135/870

3-9

Yule-Walker AR(3-32)

Autoregressive (AR) spectralestimateof a time-series from itsestimated autocorrelation function

pyul ear

Burg(3-33)

Autoregressive (AR) spectralestimation of a time-seri es byminimization of linear prediction

errors

pburg

Covariance(3-36)

Autoregressive (AR) spectralestimation of a time-seri es by

minimization of the forwardprediction errors

pcov

Modified

Covariance(3-36)

Autoregressive (AR) spectral

estimation of a time-seri es byminimization of the forward and

backward prediction errors

pmcov

MUSIC(3-36)

Multiple signal classification pmusi c

Eigenvector(3-36)

Pseudospectrum estimate pei g

3 Statistical Signal Processing

Nonparametric Methods The following sections discuss the periodogram, modified periodogram, Welch,and multitaper methods of nonparametric estimation, along with the relatedCSD function, transfer function estimate, and coherence function.

The Periodogram

One way of estimating the power spectrum of a process is to simply find thediscrete-time Fourier transform of the samples of the process (usually done ona grid with an F FT ) and take the magnitude squared of the result. Thisestimate is called the periodogram.

Page 136: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 136/870

3-10

The periodogram estimate of the PSD of a length-L signal xL[n] is

where

The actual computation of XL(f ) can be performed only at a finite number of frequency points, N, and usually employs the FF T. I n practice, mostimplementations of the periodogram method compute the N-point PSDestimate

where

I t is wise to choose N >L so that N is the next power of two larger than L . Toevaluate XL [f k], wesimply pad xL [n] with zeros to length N. I f L >N, wemustwrap xL [n] modulo-N prior to computing XL [f k].

P xx f ( )XL f ( )

2

f sL--------------------=

XL f ( ) xL n[ ]e

2π j fn– f s ⁄

n 0=

å=

P xx f k[ ]X

L

f k

[ ]2

f sL----------------------- ,= f kkf

sN--------,= k 0 1 … N 1–, , ,=

XL f k[ ] xL n[ ]e2π j kn– N ⁄

n 0=

N 1–

å=

Spectral Analysis

As an example, consider the following 1001-element signal xn, which consistsof two sinusoids plus noise.

randn( ' state ' , 0) ;

f s = 1000; % Sampl i ng f r equency

t = (0: f s ) / f s ; % One second wor t h of sampl es

A = [ 1 2] ; % Si nusoi d ampl i t udes ( r ow vect or )

f = [150; 140] ; % Si nusoi d f requenci es (col umn vector )

xn = A*si n( 2*pi *f *t ) + 0. 1*r andn( si ze( t ) ) ;

Note The three last lines illustrate a convenient and general way to express

Page 137: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 137/870

3-11

Note The three last l ines illustrate a convenient and general way to expressthe sum of sinusoids. Together they are equivalent to

xn = si n( 2*pi *150*t ) + 2*si n( 2*pi *140*t ) + 0. 1*r andn( si ze( t ) ) ;

The periodogram estimate of the PSD can be computed by

Pxx = per i odogr am( xn, [ ] , ' t wosi ded' , 1024, f s) ;

and a plot of the estimate can bedisplayed by simply omitting the outputargument, as below.

per i odogr am( xn, [ ] , ' t wosi ded' , 1024, f s) ;

0 100 200 300 400 500 600 700 800 900−90

−80

−70

−60

−50

−40

−30

−20

−10

0

Frequency (Hz)

P o w e r S p e c t r a l D e n s i t y ( d B / H z )

Periodogram PSD Estimate

3 Statistical Signal Processing

The average power can be computed by approximating the integral with thefollowing sum.

Pow = ( f s/ l engt h( Pxx) ) * sum( Pxx)

Pow =

2. 5028

You can also compute the average power from the one-sided PSD estimate.

Pxxo = peri odogr am( xn, [ ] , 1024, f s) ;

Pow = ( f s/ ( 2*l engt h( Pxxo) ) ) * sum( Pxxo)

Page 138: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 138/870

3-12

Pow = ( f s/ ( 2*l engt h( Pxxo) ) ) * sum( Pxxo)

Pow =

2. 4979

Performance of the Periodogram

The following sections discuss theperformance of theperiodogram with regardto the issues of leakage, resolution, bias, and variance.

Spectral Leakage. Consider the power spectrum or PSD of a fini te-length signalxL [n], as discussed in “The Periodogram” on page 3-10. I t is frequently usefulto interpret xL [n] as the result of multiplying an infinite signal, x[n], by afinite-length rectangular window, wR[n].

Because multiplication in the time domain corresponds to convolution in the

frequency domain, the Fourier transform of the expression above is

The expression developed earlier for the periodogram,

illustrates that the periodogram is alsoinfluenced by this convolution.

xL n[ ] x n[ ] wR n[ ]⋅=

XL f ( )1f s---- X ρ( )WR f ρ–( ) ρd

f s 2 ⁄ –

f s 2 ⁄

=

P xx f ( )XL f ( ) 2

f sL--------------------=

Spectral Analysis

The effect of the convolution is best understood for sinusoidal data. Supposethat x[n] is composed of a sum of M complex sinusoids.

I ts spectrum is

x n[ ] Ake j ωkn

k 1=

M

å=

X f ( ) f s Akδ f f k–( )

M

å=

Page 139: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 139/870

3-13

which for a finite-length sequence becomes

So in the spectrum of the finite-length signal, the Dirac deltas havebeenreplaced by terms of the form , which corresponds to the frequencyresponse of a rectangular window centered on the frequency f k.

The frequency response of a rectangular window has theshapeof a sincsignal,as shown below.

k 1=

XL f ( ) Akδ ρ f k–( )

k 1=

M

å

WR f ρ–( ) ρd

f s 2 ⁄ –

f s 2 ⁄

AkWR f f k–( )

k 1=

M

å= =

WR f f k–( )

−0.5 0 0.5−90

−80

−70

−60

−50

−40

−30

−20

−10

0

3 Statistical Signal Processing

The plot displays a main lobe and several sidelobes, the largest of which isapproximately 13.5 dB below the mainlobe peak. These lobes account for theeffect known as spectral leakage. While theinfinite-length signal has its power

concentrated exactly at the discrete frequency points f k, the windowed (ortruncated) signal has a continuum of power “leaked” around the discretefrequency points f k.

Becausethefrequency responseof a short rectangular window is a much poorerapproximation to the Dirac delta function than that of a longer window,spectral leakageis especially evident when data records areshort. Consider thefollowing sequence of 100 samples.

Page 140: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 140/870

3-14

r andn( ' state' , 0)f s = 1000; % Sampl i ng f r equency

t = ( 0: f s/ 10) / f s; % One- t ent h of a second wor t h of sampl es

A = [ 1 2] ; % Si nusoi d ampl i t udes

f = [ 150; 140] ; % Si nusoi d f r equenci es

xn = A*si n( 2*pi *f *t ) + 0. 1*r andn( si ze( t ) ) ;

per i odogr am( xn, [ ] , 1024, f s) ;

I t is important to note that theeffect of spectral leakage is contingent solely onthe length of the data record. I t is not a consequence of the fact that theperiodogram is computed at a finite number of frequency samples.

0 100 200 300 400 500−80

−70

−60

−50

−40

−30

−20

−10

0

Frequency (Hz)

P o w e r S p e

c t r a l D e n s i t y ( d B / H z )

Periodogram PSD Estimate

Spectral Analysis

Resolution. Resolution refers totheability to discriminatespectral features, andis a key concept on the analysis of spectral estimator performance.

I n order toresolvetwosinusoids that arerelatively closetogether in frequency,it is necessary for thedifferencebetween thetwofrequenciesto begreater thanthewidth of themainlobeof theleaked spectra for either oneof thesesinusoids. The mainlobe width is defined to be the width of the mainlobe at the pointwhere the power is half thepeak mainlobe power (i.e., 3 dB width). This widthis approximately equal to f s / L .

I n other words, for two sinusoids of frequencies f 1 and f 2, the resolvabilitycondition requires that

Page 141: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 141/870

3-15

I n the example above, where two sinusoids are separated by only 10 Hz, thedata record must be greater than 100 samples to allow resolution of twodistinct sinusoids by a periodogram.

Consider a case where this criterion is not met, as for the sequence of 67

samples below.r andn( ' state' , 0)

f s = 1000; % Sampl i ng f r equency

t = ( 0: f s / 15) . / f s; % 67 sampl es

A = [ 1 2] ; % Si nusoi d ampl i t udes

f = [ 150; 140] ; % Si nusoi d f r equenci es

xn = A*si n( 2*pi *f *t ) + 0. 1*r andn( si ze( t ) ) ;

per i odogr am( xn, [ ] , 1024, f s) ;

∆f f 1 f 2–( )f sL---->=

3 Statistical Signal Processing

−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 142: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 142/870

3-16

The abovediscussion about resolution did not consider theeffects of noisesincethe signal-to-noise ratio (SNR) has been relatively high thus far. When theSNR is low, true spectral features are much harder to distinguish, and noise

artifacts appear in spectral estimates based on the periodogram. The examplebelow illustrates this.

r andn( ' state' , 0)

f s = 1000; % Sampl i ng f r equency

t = ( 0: f s/ 10) . / f s; % One- t ent h of a second wor t h of sampl es

A = [ 1 2] ; % Si nusoi d ampl i t udes

f = [ 150; 140] ; % Si nusoi d f r equenci es

xn = A*si n( 2*pi *f *t ) + 2*r andn( si ze( t ) ) ;

per i odogr am( xn, [ ] , 1024, f s) ;

0 100 200 300 400 500−70

−60

Frequency (Hz)

Spectral Analysis

45

−40

−35

−30

−25

−20

−15

−10

−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 )

Periodogram PSD Estimate

Page 143: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 143/870

3-17

Bias of the Periodogram. The periodogram is a biased estimator of the PSD. I tsexpected value can be shown to be

which is similar to the first expression for XL (f ) in “Spectral L eakage” onpage 3-12, except that the expression here is in terms of average power ratherthan magnitude. This suggests that the estimates produced by theperi odogram correspond to a leaky PSD rather than the true PSD.

Notethat essentially yields a triangular Bartlett window (whichis apparent from the fact that the convolution of two rectangular pulses is atriangular pulse). This results in a height for thelargest sidelobes of theleakypower spectra that is about 27 dB below themainlobepeak;i.e., about twicethefrequency separation relative to the non-squared rectangular window.

The periodogram is asymptotically unbiased, which is evident from theearlierobservation that as the data record length tends to infinity, the frequency

responseof the rectangular window more closely approximates the Dirac deltafunction (also true for a Bartlett window). However, in some cases theperiodogram is a poor estimator of the PSD even when the data record is long. This is due to the variance of the periodogram, as explained below.

0 100 200 300 400 500−55

−50

−45

Frequency (Hz)

EXL f ( )

2

f sL--------------------

î 1

f sL-------- P xx ρ( ) WR f ρ–( )

2ρd

f s 2 ⁄ –

f s 2 ⁄

=

WR f ρ–( )2

3 Statistical Signal Processing

Variance of the Periodogram. The variance of the periodogram can be shown to beapproximately

which indicates that the variance does not tend to zero as the data length L

tends to infinity. I n statistical terms, the periodogram is not a consistentestimator of the PSD. Nevertheless, the periodogram can be a useful tool forspectral estimation in situations where the SNR is high, and especially if thedata record is long.

var XL f ( )2

f sL--------------------

î þ P xx

2 f ( ) 1 2πL f f s ⁄ ( )sinL 2πf f s ⁄ ( )sin------------------------------------

2+≈

Page 144: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 144/870

3-18

The Modified Periodogram

The modified peri odogram windows thetime-domain signal prior to computingthe FFT in order to smooth the edges of the signal. This has the effect of reducing the height of the sidelobes or spectral leakage. Thi s phenomenongives riseto the interpretation of sidelobes as spurious frequencies introducedinto the signal by the abrupt truncation that occurs when a rectangularwindow is used. For nonrectangular windows, the end points of the truncated

signal are attenuated smoothly, andhencethe spurious frequencies introducedaremuch less severe.On theother hand, nonrectangular windowsalsobroadenthe mainlobe, which results in a net reduction of resolution.

The peri odogr amfunction allows you to compute a modified periodogram byspecifying the window to be used on the data. F or example, compare arectangular window and a Hamming window.

r andn( ' state' , 0)

f s = 1000; % Sampl i ng f r equencyt = ( 0: f s/ 10) . / f s; % One- t ent h of a second wor t h of sampl es

A = [ 1 2] ; % Si nusoi d ampl i t udes

f = [ 150; 140] ; % Si nusoi d f r equenci es

xn = A*si n( 2*pi *f *t ) + 0. 1*r andn( si ze( t ) ) ;

per i odogr am( xn, boxcar( l engt h( xn) ) , 1024, f s) ;

Spectral Analysis

−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 145: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 145/870

3-19

peri odogr am( xn, hammi ng( l engt h( xn) ) , 1024, f s) ;

You can verify that although the sidelobes are much less evident in the

Hamming-windowed periodogram, the two main peaks are wider. I n fact, the3 dB width of the mainlobe corresponding to a Hamming window isapproximately twice that of a rectangular window. Hence, for a fixed datalength, the PSD resolution attainable with a Hamming 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

approximately half that attainable with a rectangular window. The competinginterests of mainlobe width and sidelobe height can beresolved to some extentby using variable windows such as the K aiser window.

Nonrectangular windowing affects the averagepower of a signal becausesomeof the time samples are attenuated when multiplied by the window. Tocompensate for this, the per i odogr amfunction normalizes the window to havean average power of unity. This way the choice of window does not affect theaverage power of the signal.

The modified periodogram estimate of the PSD is

P f( ) XL f( )

2

Page 146: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 146/870

3-20

where U is the window normalization constant

which is independent of the choice of window. The addition of U as anormalization constant ensures that the modified periodogram isasymptotically unbiased.

Welch’s Method

An improved estimator of the PSD is the one proposed by Welch [8]. Themethod consists of dividing the time series data into (possibly overlapping)

segments, computing a modified periodogram of each segment, and thenaveraging the PSD estimates. The result is Welch’s PSD estimate.

Welch’s method is implemented in theSignal Processing Toolbox bythepwel ch

function. By default, the data is divided into eight segments with 50% overlapbetween them. A Hamming window is used to compute the modifiedperiodogram of each segment.

The averaging of modified periodograms tends to decrease the variance of the

estimate relative to a single periodogram estimate of the entire data record.Althoughoverlapbetween segments tends tointroduceredundant information,this effect is diminished by theuse of a nonrectangular window, which reduces

P xx f ( ) XL f ( )f sL U

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

U1L---- w n( )

2

n 0=

L 1–

å=

Spectral Analysis

the importance or weight given to the end samples of segments (the samplesthat overlap).

However, as mentioned above, the combined use of short data records andnonrectangular windows results in reduced resolution of the estimator. I nsummary, there is a tradeoff between variance reduction and resoluti on. Onecan manipulate the parameters in Welch’s method to obtain improvedestimates relative to the periodogram, especially when the SNR is low. This isillustrated in the following example.

Consider an original signal consisting of 301 samples.

r andn( ' state' , 1)

f s = 1000; % Sampl i ng f r equency

Page 147: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 147/870

3-21

f s 1000; % Sampl i ng f r equencyt = ( 0: 0. 3*f s ) . / f s; % 301 sampl es

A = [ 2 8] ; % Si nusoi d ampl i t udes ( row vect or )

f = [ 150; 140] ; % Si nusoi d f r equenci es ( col umn vect or )

xn = A*si n( 2*pi *f *t ) + 5*r andn( si ze( t ) ) ;

per i odogr am( xn, boxcar ( l engt h( xn) ) , 1024, f s) ;

0 100 200 300 400 500−60

−50

−40

−30

−20

−10

0

10

Frequency (Hz)

P o w e r S

p e c t r a l D e n s i t y ( d B / H z )

Periodogram PSD Estimate

3 Statistical Signal Processing

We can obtain Welch’s spectral estimate for 3 segments with 50%overlap with

pwel ch( xn, boxcar ( 150) , 75, 512, f s) ;

−10

−5

0

5

10

p e c t

r a l D e n s i t y ( d B / H z )

Welch PSD Estimate

Page 148: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 148/870

3-22

I n the periodogram above, noise and the leakage make one of the sinusoidsessentially indistinguishable from the artificial peaks. I n contrast, althoughtheP SD produced by Welch’s method has wider peaks, you can still distinguishthe two sinusoids, which stand out from the “noise floor.”

However, if wetry to reduce thevariance further, the loss of resolution causesone of the sinusoids to be lost altogether.

pwel ch( xn, hammi ng( 100) , 75, 512, f s) ;

0 100 200 300 400 500−25

−20

−15

Frequency (Hz)

P o w e r S p

Spectral Analysis

−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 149: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 149/870

3-23

For a more detailed discussion of Welch’s method of P SD estimation, seeK ay [2] and Welch [8].

Bias and Normalization in Welch’s MethodWelch’s method yields a biased estimator of the PSD. The expected value canbe found to be

where L s is the length of the data segments and U is the same normalizationconstant present in the definition of the modified periodogram. As is the casefor all periodograms, Welch’s estimator is asymptotically unbiased. F or a fixedlength data record, the bias of Welch’s estimate is larger than that of theperiodogram because L s <L .

The variance of Welch’s estimator is difficult to compute becauseit depends onboth the window used andthe amount of overlap between segments. Basically,the variance is inversely proportional to the number of segments whosemodified periodograms are being averaged.

0 100 200 300 400 500−20

Frequency (Hz)

E P welch 1

f sL sU---------------- P xx ρ( ) W f ρ–( )

2ρd

f s 2 ⁄ –

f s 2 ⁄

=

3 Statistical Signal Processing

Multitaper Method

The periodogram can be interpreted as filtering a length L signal, xL [n],through a filter bank (a set of filters in parallel) of L FI R bandpass filters. The

3 dB bandwidth of each of these bandpass filters can be shown to beapproximately equal to f s / L . The magnitude response of each one of thesebandpass filters resembles that of the rectangular window discussed in“Spectral L eakage” on page 3-12. The periodogram can thus be viewed as acomputation of the power of each filtered signal (i.e., the output of eachbandpass filter) that uses just one sample of each fil tered signal and assumesthat the PSD of xL [n] is constant over the bandwidth of each bandpass filter.

As the length of the signal increases, the bandwidth of each bandpass filterdecreases, making it a more selective filter, and improving the approximation

Page 150: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 150/870

3-24

of constant PSD over the bandwidth of the fil ter. This provides anotherinterpretation of why the PSD estimate of the periodogram improves as thelength of the signal increases. However, there are two factors apparent fromthis standpoint that compromise the accuracy of the peri odogram estimate.First, the rectangular window yields a poor bandpass filter. Second, thecomputation of thepower at theoutput of each bandpassfilter relies on a singlesample of the output signal, producing a very crude approximation.

Welch’s method can be given a similar interpretation in terms of a filter bank.I n Welch’s implementation, several samples are used to compute the outputpower, resulting in reduced variance of the estimate. On the other hand, thebandwidth of each bandpass filter is larger than that corresponding to theperiodogram method, which results in a loss of resolution. The filter bankmodel thus provides a new interpretation of the compromise between varianceand resolution.

Thompson’s multitaper method (MT M) builds on these results to provide animproved PSD estimate. I nstead of using bandpass filters that are essentiallyrectangular windows (as in the periodogram method), the MTM method uses abank of optimal bandpass filters to compute the estimate. These optimal F I Rfilters arederived from a set of sequences known as discreteprolatespheroidalsequences (DPSSs, also known as Slepian sequences).

I n addition, the MTM method provides a time-bandwidth parameter withwhich to balance the variance and resolution. This parameter is given by thetime-bandwidth product, NW and it is directly related to thenumber of tapersused to compute the spectrum. There are always 2*NW-1 tapers used to formthe estimate. This means that, as NW increases, there are more estimates of

Spectral Analysis

the power spectrum, and the variance of the estimate decreases. However, thebandwidth of each taper is also proportional to NW, so as NW increases, eachestimate exhibits more spectral leakage (i.e., wider peaks) and the overall

spectral estimate is more biased. For each data set, there is usually a value forNW that allows an optimal trade-off between bias and variance.

The Signal Processing Toolbox function that implements the MTM method iscalled pmt m. Use pmt mto compute the PSD of xn from the previous examples.

r andn( ' state' , 0)

f s = 1000; % Sampl i ng f r equency

t = ( 0: f s ) / f s ; % One second wor t h of sampl es

A = [ 1 2] ; % Si nusoi d ampl i t udesf = [ 150; 140] ; % Si nusoi d f r equenci es

Page 151: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 151/870

3-25

q

xn = A*si n( 2*pi *f *t ) + 0. 1*r andn( si ze( t ) ) ;

[ P, F] = pmt m( xn, 4, 1024, f s) ;

pl ot (F, 10*l og10( P) ) % Pl ot i n dB/ Hz

xl abel ( ' Frequency ( Hz) ' ) ;

yl abel ( ' Power Spect r al Densi t y ( dB/ Hz) ' ) ;

0 100 200 300 400 500−55

−50

−45

−40

−35

−30

−25

−20

−15

−10

−5

Frequency (Hz)

P o w e r S p e

c t r a l D e n s i t y ( d B / H z )

3 Statistical Signal Processing

By loweringthetime-bandwidth product, you can increasetheresoluti on at theexpense of larger variance.

[ P1, f ] = pmt m( xn, 3/ 2, 1024, f s) ;

pl ot ( f , 10*l og10( P1) ) % Pl ot i n dB/ Hzxl abel ( ' Frequency ( Hz) ' ) ;

yl abel ( ' Power Spect r al Densi t y ( dB/ Hz) ' ) ;

30

−20

−10

0

y ( d B / H z )

Page 152: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 152/870

3-26

Note that the average power is conserved in both cases.

Pow = ( f s/ 1024) * sum( P)

Pow =

2. 4926

Pow1 = ( f s/ 1024) * s um( P1)

Pow1 =

2. 4927

This method is more computationally expensive than Welch’s method due to

the cost of computing the discrete prolatespheroidal sequences. For long dataseries (10,000 points or more), it is useful to compute the DPSSs once and savethem in a MAT-file. The M-files dpsssave, dpssl oad, dpssdi r , and dpsscl ear

are provided to keep a database of saved DPSSs in the MA T-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

Spectral Analysis

Cross-Spectral Density Function

The PSD is a special case of the cross spectral density (CSD) function, definedbetween two signals xn and yn as

As is the case for the correlation and covariance sequences, the toolboxestimates the PSD and CSD because signal lengths are finite.

To estimatethe cross-spectral density of twoequal length signals x and y using

Welch’s method, the csd function forms the periodogram as the product of theFFT of x and the conjugate of the FF T of y Unlike the real-valued PSD the

Sxy ω( ) R xy m( )e j ωm–

m ∞–=

å=

Page 153: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 153/870

3-27

FFT of x and the conjugate of the FF T of y. Unlike the real-valued PSD, theCSD is a complex function. csd handles the sectioning and windowing of x andy in the same way as the pwel ch function.

Sxy = csd( x, y, nf f t , f s, wi ndow, numover l ap)

Confidence Intervals

You can compute confidence intervals using the csd function by including anadditional input argument p that specifies the percentage of the confidenceinterval, and setting thenumover l ap argument to 0.

[ Sxy, Sxyc, f ] = csd( x, y, nf f t , f s, wi ndow, 0, p)

p must be a scalar between 0 and 1. This function assumes chi-squareddistributed periodograms of the nonoverlapping sections of windowed data incomputing the confidence intervals. This assumption is valid when the signal

is a Gaussian distributed random process. Provided these assumptions arecorrect, the confidence interval

[ Sxy- Sxyc( : , 1) Sxy+Sxyc( : , 2) ]

covers the true CSD with probability p. I f you set numover l ap to any valueother than 0, you generate a warning indicating that the sections overlap andthe confidence interval is not reli able.

3 Statistical Signal Processing

Transfer Function Estimate

One application of Welch’s method is nonparametric system identification.Assume that H is a linear, time invariant system, and x(n) and y(n) are the

input to and output of H, respectively. Then the power spectrum of x(n) isrelated to the CSD of x(n) and y(n) by

An estimate of the transfer function between x(n) and y(n) is

This method estimates both magnitude and phase information The t f e

Sxy ω( ) H ω( )Sxx ω( )=

H ω( )Sxy ω( )

xx ω( )

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

Page 154: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 154/870

3-28

This method estimates both magnitude and phase information. The t f e

function uses Welch’s method to compute the CSD and power spectrum, andthen forms their quotient for the transfer function estimate. Uset f e the sameway that you use the csd function.

Filter thesignal xn with an FI R filter, then plot theactual magnitude responseand the estimated response.

h = ones( 1, 10) / 10; % Movi ng aver age f i l t er

yn = f i l t er ( h, 1, xn) ;

[ HEST, f ] = t f e( xn, yn, 256, f s, 256, 128, ' none' ) ;

H = f r eqz(h, 1, f , f s);

subpl ot ( 2, 1, 1) ; pl ot ( f , abs(H) ) ;

t i t l e( ' Actual Tr ansf er Functi on Magni t ude' ) ;

subpl ot ( 2, 1, 2) ; pl ot ( f , abs(HEST) ) ;

t i t l e( ' Tr ansf er Funct i on Magni t ude Est i mat e' ) ;

xl abel ( ' Frequency ( Hz) ' ) ;

Spectral Analysis

0 100 200 300 400 5000

0.2

0.4

0.6

0.8

1Actual Transfer Function Magnitude

0 100 200 300 400 5000

0.2

0.4

0.6

0.8

1Transfer Function Magnitude Estimate

Page 155: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 155/870

3-29

Coherence Function

The magnitude-squared coherence between two signals x(n) and y(n) is

This quotient is a real number between 0 and 1 that measures the correlationbetween x(n) and y(n) at the frequency ω.

The cohere function takes sequences x and y, computes their power spectraand CSD, and returns the quotient of the magnitude squared of the CSD andthe product of the power spectra. I ts options and operation are similar to thecsd and t f e functions.

The coherence function of xn and the filter output yn versus frequency is

coher e( xn, yn, 256, f s, 256, 128, ' none' )

0 100 200 300 400 500Frequency (Hz)

Cxy ω( )

Sxy ω( ) 2

Sxx ω( )Syy ω( )-----------------------------------=

3 Statistical Signal Processing

I f the input sequence length nf f t , window length wi ndow, and the number of overlapping data points in a window numover l ap, are such that cohere

operates on only a single record, the function returns all ones. This is becausethe coherence function for linearly dependent data is one

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 156: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 156/870

3-30

the coherence function for linearly dependent data is one.

Parametric MethodsParametric methods can yield higher resolutions than nonparametri c methodsin cases when the signal length is short. These methods use a differentapproach to spectral estimation; instead of trying to estimate the PSD directly

from the data, they model the data as the output of a linear system driven bywhite noise, and then attempt to estimate the parameters of that linearsystem.

The most commonly used linear system model is the all-pole model, a filterwith all of its zeroes at the origin in the z-plane. The output of such a filter forwhite noise input is an autoregressive (AR) process. For this reason, thesemethods are sometimes referred to as AR methods of spectral estimation.

The AR methods tend to adequately describe spectra of data that is “peaky,”that is, data whose PSD is large at certain frequencies. The data in manypractical applications (such asspeech) tendstohave“peaky spectra”sothat ARmodels are often useful. I n addition, the AR models lead to a system of linearequations which is relatively simple to solve.

The Signal P rocessing Toolbox offers the following AR methods for spectralestimation:

• Yule-Walker AR method (autocorrelation method)• Burg method

Spectral Analysis

• Covariance method

• Modified covariance method

All AR methods yield a PSD estimate given by

The different AR methods estimate the AR parameters ap(k) slightlydifferently, yielding different PSD estimates. The following table provides a

summary of the different AR methods.

P A R f ( )1f s----

εp

1 ap k( )e2π j kf – f s ⁄

p

å+

2-------------------------------------------------------------------=

Page 157: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 157/870

3-31

Burg Covariance Modified Covariance Yule-Walker

Characteristics Does not applywindow to data

Does not applywindow to data

Does not applywindow to data

Applies window todata

Mi nimizes theforwardandbackward

prediction errors inthe least squaressense, with the ARcoefficientsconstrained to satisfy

the L-D recursion

Mi nimizes theforward prediction

error in the leastsquares sense

Mi nimizes theforwardandbackward

prediction errors inthe least squaressense

Minimizes theforward prediction

error in the leastsquares sense(also called“Autocorrelationmethod”)

Advantages High resolution forshort data records

Better resolution than Y-W for short datarecords (more

accurate estimates)

High resolution forshort data records

Performs as well asother methods forlarge data records

Always produces astable model

Able to extractfrequencies from dataconsisti ng of p or more

pure sinusoids

Able to extractfrequencies from dataconsisting of p or more

pure sinusoids

Always produces astable model

Does not sufferspectral line-splitting

3 Statistical Signal Processing

Disadvantages Peak locations highlydependent on initialphase

May produce unstablemodels

Mayproduce unstablemodels

Performs relativelypoorly for short datarecords

May suffer spectralline-splitti ng forsinusoids in noise, orwhen order is verylarge

Frequency bias forestimates of sinusoidsin noise

Peak locationsslightly dependent oninitial phase

Frequency bias forestimatesof sinusoidsin noise

Frequency bias forestimates of sinusoids

in noise

Minor frequency biasfor estimates of

sinusoids in noise

Conditions for Order must beless Order must be less Because of the biased

Burg Covariance Modified Covariance Yule-Walker

Page 158: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 158/870

3-32

Yule-Walker AR Method The Yule-Walker AR method of spectral estimation computes the ARparameters by forming a biased estimate of the signal’s autocorrelationfunction, and solving the least squares minimization of the forward predictionerror. This results in the Yule-Walker equations

The use of a biased estimate of the autocorrelation function ensures that theautocorrelation matrix above is positive definite. Hence, the matrix isinvertible and a solution is guaranteed to exist. Moreover, the AR parametersthus computed always result in a stable all-pole model. The Y ule-Walker

equations can be solved efficiently via Levinson’s algorithm, which takesadvantage of the Toeplitz structure of the autocorrelation matrix.

The toolbox function pyul ear implements the Yule-Walker AR method.

Conditions forNonsingularity

Order must belessthan or equal to half the input frame size

Order must be lessthan or equal to 2/3the input frame size

Because of the biasedestimate, theautocorrelationmatrix is guaranteedto positive-defini te,

hencenonsingular

r 1( ) r 2( )*

L r p( )*

r 2( ) r 1( )L

r p 1–( )*

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

a 2( )

a 3( )

a p 1+( )

r 2( )–

r 3( )–

r p 1+( )–

=

Spectral Analysis

For example, compare the spectrum of a speech signal using Welch’s methodand the Yule-Walker AR method.

l oad mt l b

[ P1, f ] = pwel ch( mt l b, hammi ng( 256) , 128, 1024, f s) ;[ P2, f ] = pyul ear ( mt l b, 14, 1024, f s) ;

pl ot ( f , 10* l og10( P1) , ' : ' , f , 10* l og10( P2) ) ; gr i d

yl abel ( ' PSD Est i mat es ( dB/ Hz) ' ) ;

xl abel ( ' Frequency ( Hz) ' ) ;

l egend( ' Wel ch' , ' Yul e- Wal ker AR' )

−20

−10

WelchYule−Walker AR

Page 159: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 159/870

3-33

The solid-line Yule-Walker AR spectrum is smoother than the periodogram

because of the simple underlying all-pole model.

Burg Method

The Burg method for AR spectral estimation i s based on minimizing theforward and backward prediction errors while satisfying the L evinson-Durbinrecursion (see Marple [3], Chapter 7, and Proakis [6], Section 12.3.3). I ncontrast to other AR estimation methods, the Burg method avoids calculatingthe autocorrelation function, and instead estimates the reflection coefficients

directly. The primary advantages of the Burg method are resolving closely spacedsinusoids in signals with low noiselevels, and estimating short data records, in

0 100 200 300 400 500 600−70

−60

−50

−40

−30

P

S D

E s t i m a t e s ( d B / H z )

Frequency (Hz)

3 Statistical Signal Processing

which case the AR power spectral density estimates are very close to the truevalues. I n addition, the Burg method ensures a stable AR model and iscomputationally efficient.

The accuracy of the Burg method is lower for high-order models, long datarecords, and high signal-to-noise ratios (which can cause linesplitting, or thegeneration of extraneous peaks in thespectrum estimate). The spectral densityestimate computed by the Burg method is also susceptible to frequency shifts(relative to the true frequency) resulting from the initial phase of noisysinusoidal signals. This effect is magnified when analyzing short datasequences.

The toolbox function pburg implements the Burg method. Compare thespectrum of the speech signal generated by both the Burg method and the Yule-Walker AR method. They are very similar for large signal lengths.

Page 160: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 160/870

3-34

l oad mt l b

[ P1, f ] = pburg(mt l b( 1: 512) , 14, 1024, f s); % 14t h order model

[ P2, f ] = pyul ear ( mt l b( 1: 512) , 14, 1024, f s) ; % 14t h or der model

pl ot ( f , 10* l og10( P1) , ' : ' , f , 10* l og10( P2) ) ; gr i d

yl abel ( ' Magni t ude ( dB) ' ) ; xl abel ( ' Fr equency ( Hz) ' ) ;

l egend( ' Bur g' , ' Yul e- Wal ker AR' )

0 100 200 300 400 500 600−80

−70

−60

−50

−40

−30

−20

−10

M a g n i t u d e

( d B )

Frequency (Hz)

BurgYule−Walker AR

Spectral Analysis

Compare the spectrum of a noisy signal computed using the Burg method andthe Welch method.

r andn( ' state' , 0)

f s = 1000; % Sampl i ng f r equencyt = (0: f s ) / f s ; % One second wor t h of sampl es

A = [ 1 2] ; % Si nusoi d ampl i t udes

f = [ 150; 140] ; % Si nusoi d f r equenci es

xn = A*si n( 2*pi *f *t ) + 0. 1*r andn( si ze( t ) ) ;

[ P1, f ] = pwel ch( xn, hammi ng( 256) , 128, 1024, f s) ;

[ P2, f ] = pbur g( xn, 14, 1024, f s) ;

pl ot ( f , 10* l og10( P1) , ' : ' , f , 10* l og10( P2) ) ; gr i dyl abel ( ' PSD Est i mat es ( dB/ Hz) ' ) ;

xl abel ( ' Frequency ( Hz) ' ) ;

Page 161: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 161/870

3-35

xl abel ( Frequency ( Hz) ) ;

l egend( ' Wel ch' , ' Bur g' )

Note that, as themodel order for theBurg method is reduced, a frequency shiftdue to the initial phase of the sinusoids will become apparent.

0 100 200 300 400 500 600−60

−50

−40

−30

−20

−10

0

P S D

E s t i m a t e s ( d B / H z )

Frequency (Hz)

WelchBurg

3 Statistical Signal Processing

Covariance and Modified Covariance Methods

The covariance method for AR spectral estimation is based on minimizing theforward prediction error. The modified covariance method is based on

minimizing the forward and backward prediction errors. The toolbox functionspcov and pmcov implement the respective methods.

Compare the spectrum of the speech signal generated by both the covariancemethod and the modified covariance method. They are nearly identical, evenfor a short signal l ength.

l oad mt l b

[ P1, f ] = pcov( mt l b( 1: 64) , 14, 1024, f s) ; % 14t h or der model

[ P2, f ] = pmcov(mt l b( 1: 64) , 14, 1024, f s) ; % 14t h or der modelpl ot ( f , 10* l og10( P1) , ' : ' , f , 10* l og10( P2) ) ; gr i d

yl abel ( ' Magni t ude ( dB) ' ) ; xl abel ( ' Fr equency ( Hz) ' ) ;

Page 162: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 162/870

3-36

l egend( ' Covar i ance' , ' Modi f i ed Covar i ance' )

MUSIC and Eigenvector Analysis Methods

The pmusi c and pei g functions provide two related spectral analysis methods:

• pmusi c provides the multiple signal classification (MU SI C) methoddeveloped by Schmidt

• pei g provides the eigenvector (EV) method developed by J ohnson

See Marple [3] (pgs. 373-378) for a summary of these methods.

0 500 1000 1500 2000 2500 3000 3500 4000−100

−90

−80

−70

−60

−50

−40

M a g n i t u d e ( d B )

Frequency (Hz)

CovarianceModified Covariance

Spectral Analysis

Both of these methods are frequency estimator techniques based oneigenanalysis of the autocorrelation matrix. This type of spectral analysiscategorizes the information in a correlation or data matrix, assigninginformation to either a signal subspace or a noise subspace.

Eigenanalysis Overview

Consider a number of complex sinusoids embedded in white noise. You canwrite the autocorrelation matrix R for this system as the sum of the signalautocorrelation matrix (S) and the noise autocorrelation matrix (W).

There is a close relationship between the eigenvectors of the signalautocorrelation matrix and the signal and noise subspaces. The eigenvectors vof S span thesamesignal subspace asthesignal vectors. I f thesystem contains

R S W+=

Page 163: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 163/870

3-37

p g p g yM complex sinusoids and the order of the autocorrelation matrix is p,eigenvectors vM+1 through vp+1 span the noise subspace of the autocorrelationmatrix.

Frequency Estimator Functions. To generate their frequency estimates,

eigenanalysis methodscalculatefunctionsof thevectors in thesignal andnoisesubspaces. Both the MUSI C and EV techniques choose a function that goes toinfinity (denominator goes to zero) at one of the sinusoidal frequencies in theinput signal. Using digital technology, the resulting estimatehas sharp peaksat the frequencies of interest; this means that there might not be infinityvalues in the vectors.

The MUSI C estimate is given by the formula

where N is thesizeof theeigenvectors and e(f ) is a vector of complex sinusoids.

v represents the eigenvectors of the input signal’s correlation matrix; vk is thekth eigenvector. H is the conjugate transpose operator. The eigenvectors used

Pmusic f ( ) 1

eH f ( ) vkvkH

k p 1+=

N

åè ø

e f ( )

---------------------------------------------------------------- 1

vkH e f ( ) 2

k p 1+=

N

å

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

e f ( ) 1 exp j2πf ( ) exp j2πf 2⋅( ) exp j2πf 4⋅( ) … exp j2πf n 1–( )⋅( )[ ]H=

3 Statistical Signal Processing

in thesumcorrespond to thesmallest eigenvaluesandspan the noise subspace(p is the size of the signal subspace).

The expression is equivalent to a Fourier transform (the vector e(f )

consists of complex exponentials). This form is useful for numeric computationbecausethe FFT can becomputed for each vk andthen thesquared magnitudescan be summed.

The EV method weights the summation by the eigenvalues of the correlationmatrix.

vkH e f ( )

P ev f ( )1

vkH e f ( ) 2

k p 1+=

N

åè ø

λk ⁄

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

Page 164: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 164/870

3-38

The pmusi c and pei g functions in this toolbox use the svd (singular valuedecomposition) function in the signal case and the ei g function for analyzingthe correlation matrix and assigning eigenvectors to the signal or noisesubspaces. When svd is used, pmusi c and pei g never compute the correlationmatrix explicitly, but the singular values are the eigenvalues.

Selected Bibliography

Selected Bibliography

[1] Hayes, M.H. Statistical Digital Signal Processing and Modeling. New York: J ohn Wiley & Sons, 1996.

[2] K ay,S.M. Modern Spectral Estimation. Englewood Cliffs, NJ : PrenticeH all,1988.

[3] Marple, S.L . Digital Spectral Analysis. Englewood Cliffs, NJ : Prentice Hall,1987.

[4] Orfanidis, S.J . I ntroduction to Si gnal Processing. Upper Saddle River, NJ :Prentice Hall, 1996.

[5] Percival, D.B., and A.T. Walden. Spectral Analysis for PhysicalApplications: Multitaper and Conventional UnivariateTechniques. Cambridge:Cambridge University Press 1993

Page 165: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 165/870

3-39

Cambridge University Press, 1993.

[6] Proakis, J .G., and D.G. Manolakis. Digital Si gnal P rocessing: Pr inciples,Algori thms, and Applications. Englewood Cliffs, NJ : Prentice Hall, 1996.

[7] Stoica, P., and R. Moses. I ntroduction to Spectral Analysis. Upper SaddleRiver, NJ : Prentice Hall, 1997.

[8] Welch, P.D. “TheUseof Fast Fourier Transform for theE stimation of PowerSpectra: A Method Based on Time Averaging Over Short, ModifiedPeriodograms.” I EE E Tr ans. Audio E lectroacoust. Vol. AU-15 (J une 1967).Pgs. 70-73.

3 Statistical Signal Processing

Page 166: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 166/870

3-40

4

Special Topics

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

Windows . . . . . . . . . . . . . . . . . . . . . . 4-3Basic Shapes . . . . . . . . . . . . . . . . . . . . 4-3Generalized Cosine Windows . . . . . . . . . . . . . . 4-5

K aiser Window . . . . . . . . . . . . . . . . . . . 4-5Chebyshev Window . . . . . . . . . . . . . . . . . . 4-9

Page 167: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 167/870

Parametric Modeling . . . . . . . . . . . . . . . . 4-11 Time-Domain Based Modeling . . . . . . . . . . . . . 4-13Frequency-Domain Based Modeling . . . . . . . . . . . 4-18

Resampling . . . . . . . . . . . . . . . . . . . . 4-21

Cepstrum Analysis . . . . . . . . . . . . . . . . . 4-24I nverse C omplex Cepstrum . . . . . . . . . . . . . . 4-26

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

Median Filtering . . . . . . . . . . . . . . . . . . 4-29

Communications Applications . . . . . . . . . . . . 4-30

Deconvolution . . . . . . . . . . . . . . . . . . . 4-34

Specialized Transforms . . . . . . . . . . . . . . . 4-35Chirp z-Transform . . . . . . . . . . . . . . . . . . 4-35Discrete C osine Transform . . . . . . . . . . . . . . . 4-37H ilbert Transform . . . . . . . . . . . . . . . . . . 4-39

Selected Bibliography . . . . . . . . . . . . . . . 4-41

4Special Topics

Overview

The Signal Processing Toolbox provides functions that allow you to apply avariety of signal processing techniques. The following sections describehow touse some of these functions:

• “Windows”

• “Parametric Modeli ng”

• “Resampling”

• “Cepstrum Analysis”

• “FFT-Based Time-Frequency Analysis”

• “Median Filtering”

• “Communications Applications”

• “Deconvolution”

Page 168: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 168/870

4-2

• Deconvolution

• “Specialized Transforms”

• “Selected Bi bliography”

Windows

Windows

I n both digital fi lter design and power spectrum estimation, the choice of awindowing function can play an important role in determining the quality of overall results. The main role of the window is to damp out the effects of theGibbs phenomenon that results from truncation of an infinite series.

The toolbox window functions are shown in the table below.

Window Function

Bartlett window bart l et t

Blackman window bl ackman

Chebyshev window chebwi n

Page 169: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 169/870

4-3

Basic Shapes The basic window is therectangular window, a vector of ones of theappropriate

length. A rectangular window of length 50 isn = 50;

w = boxcar ( n) ;

This toolbox stores windows in column vectors by convention, soan equivalentexpression is

w = ones( 50, 1) ;

The Bartlett (or triangular) window is the convolution of two rectangularwindows. The functions bart l et t and t r i ang compute similar triangularwindows, with threeimportant differences. The bart l et t function always

Hamming window hammi ng

Hann window hann

K aiser window kai ser

Rectangular window boxcar

Triangular window t r i ang

4Special Topics

returns a window with two zeros on theends of thesequence, so that for n odd,the center section of bar t l et t ( n+2) is equivalent to t r i ang( n) .

bart l et t ( 7)

ans =

0

0. 3333

0. 6667

1. 0000

0. 6667

0. 3333

0

t ri ang( 5)

ans

Page 170: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 170/870

4-4

ans =

0. 3333

0. 6667

1. 0000

0. 66670. 3333

For n even, bart l et t is stil l the convolution of two rectangular sequences. There is nostandard definition for the triangular window for n even; the slopesof the line segments of the t r i ang result are slightly steeper than those of bart l et t in this case.

w = bar t l et t ( 8) ;

[ w( 2: 7) t r i ang( 6) ]

ans =

0. 2857 0. 1667

0. 5714 0. 5000

0. 8571 0. 8333

0. 8571 0. 8333

0. 5714 0. 5000

0. 2857 0. 1667

The final difference between theBartlett and triangular windows is evident inthe Fourier transforms of thesefunctions. The Fourier transform of a Bartlett

Windows

window is negative for n even. The Fourier transform of a triangular window,however, is always nonnegative.

This difference can beimportant when choosing a window for some spectral

estimation techniques, such astheBlackman-Tukeymethod. Blackman-Tukeyforms the spectral estimate by calculating the Fourier transform of theautocorrelation sequence. The resulting estimate might be negative at somefrequencies if the window’s Fourier transform is negative (see K ay [1], pg. 80).

Generalized Cosine WindowsBlackman, Hamming, Hann, and rectangular windows are all special cases of the general ized cosine window. Thesewindows are combinations of sinusoidalsequences with frequencies 0, , and , where N is thewindow length. One way to generate them is

i nd = ( 0: n- 1) ' *2*pi / ( n- 1) ;

2π N 1–( ) ⁄ 4π N 1–( ) ⁄

Page 171: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 171/870

4-5

p

w = A - B*cos( i nd) + C*cos( 2*i nd) ;

where A, B, and C are constants you define. The concept behind these windowsis that by summing thei ndividual terms toform thewindow, thelow frequencypeaks in the frequency domain combine in such a way as to decrease sidelobeheight. This has the side effect of increasing the mainlobe width.

The Hamming and Hann windows are two-term generalized cosine windows,given by A =0. 54, B =0. 46 for H amming and A =0. 5, B =0. 5 for Hann (C =0

in both cases). The hammi ng and hann functions, respectively, compute thesewindows.

Note that the definition of the generalized cosine window shown in the earlierMATL AB code yields zeros at samples 1 and n for A =0. 5 and B =0. 5.

The Blackman window is a popular three-term window, given by A =0. 42,B =0. 5, C =0. 08. The bl ackman function computes this window.

Kaiser Window The Kaiser window is an approximation to the prolate-spheroidal window, forwhich theratioof themainlobe energytothesidelobe energyis maximized. Fora K aiser window of a particular length, the parameter β controls the sidelobeheight. For a given β, thesidelobeheight is fixed with respect towindow length. The statement kai ser ( n, bet a) computes a length n K aiser window withparameter beta.

4 Special Topics

Examples of K aiser windows with length 50 and various values for thebeta

parameter are

n = 50;

w1 = kai ser ( n, 1) ;w2 = kai ser ( n, 4) ;

w3 = kai ser ( n, 9) ;

[ W1, f ] = f r eqz( w1/ sum( w1) , 1, 512, 2) ;

[ W2, f ] = f r eqz( w2/ sum( w2) , 1, 512, 2) ;

[ W3, f ] = f r eqz( w3/ sum( w3) , 1, 512, 2) ;

pl ot ( f , 20*l og10( abs( [ W1 W2 W3] ) ) ) ; gr i d;

l egend( ' bet a = 1' , ' bet a = 4' , ' bet a = 9' , 3)

t i t l e( ' Thr ee Kai ser Wi ndow Responses' )xl abel ( ' Nor mal i zed Fr equency ( Nyqui st = 1) ' )

yl abel ( ' Nor mal i zed Magni t ude (dB) ' )

Page 172: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 172/870

4-6

As β increases, the sidelobeheight decreases andthe mainlobewidth increases. To see how the sidelobe height stays the same for a fixed β parameter as thelength is varied, try

w1 = kai ser ( 50, 4) ;

w2 = kai ser ( 20, 4) ;w3 = kai ser ( 101, 4) ;

[ W1, f ] = f r eqz( w1/ sum( w1) , 1, 512, 2) ;

[ W2, f ] = f r eqz( w2/ sum( w2) , 1, 512, 2) ;

0 0.2 0.4 0.6 0.8 1−180

−160

−140

−120

−100

−80

−60

−40

−20

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

Windows

[ W3, f ] = f r eqz( w3/ sum( w3) , 1, 512, 2) ;

pl ot ( f , 20*l og10( abs( [ W1 W2 W3] ) ) ) ; gr i d;

l egend( ' l engt h = 50' , ' l engt h = 20' , ' l engt h = 101' )

t i t l e( ' Thr ee Kai ser Wi ndow Responses, Bet a Fi xed' )

xl abel ( ' Nor mal i zed Fr equency ( Nyqui st = 1) ' )yl abel ( ' Nor mal i zed Magni t ude (dB) ' )

−60

−40

−20

0

20Three Kaiser Window Responses, Beta Fixed

z e d M a g n i t u d e (

d B )

length = 50length = 20length = 101

Page 173: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 173/870

4-7

Kaiser Windows in FIR Design

There are two design formulas that can help you design F I R filters to meet aset of filter specifications using a K aiser window. To achieve a sidelobe heightof −α dB, the bet a parameter is

For a transition width of ∆ω rad/s, use the length

Filters designed using these heuristics will meet the specificationsapproximately, but you should verify this. To design a lowpass filter with cutoff

0 0.2 0.4 0.6 0.8 1−120

−100

−80

Normalized Frequency (Nyquist = 1)

N o r m a l i z

β

0.1102 α 8.7–( ), α 50>

0.5842 α 21–( )0.4 0.07886 α 21–( )+ , 50 α 21≥ ≥

0, α 21<î

=

nα 8–

2.285 ω∆----------------------- 1+=

4 Special Topics

frequency rad/s, transition width rad/s, and 40 dB of attenuation inthe stopband, try

[ n, wn, bet a] = kai ser or d( [ 0. 4 0. 6] *pi , [ 1 0] , [ 0. 01 0. 01] , 2*pi ) ;

h = f i r 1( n, wn, kai ser ( n+1, bet a) , ' noscal e' ) ;

The kai ser or d function estimates thefil ter order, cutoff frequency, andK aiserwindow beta parameter needed to meet a given set of frequency domainspecifications.

The ripple in the passband is roughly the same as the ripple in the stopband.As you can see from the frequency response, this filter nearly meets thespecifications.

[ H, f ] = f r eqz( h, 1, 512, 2) ;

pl ot ( f , 20*l og10( abs( H) ) ) , gr i d

0.5π 0.2π

FIR Design using Kaiser Window

Page 174: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 174/870

4-8

For details on kai ser or d, see the description in Chapter 7, “FunctionReference.”

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

-80

-60

-40

-20

0

20

Normalized Frequency (Nyquist == 1)

M a g n i t u d e ( d B )

FIR Design using Kaiser Window

0.240 dB

Windows

Chebyshev Window The Chebyshev window minimizes the mainlobe width, given a particularsidelobe height. I t is characterized by an equiripple behavior, that is, its

sidelobes all have the same height. The chebwi n function, with length andsidelobe height parameters, computes a Chebyshev window.

n = 51;

Rs = 40; % Si del obe hei ght i n deci bel s

w = chebwi n(n, Rs) ;

st em( w) ; t i t l e( ' Lengt h 51 Chebyshev Wi ndow' ) ;

xl abel ( ' Sampl e Number' ) ;

0.6

0.8

1Length 51 Chebyshev Window

Page 175: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 175/870

4-9

As shown in the plot, the Chebyshev window has large spikes at its outersamples. Plot the frequency response to see the equiripples at -40 dB.

[ W, f ] = f r eqz( w, 1, 512, 2) ;

pl ot ( f , 20*l og10( abs( W) / sum( w) ) ) , gr i d

t i t l e( ' Chebyshev Wi ndow Magni t ude Response' ) ;

xl abel ( ' Nor mal i zed Frequency (Nyqui st = 1) ' ) ;

yl abel ( ' Nor mal i zed Magni t ude ( dB) ' ) ;

0 5 10 15 20 25 30 35 40 45 500

0.2

0.4

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

4 Special Topics

For a detailed discussion of the characteristics and applications of the variouswindow types, see Oppenheim and Schafer [2], pgs. 444-462, and Parks andBurrus [3], pgs. 71-73.

Page 176: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 176/870

4-10

Parametric Modeling

Parametric Modeling

Parametricmodeli ngtechniques find the parameters for a mathematical modeldescribing a signal, system, or process. These techniques use known

information about the system to determine the model. Applications forparametric modeli ng include speech and music synthesis, data compression,high-resolution spectral estimation, communications, manufacturing, andsimulation.

The toolbox parametric modeling functions operate with the rational transferfunction model. Given appropri ate information about an unknown system(impulse or frequency response data, or input and output sequences), these

functions find the coefficients of a linear system that models the system.One important application of the parametri c modeli ng functions is in thedesign of filters that have a prescribed time or frequency response. Thesefunctions provide a data-oriented alternative to the I I R and F I R filter designf ti di d i Ch t 2 “Filt D i ”

Page 177: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 177/870

4-11

functions discussed in Chapter 2, “Filter Design.”

4 Special Topics

Here is a summary of the parametric modeling functions in this toolbox. Notethat the System I dentification T oolbox provides a more extensive collection of parametric modeli ng functions.

Domain Functions Description

Time arbur g Generate all-pole filter coefficients that model an input datasequence using the L evinson-Durbin algorithm.

arcov Generate all-pole filter coefficients that model an input datasequence by minimizing the forward prediction error.

ar mcov Generate all-pole filter coefficients that model an input datasequence by minimizing the forward and backward predictionerrors.

ar yul e Generate all-pole filter coefficients that model an input data

Page 178: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 178/870

4-12

Because yul ewal k is geared explicitly toward ARM A filter design, it isdiscussed in Chapter 2, “F ilter Design.”pburg and pyul ear are discussed inChapter 3, “Statistical Signal Processing,”along with the other(nonparametric) spectral estimation methods.

sequence using an estimate of the autocorrelation function.

l pc,l evi nson

Linear Predictive Coding. Generate all-pole recursive filter whoseimpulse response matches a given sequence.

prony Generate I I R filter whose impulse response matches a given

sequence.

st mcb Find I I R filter whose output, given a specifi ed input sequence,matches a given output sequence.

Frequency i nvf r eqz,i nvf r eqs

Generate digital or analog filter coefficients given complexfrequency response data.

Parametric Modeling

Time-Domain Based Modeling The l pc, prony, and st mcb functions find the coefficients of a digital rationaltransfer function that approximates a given time-domain impulse response.

The algorithms differ in complexity and accuracy of the resulting model.

Linear Prediction

Linear prediction modeling assumes that each output sample of a signal, x(k) ,is a linear combination of the past n outputs (that i s, it can be “linearlypredicted” from these outputs), and that the coefficients are constant fromsample to sample.

An nth-order all-pole model of a signal x is

a = l pc( x, n)

To illustrate l pc create a sample signal that is the impulse response of an

x k( ) a 2( )x k 1–( )– a 3( )x k 2–( )– …– a n 1+( )x k n–( )–=

Page 179: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 179/870

4-13

To il lustrate l pc, create a sample signal that is the impulse response of anall-pole filter with additive white noise.

r andn( ' state' , 0) ;

x = i mpz( 1, [ 1 0. 1 0. 1 0. 1 0. 1] , 10) + r andn( 10, 1) / 10;

The coefficients for a fourth-order all-pole filter that models the system are

a = l pc( x, 4)

a =

1. 0000 0. 2574 0. 1666 0. 1203 0. 2598

l pc first calls xcor r to find a biased estimate of the correlation function of x,

and then uses the L evinson-Durbin recursion, implemented in the l evi nsonfunction, to find the model coefficients a. The L evinson-Durbin recursion is afast algorithm for solving a system of symmetric Toeplitz linear equations.l pc’s entire algorithm for n =4 is

r = xcor r ( x) ;

r ( 1: l ength(x) - 1) = [ ] ; % Remove cor r . at negat i ve l ags

a = l evi nson( r , 4)

a =1. 0000 0. 2574 0. 1666 0. 1203 0. 2598

4 Special Topics

You could form the linear prediction coefficients with other assumptions bypassing a different correlation estimate to l evi nson, such as the biasedcorrelation estimate.

r = xcor r ( x, ' bi ased' ) ;r ( 1: l ength(x ) - 1) = [ ] ; % Remove cor r . at negat i ve l ags

a = l evi nson( r , 4)

a =

1. 0000 0. 2574 0. 1666 0. 1203 0. 2598

Prony’s Method (ARMA Modeling)

The prony function models a signal usinga specified number of polesandzeros.Given a sequencex and numerator and denominator orders nb and na,respectively, the statement

[ b, a] = pr ony(x, nb, na)

Page 180: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 180/870

4-14

finds the numerator and denominator coefficients of an I I R filter whoseimpulse response approximates the sequence x.

The prony function implements the method described in [3] Parks and Burrus

(pgs. 226-228). This method uses a variation of the covariance method of ARmodeling to find the denominator coefficients a, and then finds thenumeratorcoefficients b for which the resulting filter’s impulse responsematches exactlythe first nb +1 samples of x. The filter is not necessarily stable, but it canpotentially recover the coefficients exactly if the data sequence is truly anautoregressive moving average (ARMA) process of the correct order.

Note The functions prony and st mcb (descri bed next) are more accuratelydescribed as ARX models in system identification terminology. ARMAmodeling assumes noise only at the inputs, while ARX assumes an externalinput. prony and st mcb know the input signal: it is an impulse for prony andis arbitrary for st mcb.

Parametric Modeling

A model for the test sequencex (from the earlier l pc example) using athird-order IIR filter is

[ b, a] = pr ony(x, 3, 3)

b =0. 9567 - 0. 3351 0. 1866 - 0. 3782

a =

1. 0000 - 0. 0716 0. 2560 - 0. 2752

The i mpz command shows how well this filter’s impulse responsematches theoriginal sequence.

f ormat l ong[ x i mpz( b, a, 10) ]

ans =

0 95674351884718 0 95674351884718

Page 181: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 181/870

4-15

0. 95674351884718 0. 95674351884718

- 0. 26655843782381 - 0. 26655843782381

- 0. 07746676935252 - 0. 07746676935252

- 0. 05223235796415 - 0. 05223235796415

- 0. 18754713506815 - 0. 057267770151210. 15348154656430 - 0. 01204969926150

0. 13986742016521 - 0. 00057632797226

0. 00609257234067 - 0. 01271681570687

0. 03349954614087 - 0. 00407967053863

0. 01086719328209 0. 00280486049427

Notice that the first four samples match exactly. For an example of exact

recovery, recover the coefficients of a Butterworth filter from its impulseresponse.

[ b, a] = but t er ( 4, . 2) ;

h = i mpz( b, a, 26) ;

[ bb, aa] = pr ony(h, 4, 4) ;

Try this example; you’ll see that bb and aa match the original filter coefficientsto within a tolerance of 10-13.

4 Special Topics

Steiglitz-McBride Method (ARMA Modeling)

The st mcb function determines the coefficients for the system b(z)/a(z) given anapproximate impulse response x, as well as the desired number of zeros andpoles. This function identifies an unknown system based on both input and

output sequences that descri be the system’s behavior, or just the impulseresponse of the system. I n its default mode, st mcb works like prony.

[ b, a] = st mcb( x, 3, 3)

b =

0. 9567 - 0. 5181 0. 5702 - 0. 5471

a =

1. 0000 - 0. 2384 0. 5234 - 0. 3065

st mcb also finds systems that match given input and output sequences.

y = f i l t er ( 1, [ 1 1] , x); % Cr eat e an out put si gnal .

[ b, a] = st mcb( y, x, 0, 1)

Page 182: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 182/870

4-16

y

b =

1. 0000

a =

1 1

I n this example, st mcb correctly identifies the system used to create y from x.

The Steiglitz-McBride method is a fast iterative algorithm that solves for thenumerator and denominator coefficients simultaneously in an attempt tominimize the signal error between the fil ter output and the given outputsignal. This algorithm usually converges rapidly, but might not convergeif themodel order is too large. As for prony, st mcb’s resulting filter is not necessarilystable due to its exact modeling approach.

st mcb provides control over several important algorithmic parameters; modifythese parameters if you are having trouble modeling the data. To change thenumber of iterations from thedefault of fiveand providean initial estimate forthe denominator coefficients

n = 10; % Number of i t erat i ons

a = l pc( x, 3) ; % I ni t i al est i mat es f or denomi nat or

[ b, a] = st mcb( x, 3, 3, n, a) ;

Parametric Modeling

The function uses an all-pole model created with prony as an initial estimatewhen you do not provide one of your own.

To compare the functions l pc, prony, and st mcb, compute the signal error in

each case.a1 = l pc( x, 3) ;

[ b2, a2] = pr ony(x, 3, 3) ;

[ b3, a3] = st mcb( x, 3, 3) ;

[ x- i mpz( 1, a1, 10) x- i mpz( b2, a2, 10) x- i mpz( b3, a3, 10) ]

ans =

- 0. 0433 0 - 0. 0000

- 0. 0240 0 0. 0234- 0. 0040 0 - 0. 0778

- 0. 0448 - 0. 0000 0. 0498

- 0. 2130 - 0. 1303 - 0. 0742

0. 1545 0. 1655 0. 1270

Page 183: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 183/870

4-17

0. 1426 0. 1404 0. 1055

0. 0068 0. 0188 0. 0465

0. 0329 0. 0376 0. 0530

0. 0108 0. 0081 - 0. 0162

sum( ans. 2)

ans =

0. 0953 0. 0659 0. 0471

I n comparing modeling capabilities for a given order I I R model, the last result

shows that for this example, st mcb performs best, followed by prony, then l pc. This relative performance is typical of the modeling functions.

4 Special Topics

Frequency-Domain Based Modeling The i nvf r eqs and i nvf r eqz functions implement the inverse operations of f r eqs and f r eqz; they find an analog or digital transfer function of a specifiedorder that matches a given complex frequency response. Though the followingexamples demonstrate i nvf r eqz, the discussion also applies to i nvf r eqs.

To recover the original filter coefficients from the frequency response of asimple digital filter

[ b, a] = but t er ( 4, 0. 4) % Desi gn But t er wort h l owpass

b =

0. 0466 0. 1863 0. 2795 0. 1863 0. 0466

a =

1. 0000 - 0. 7821 0. 6800 - 0. 1827 0. 0301

[ h, w] = f r eqz( b, a, 64) ; % Comput e f r equency r esponse

[ bb, aa] = i nvf r eqz( h, w, 4, 4) % Model : nb = 4, na = 4

Page 184: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 184/870

4-18

bb =

0. 0466 0. 1863 0. 2795 0. 1863 0. 0466

aa =

1. 0000 - 0. 7821 0. 6800 - 0. 1827 0. 0301

The vector of frequencies whas the units in rad/sample, and the frequenciesneed not be equall y spaced. i nvf r eqz finds a filter of any order to fit thefrequency data; a third-order example is

[ bb, aa] = i nvf r eqz(h, w, 3, 3) % Fi nd t hi rd- or der I I R

bb =

0. 0464 0. 1785 0. 2446 0. 1276

aa =

1. 0000 - 0. 9502 0. 7382 - 0. 2006

Both i nvf r eqs and i nvf r eqz design filters with real coefficients; for a datapoint at positivefrequency f , thefunctions fit thefrequency response at both f

and - f .

Parametric Modeling

By default i nvf r eqz uses an equation error method to identify the best modelfrom the data. This finds b and a in

by creating a system of linear equations and solving them with MAT LAB’s \

operator. Here A(w(k)) and B(w(k)) are the Fourier transforms of thepolynomials a and b respectively at the frequency w(k), and n is the number of frequency points (thelength of h and w). wt(k) weights theerror relative to theerror at different frequencies. The syntax

i nvf r eqz( h, w, nb, na, wt )

includes a weighting vector. I n this mode, the filter resulting from i nvf r eqz isnot guaranteed to be stable.

i nvf r eqz provides a superior (“output-error”) algorithm that solves the direct

minb a, wt k( ) h k( )A w k( )( ) B w k( )( )– 2

k 1=

n

å

Page 185: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 185/870

4-19

problem of minimizing the weighted sum of the squared error between theactual frequency response points and the desired response

To use this algorithm, specify a parameter for the iteration count after theweight vector parameter

wt = ones( si ze(w) ) ; % Cr eat e uni t y wei ght i ng vect or

[ bbb, aaa] = i nvf r eqz( h, w, 3, 3, wt , 30) % 30 i t er at i ons

bbb =

0. 0464 0. 1829 0. 2572 0. 1549

aaa =

1. 0000 - 0. 8664 0. 6630 - 0. 1614

The resulting filter i s always stable.

minb a,

wt k( ) h k( )B w k( )( )

A w k( )( )--------------------–

2

k 1=

n

å

4 Special Topics

Graphically compare the results of the first and second algorithms to theoriginal Butterworth filter.

[ H1, w] = f r eqz( b, a) ;

[ H2] = f r eqz( bb, aa) ;

[ H3] = f r eqz( bbb, aaa) ;

s. pl ot = ' mag' ;

s. xuni t s = ' r ad/ sampl e' ;

s . yuni t s = ' l i near ' ;

f r eqzpl ot ( [ H1 H2 H3] , w) ;

l egend( ' Ori gi nal ' , ' F i rst Est i mat e' , ' Second Est i mat e' , 3) ;

gr i d on

−200

−100

0

100

M a g n i t u d e ( d B )

OriginalFirst Estimate

Page 186: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 186/870

4-20

To verify the superiority of the fit numerically, typesum( abs( h- f r eqz( bb, aa, w) ) . 2) % Tot al er r or , al gor i t hm 1

ans =

0. 0200

sum( abs( h- f r eqz( bbb, aaa, w) ) . 2) % Tot al er r or , al gor i t hm 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

Normalized Frequency (×π rad/sample)

Second Estimate

Resampling

Resampling

The toolbox provides a number of functions that resample a signal at a higheror lower rate.

Operation Function

Apply F I R filter with resampling upf i r dn

Cubic spline interpolation spl i ne

Decimation deci mat e

I nterpolation i nterp

Other 1-D interpolation i nt er p1

Resample at new rate r esampl e

Page 187: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 187/870

4-21

The r esampl e function changes the sampling rate for a sequence to any ratethat is a ratio of two integers. The basic syntax for r esampl e is

y = r esampl e(x, p, q)

where the function resamples the sequence x at p/ q times the originalsampling rate. The length of the result y is p/ q times the length of x.

One resampling application is the conversion of digitized audio signals fromone sampling rate to another, such as from 48 kHz (the digital audio tapestandard) to 44.1 kHz (the compact disc standard). I n the next example, thesampling rates are different but the idea is the same.

The example file contains a length 4001 vector of speech sampled at 7418 Hz.

cl ear

l oad mt l b

whos

Name Si ze Byt es Cl ass

Fs 1x1 8 doubl e ar r ay

mt l b 4001x1 32008 doubl e ar r ay

Gr and t otal i s 4002 el ement s usi ng 32016 byt es

4 Special Topics

Fs

Fs =

7418

To play this speech signal on a workstation that can only play sound at8192 Hz, use the r at function to find integers p and q that yield the correctresampling factor.

[ p, q] = r at ( 8192/ Fs, 0. 0001)

p =

127

q =

115

Since p/ q*Fs = 8192. 05 Hz, the tolerance of 0.0001 is acceptable; to resamplethe signal at very close to 8192 Hz.

y = r esampl e(mt l b, p, q) ;

Page 188: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 188/870

4-22

r esampl e applies a lowpass filter to the input sequence to prevent aliasingduring resampling. I t designs this filter using thef i r l s function with a K aiser

window. The syntax

r esampl e( x, p, q, l , bet a)

controls the filter’s length and the beta parameter of the K aiser window.Alternatively, use the function i nt f i l t to design an interpolation filter b anduse it with

r esampl e( x, p, q, b)

The deci mat e and i nterp functions dothesame thing as r esampl e with p =1

and q =1, respectively. These functions provide different anti-alias filteringoptions, and they incur a slight signal delay due to filtering. The i nt erp

function is significantly less efficient than the r esampl e function with q =1.

The toolbox also contains a function, upf i r dn, that applies an F I R filter to aninput sequence and outputs the filtered sequence at a different sample ratethan its original rate. See “Multirate Filter Bank I mplementation” on page

1-20 and the description of upf i r dn in Chapter 7, “Function Reference,” formore details.

Resampling

The standard MA TL AB environment contains a function, spl i ne, that workswith irregularly spaced data. The MA TL AB function i nt erp1 performsinterpolation, or table lookup, using various methods including linear andcubic interpolation. See the MAT L AB documentation for information on

spl i ne and i nt er p1.

Page 189: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 189/870

4-23

4 Special Topics

Cepstrum Analysis

Cepstrum analysis is a nonlinear signal processing techniquewith a variety of applications in areas such as speech and image processing. The Signal

Processing Toolbox provides three functions for cepstrum analysis.

The complex cepstrum for a sequence x is calculated by finding the complexnatural logarithm of the Fourier transform of x, then the inverse Fouriertransform of the resulting sequence.

Operation Function

Complex cepstrum cceps

I nverse complex cepstrum i cceps

Real cepstrum r ceps

π

Page 190: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 190/870

4-24

The toolbox function cceps performs this operation, estimating the complexcepstrum for an input sequence. I t returns a real sequence thesame sizeas theinput sequence.

xhat = cceps( x)

The complex cepstrum transformation is central to the theory and applicationof homomorphic systems, that is, systems that obey certain general rules of

superposition. See Oppenheim and Schafer [2] for a discussion of the complexcepstrum andhomomorphictransformations, with details on speech processingapplications.

Try using cceps in an echo detection application. F irst, create a 45 Hz sinewave sampled at 100 Hz.

t = 0: 0. 01: 1. 27;

s1 = si n( 2*pi *45*t ) ;

x1

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

π–

π

ò =

Cepstrum Analysis

Add an echo of the signal, with half the amplitude, 0.2 seconds after thebeginning of the signal.

s2 = s1 + 0. 5*[ zeros( 1, 20) s1(1: 108) ] ;

The complex cepstrum of this new signal is

c = cceps( s2) ;

pl ot ( t , c)

0 5

0

0.5

1

Page 191: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 191/870

4-25

Note that the complex cepstrum shows a peak at 0.2 seconds, indicating theecho.

The real cepstrum of a signal x, sometimes called simply the cepstrum, iscalculated by determining the natural logarithm of magnitude of the Fouriertransform of x, then obtaining the inverse Fourier transform of the resultingsequence.

0 0.2 0.4 0.6 0.8 1 1.2 1.4-1.5

-1

-0.5

cx1

2π------ X e j ω( )log e j ωn ωd

π–

π

ò =

4 Special Topics

The toolbox function r ceps performs this operation, returning the realcepstrum for a sequence x. The returned sequence is a real-valued vector thesame size as the input vector.

y = r ceps( x)

By definition, you cannot reconstruct the original sequence from its realcepstrum transformation, as the real cepstrum is based only on the magnitudeof theF ourier transform for thesequence(seeOppenheim andSchafer [2]).Ther ceps function, however, can reconstruct a minimum-phase version of theoriginal sequence by applying a windowing function in the cepstral domain. Toobtain both the real cepstrum and the minimum phase reconstruction for asequence, use

[ y, ym] = r ceps( x)

where y is the real cepstrum and ymis the minimum phase reconstruction of x.

Inverse Complex CepstrumTo invert the complex cepstrum use the i function I nversion is

Page 192: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 192/870

4-26

To invert the complex cepstrum, use the i cceps function. I nversion iscomplicated by the fact that the cceps function performs a data dependent

phase modification so that the unwrapped phase of its input is continuous atzero frequency. The phase modification is equivalent to an integer delay. Thisdelay term is returned by cceps if you ask for a second output. For example,

x = 1: 10;

[ xh, nd] = cceps( x)

xh =

Col umns 1 t hr ough 7

2. 2428 - 0. 0420 - 0. 0210 0. 0045 0. 0366 0. 0788 0. 1386Col umns 8 t hr ough 10

0. 2327 0. 4114 0. 9249

nd =

1

Cepstrum Analysis

To invert the complex cepstrum, use i cceps with the original delay parameter.

i cceps( xh, nd)

ans =

Col umns 1 t hr ough 71. 0000 2. 0000 3. 0000 4. 0000 5. 0000 6. 0000 7. 0000

Col umns 8 t hr ough 10

8. 0000 9. 0000 10. 0000

Note With any modification of the complex cepstrum, the original delay termmay no longer be valid. Usethe i cceps function with care.

Page 193: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 193/870

4-27

4 Special Topics

FFT-Based Time-Frequency Analysis

The Signal P rocessing Toolbox provides a function, specgram, that returns thetime-dependent Fouri er transform for a sequence, or displays this information

as a spectrogram. The time-dependent Fourier transform is the discrete-timeFourier transform for a sequence, computed using a sliding window. This formof the Fourier transform, also known as the short-time Fourier transform(STF T), hasnumerous applications in speech, sonar, andradar processing. Thespectrogram of a sequence is the magnitude of the time-dependent Fouriertransform versus time.

To display the spectrogram of a linear FM signal

f s = 10000;t = 0: 1/ f s: 2;

x = vco( sawt oot h( 2*pi *t , . 75) , [ 0. 1 0. 4] *f s, f s) ;

specgr am( x, 512, f s, kai ser ( 256, 5) , 220)

5000

Page 194: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 194/870

4-28

Notethat the spectrogram display is an image, not a plot.

Time

F r e q u e n c y

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.80

500

1000

1500

2000

2500

3000

3500

4000

4500

5000

Median Filtering

Median Filtering

The function medf i l t 1 implements one-dimensional median filtering, anonlinear technique that applies a sliding window to a sequence. The median

filter replaces thecenter value in thewindow with the median value of all thepoints within the window [4]. I n computing this median, medf i l t 1 assumeszeros beyond the input points.

When the number of elements n in the window is even, medf i l t 1 sorts thenumbers, then takes the average of the (n -1 ) / 2 and (n -1 ) / 2 +1 elements.

Two simple examples with fourth- and third-order median fi lters are

medf i l t 1( [ 4 3 5 2 8 9 1] , 4)

ans =

1. 500 3. 500 3. 500 4. 000 6. 500 5. 000 4. 500

medf i l t 1( [ 4 3 5 2 8 9 1] , 3)

ans =

Page 195: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 195/870

4-29

ans =

3 4 3 5 8 8 1

See the I mage Processing Toolbox User’s Guide for information ontwo-dimensional median filtering.

4 Special Topics

Communications Applications

The toolbox provides three functions for communications simulation.

Modulation varies the amplitude, phase, or frequency of a carrier signal withreference to a message signal. The modul at e function modulates a messagesignal with a specified modulation method.

The basic syntax for the modul at e function is

y = modul at e( x, f c, f s, ' met hod' , opt )

h

Operation Function

Modulation modul at e

Demodulation demod

Voltage controlled oscil lation vco

Page 196: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 196/870

4-30

where:

•x is the message signal.

• f c is the carrier frequency.

• f s is the sampling frequency.

• met hod is a flag for the desired modulation method.

• opt is any additional argument that the method requires. (Not allmodulation methods require an option argument.)

The table below summarizes the modulation methods provided; see thedocumentation for modul at e, demod, and vco for complete details on each.

Method Description

amdsb- sc or am Amplitude modulation, double side-band, suppressedcarrier

amdsb- t c Amplitude modulation, double side-band, transmittedcarrier

Communications Applications

I f the input x is an array rather than a vector, modul at e modulates eachcolumn of the array.

To obtain thetimevector that modul at e uses to compute the modulated signal,specify a second output parameter.

[ y, t ] = modul at e( x, f c, f s, ' met hod' , opt )

amssb Amplitude modulation, single side-band

f mFrequency modulation

pm Phase modulation

pt m Pulse time modulation

pwm Pulse width modulation

qam Quadrature amplitude modulation

Method Description

Page 197: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 197/870

4-31

The demod function performs demodulation, that is, it obtains the original

message signal from the modulated signal. The syntax for demod is

x = demod( y, f c, f s, ' met hod' , opt )

demod uses any of the methods shown for modul at e, but the syntax forquadrature amplitude demodulation requires two output parameters.

[ X1, X2] = demod( y, f c, f s, ' qam' )

I f the input y is an array, demod demodulates all columns.

Try modulating and demodulating a signal. A 50 Hz sine wavesampled at1000 Hz is

t = ( 0: 1/ 1000: 2) ;

x = si n( 2*pi *50*t ) ;

4 Special Topics

With a carrier frequency of 200 Hz, the modulated and demodulated versionsof this signal are

y = modul ate(x, 200, 1000, ' am' ) ;

z = demod( y, 200, 1000, ' am' ) ;

To plot portions of the original, modulated, and demodulated signal

f i gure; pl ot ( t ( 1: 150) , x( 1: 150)) ; t i t l e( ' Or i gi nal Si gnal ' ) ;

f i gure; pl ot ( t ( 1: 150) , y( 1: 150) ) ; t i t l e( ' Modul at ed Si gnal ' ) ;

f i gur e; pl ot ( t ( 1: 150) , z(1: 150) ) ; t i t l e( ' Demodul at ed Si gnal ' ) ;

−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 198: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 198/870

4-32

The voltage controlled oscillator function vco creates a signal that oscillates ata frequency determined by the input vector. The basic syntax for vco is

y = vco( x, f c, f s)

where f c is the carrier frequency and f s is the sampling frequency.

0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16−1

0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16−1

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

Communications Applications

To scale the frequency modulation range, use

y = vco( x, [ Fmi n Fmax] , f s)

I n this case, vco scales the frequency modulation range so values of x on the

interval [ - 1 1] map to oscillations of frequency on [ Fmi n Fmax] .

I f the input x is an array, vco produces an array whose columns oscillateaccording to the columns of x.

See “FFT-Based Time-Frequency Analysis” on page 4-28for an example usingthe vco function.

Page 199: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 199/870

4-33

4 Special Topics

Deconvolution

Deconvolution, or polynomial division, is the inverse operation of convolution.Deconvolution is useful in recovering the input to a known filter, given the

filtered output. This method is very sensitive to noise in the coefficients,however, so use caution in applying it.

The syntax for deconv is

[ q, r ] = deconv(b, a)

where b is the polynomial dividend, a is the divisor, q is the quotient, and r isthe remainder.

To try deconv, first convolve two simple vectors a and b (see Chapter 1, “SignalProcessing Basics,” for a description of the convolution function).

a = [ 1 2 3] ;

b = [ 4 5 6] ;

c = conv( a, b)

c =

Page 200: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 200/870

4-34

4 13 28 27 18

Now use deconv to deconvolve b from c.

[ q, r ] = deconv( c, a)

q =

4 5 6

r =

0 0 0 0 0

See the System I dentification T oolbox User’s Guidefor advanced applicationsof signal deconvolution.

Specialized Transforms

Specialized Transforms

I n addition to the discrete F ourier transform (DFT) described in Chapter 1,“Signal Processing Basics,” the Signal Processing Toolbox and the MA TL AB

environment together provide the following transform functions:• The chirp z-transform (CZT), useful in evaluating the z-transform along

contours other than the unit circle. The chirp z-transform is also moreefficient than the DF T algorithm for the computation of prime-lengthtransforms, and it is useful in computing a subset of the DF T for a sequence.

• The discrete cosine transform (DCT), closely related to the DFT . The DCT’senergy compaction properties are useful for applications like signal coding.

• The Hilbert transform, which facilitates theformation of theanalytic signal. The analytic signal is useful in the area of communications, particularly inbandpass signal processing.

Chirp z -Transform The chirp z-transform, or CZT, computes the z-transform alongspiral contoursin the z plane for an input sequence Unlike the DFT the CZT is not

Page 201: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 201/870

4-35

in the z-plane for an input sequence. Unlike the DFT, the CZT is not

constrained to operate along the unit circle, but can evaluate the z-transformalong contours descri bed by

where A is the complex starting point, W is a complex scalar describing thecomplex ratio between points on the contour, and M is the length of thetransform.

One possible spiral isA = 0. 8*exp( j *pi / 6) ;

W = 0. 995*exp( - j *pi *. 05) ;

M = 91;

z = A*( W. ( - ( 0: M- 1) ) ) ;

zpl ane( [ ] , z. ' )

zl AW l– l 0 … M 1–, ,=,=

4 Special Topics

czt ( x, M, W, A) computes the z-transform of x on these points.

An interestingand useful spiral set is mevenly spaced samples around the unit

-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 202: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 202/870

4-36

An interestingand useful spiral set is mevenly spaced samples around the unit

circle, parameterizedbyA = 1

andW = exp(- j *pi / M)

.Thez

-transform on thiscontour is simply the DFT, obtained by

y = czt ( x)

czt may be faster than the f f t function for computing the DF T of sequenceswith certain odd lengths, particularly long prime-length sequences.

Specialized Transforms

Discrete Cosine Transform The toolbox function dct computes the unitary discrete cosine transform, orDCT, for an input vector or matrix. Mathematically, the unitary DCT of aninput sequence x is

where

The DCT is closely related to the discrete F ourier transform; the DFT isactually one step in the computation of the DCT for a sequence. The DCT,however, has better energy compaction properties, with just a few of the

y k( ) w k( ) x n( )π 2n 1–( ) k 1–( )

2N-------------------------------------------cos

n 1=

å k 1 … N, ,=,=

w k( )

1

N

--------- k 1=,

2N---- 2 k N≤ ≤,

î

=

Page 203: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 203/870

4-37

transform coefficients representing the majority of the energy in the sequence.

The energy compaction properties of the DCT make it useful in applicationssuch as data communications.

The function i dct computes the inverse DCT for an input sequence,reconstructing a signal from a complete or partial set of DCT coefficients. Theinverse discrete cosine transform is

where

x n( ) w n( ) y k( )π 2n 1–( ) k 1–( )

2N

-------------------------------------------cos

k 1=

å n 1 … N, ,=,=

w n( )

1

N--------- n 1=,

2

N

---- 2 n N≤ ≤,

î

=

4 Special Topics

Because of the energy compaction mentioned above, it is possible to reconstructa signal from only a fraction of its DCT coefficients. For example, generate a25 Hz sinusoidal sequence, sampled at 1000 Hz.

t = ( 0: 1/ 999: 1) ;

x = si n( 2*pi *25*t ) ;

Compute the DCT of this sequence and reconstruct thesignal using only thosecomponents with value greater than 0.1 (64 of the original 1000 DCTcoefficients).

y = dct ( x) % Comput e DCT

y2 = f i nd( abs(y) < 0. 9) ; % Use 17 coef f i ci ent s

y( y2) = zeros( s i ze( y2) ) ; % Zero out poi nts < 0. 9

z = i dct ( y) ; %Reconst r uct si gnal usi ng i nver se DCT

Plot the ori ginal and reconstructed sequences.

subpl ot ( 2, 1, 1) ; pl ot ( t , x) ;

t i t l e( ' Or i gi nal Si gnal ' )

subpl ot ( 2, 1, 2) ; pl ot ( t , z) , axi s([ 0 1 - 1 1] )

t i t l e( ' Reconstr ucted Si gnal ' )

Page 204: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 204/870

4-38

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

1Reconstructed Signal

Specialized Transforms

One measure of the accuracy of the reconstruction is

norm( x- z) / norm( x)

that is, the norm of the difference between the original and reconstructed

signals, divided by the norm of the original signal. I n this case, the relativeerror of reconstruction is 0.1443. The reconstructed signal retainsapproximately 85% of the energy in the original signal.

Hilbert Transform The toolbox function hi l bert computes the Hilbert transform for a real inputsequence x and returns a complex result of the same length

y = hi l ber t ( x)

where the real part of y is the original real data and the imaginary part is theactual Hilbert transform.y is sometimes calledtheanalyticsignal, in referenceto the continuous-time analytic signal. A key property of the discrete-timeanalytic signal is that its z-transform is 0 on the lower half of the unit circle.Many applications of the analytic signal are related to this property; forexample, the analytic signal is useful in avoiding aliasing effects for bandpass

Page 205: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 205/870

4-39

sampling operations. The magnitude of the analytic signal is the complexenvelope of the original signal.

The Hilbert transform is related to the actual data by a 90° phase shift; sinesbecome cosines and vice versa. To plot a portion of data (solid line) and itsHilbert transform (dotted line)

t = ( 0: 1/ 1023: 1) ;

x = si n( 2*pi *60*t ) ;

y = hi l ber t ( x) ;

pl ot ( t ( 1: 50) , real ( y( 1: 50) ) ) , hol d on

pl ot ( t ( 1: 50) , i mag( y( 1: 50) ) , ' : ' ) , hol d of f

4 Special Topics

The analytic signal is useful in calculating instantaneous attributes of a timeseries, the attributes of the series at any point in time. The instantaneousamplitude of the input sequence is the amplitude of the analytic signal. Theinstantaneous phase angle of the input sequence is the (unwrapped) angl e of

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 206: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 206/870

4-40

instantaneous phase angle of the input sequence is the (unwrapped) angl e of

the analytic signal; the instantaneous frequency is the time rate of change of the instantaneous phaseangle. You can calculate the instantaneous frequencyusing di f f , as described in the MATL AB documentation.

Selected Bibliography

Selected Bibliography

[1] K ay,S.M. Modern Spectral Estimation. Englewood Cliffs, NJ : PrenticeH all,1988.

[2] Oppenheim, A.V., and R.W. Schafer. Discrete-TimeSi gnal Processing.Englewood Cliffs, NJ : Prentice Hall, 1989.

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

[4] Pratt,W.K . Digital I mage Processing. New York: J ohn Wiley & Sons, 1991.

Page 207: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 207/870

4-41

4 Special Topics

Page 208: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 208/870

4-42

5

Filter Design and Analysis Tool

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

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

Getting Help . . . . . . . . . . . . . . . . . . . . 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

Page 209: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 209/870

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

Converting the Filter Structure . . . . . . . . . . . 5-14

Importing a Filter Design . . . . . . . . . . . . . . 5-16

Exporting a Filter Design . . . . . . . . . . . . . . 5-19

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

5 Filter Design and Analysis Tool

Overview

You can use the Filter Design and Analysis Tool (FDAT ool) as a convenientalternative to the command line filter design functions. This chapter contains

the following sections, which walk you through a typical filter design sessionusing the FDATool:

• “Opening the Filter Design and Analysis Tool”

• “Getting Help”

• “Choosing a Filter Type”

• “Choosing a Filter Design Method”

• “Setting the Filter Design Specifi cations”

• “Computing the Filter Coefficients”

• “Analyzing the Fi lter”

• “Converting the Filter Structure”

• “I mporting a F ilter Design”

• “Exporting a Filter Design”

• “Saving and Opening Filter Design Sessions”

Page 210: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 210/870

5-2

Below is a brief introduction to the FDAT ool that will give you a betterunderstanding of how it can be used.

Filter Design Methods The tool gives you access to all of the filter design methods in the SignalProcessing Toolbox:

Butterworth (but t er )• Chebyshev type I (cheby1)

• Chebyshev type I I (cheby2)

• Elliptic(el l i p)

• Equiripple (r emez)

• Least squares (f i r l s)

• Windows

- Bartlett (bart l et t , f i r 2)

- Blackman (bl ackman, f i r 2)

- Boxcar (boxcar , f i r 2)

- Chebyshev (chebwi n, f i r 2)

- Hamming (hammi ng, f i r 2)

- Hann (hann, f i r 2)

- Kaiser (kai ser , f i r 1)

- Triangular (t r i ang, f i r 1)

Additional filter design methods are available to users of the Filter Design Toolbox.

Using the Filter Design and Analysis Tool

There aredifferent ways that you can design filters using theF ilter Design andAnalysis Tool. For example:

• You can first choosea filter type, such asbandpass, and then choosefromtheavailable FI R or I I R filter design methods.

• You can specify the filter by its type alone, along with certain frequency- ortime-domain specifications such as passband frequencies and stopbandfrequencies. The filter you design is then computed using the default filter

Page 211: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 211/870

5-3

design method and filter order.

Analyzing Filter ResponsesOnce you have designed your fi lter, you can analyze different filter responses:

• Magnitude response (f r eqz)

• Phase response (f r eqz)

Pole-zero plots (zpl ane)• I mpulse response (i mpz)

• Group delay (gr pdel ay)

• Step response

You can also display the filter coefficients.

Filter Design and Analysis Tool Modes The F ilter Design and Analysis Tool operates in two modes:

5 Filter Design and Analysis Tool

• Design mode. I n this mode, you can:

- Design filters from scratch.

- Modify existing filters designed by FDATool.

- Analyze filters.

• I mport mode. I n this mode, you can:

- I mport previously saved filters or filter coefficients that you havestored inthe MATL AB workspace.

- Analyze imported filters.

There is one more mode available to you if you also have the Filter Design Toolbox: the quantizemode. Use this mode to:

• Quantize double-precision filters that you design in FDATool.

• Quantize double-precision filters that you import into FDATool.

• Analyze quantized filters.

Getting HelpAt any time, you can right-click or press the What’s this? button, , to get

Page 212: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 212/870

5-4

information on the different parts of the GUI .

Opening the Filter Design and Analysis Tool

Opening the Filter Design and Analysis Tool

To open the Filter Design and Analysis Tool, type

f dat ool

The F ilter Design and Analysis Tool opens in the default design mode.

Choose an analysis method foranalyzing the filter design.

Select theWhat’s this? button and click on a regionof the GUI to access context-sensitive help.

Zoomin/out.

Use theFiltermenu to

choose between importing

filter coefficients fromtheMATLAB workspace and

designing the filter in the

GUI.

Quantize the current filter

using the Filter Design

Toolbox.

Page 213: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 213/870

5-5

Choose the type of filter

to design.

Choose the filter design

method to use

PressDesign Filter to

compute the filter

coefficients.

Set quantizationparameters for the Filter

Design Toolbox.

Set filter specifications. These depend on

the type of filter you are designing, as

well as the design method you specify.

Specify a filter order or

allowit to be estimated.

Set windowspecifications

for the FIRWindow

design.

5 Filter Design and Analysis Tool

Getting Help

Use the What’s this? button to find out more information about a particularregion of FDAT ool.

Context-Sensitive Help: The What’s This? Button To find information on a particular region of the GUI :

1 Select the What’s this? button with your mouse.

2 Click on the region of the GUI you want information on.

You can also right-click a region of the GUI or select What’s this? from theHelp menu to launch context-sensiti ve help.

Page 214: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 214/870

5-6

Choosing a Filter Type

Choosing a Filter Type

You can choose from several filter types:

• L owpass

• Highpass

• Bandpass

• Bandstop

• Differentiator

• Hilbert transformer

• Multiband

• Arbitrary magnitude

To design a bandpass filter, select the radio button next to Bandpass in theFilter Type region of the GUI .

Page 215: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 215/870

5-7

Note Not all filter design methods are available for all fi lter types. Once youchoose your filter type, this may restrict the filter design methods available toyou. Fil ter design methods that are not available for a selected filter type aredimmed in the Method menu, and removed from the Design Method regionof the GUI .

You can also use the Type menu to select a filter type.

5 Filter Design and Analysis Tool

Choosing a Filter Design Method

You can use the default filter design method for the filter type that you’veselected,or you can select a filter design method from theavailable F I R and I I Rmethods listed in the GUI .

To select theRemez algorithm tocompute FI R filter coefficients, select theFI R

radio button and choose Equi r i ppl e from the list of methods.

You can also use the Method menu to select a filter design method.

Page 216: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 216/870

5-8

Setting the Filter Design Specifications

Setting the Filter Design Specifications

The filter design specifications that you can set vary according tofilter typeanddesign method. For example, to design a bandpass fil ter, you can enter:

• Frequency specifications

• Magnitude specifications

• Filter order

The display region i llustrates filter specifications when you select Filter

Specifications from the Analysis menu.

Page 217: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 217/870

5-9

Bandpass Filter Frequency SpecificationsFor a bandpass filter, you can set:

• Units of frequency:

- Hz- kH z

- MHz

- Normalized (0 to 1)

• Sampling frequency

• Passband frequencies

• Stopband frequencies

5 Filter Design and Analysis Tool

You specify thepassband with twofrequencies. The first frequency determinesthe lower edgeof the passband, and the second frequency determines the upperedge of the passband.

Similarly, you specify the stopband with two frequencies. The first frequency

determines the upper edge of the first stopband, and the second frequencydetermines the lower edge of the second stopband.

For this example:

• K eep the units in Hz (default).

• Set the sampling frequency (Fs) to 2000 Hz.

• Set the end of the first stopband (Fstop1) to 200 Hz.

Set the beginning of the passband (Fpass1) to 300 Hz.• Set the end of the passband (Fpass2) to 700 Hz.

• Set the beginning of the second stopband (Fstop2) to 800 Hz.

Page 218: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 218/870

5-10

Bandpass Filter Magnitude SpecificationsFor a bandpass filter, you can specify the following magnitude responsecharacteristics:

• Units for the magnitude response (dB or linear)

• Passband ripple

• Stopband attenuation

Setting the Filter Design Specifications

For this example:

• K eep the units in dB (default).

• Set the passband ripple (Apass) to 0. 1 dB.

Set the stopband attenuation for both stopbands (Astop1

,Astop2

) to75

dB.

Filter Order You havetwo mutually exclusiveoptions for determining thefilter order when

you design an equiripple filter:

Page 219: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 219/870

5-11

y g q pp

• Minimum order: The filter design method determines the minimum orderfilter.

• Specify order: You enter the filter order in a text box.

Select the Minimum order radio button for this example.

Note that filter order specification options depend on the filter design methodyou choose. Some filter methods may not have both options available.

5 Filter Design and Analysis Tool

Computing the Filter Coefficients

Now that you’ve specified the filter design, select the Design Filter button tocompute the filter coefficients.

Notice that the Design Filter button is dimmed once you’ve computed thecoefficients for your fil ter design. This button is enabled again once you makeany changes to the filter specifications.

Page 220: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 220/870

5-12

Analyzing the Filter

Analyzing the Filter

Once you’ve designed the filter, you can view the following filter responsecharacteristics in the display region:

• Magnitude response• Phaseresponse

• Overlaid magnitude and phase responses

• Group delay

• I mpulse response

• Step response

Pole-zero plot You can also display the filter coefficients in this region.

You can access the analysis methods as items in the Analysis menu, or byusing the toolbar buttons.

F or example, to look at the filter’s magnitude response, select the Magnitudeb h lb

Page 221: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 221/870

5-13

Response button on the toolbar.

5 Filter Design and Analysis Tool

Converting the Filter Structure

You can usetheConvert structure button toconvert thecurrent filter toa newstructure. All fil ters can be converted to the foll owing representations:

• Di rect f orm I

• Di rect f orm I I

• Di r ect f or m I t r ansposed

• Di r ect f orm I I t r ansposed

• St at e- space

• Lat t i ce ARMA

I n addition, the following conversions are available for particular classes of filters:

• Mi nimum phaseFI R filters can be converted to Lat t i ce MA ( mi n. phase)

• Maximum phase F I R filters can be converted to Lat t i ce MA ( max. phase)

• Allpass filters can be converted to Lat t i ce al l pass

• I I R filters can be converted to Lat t i ce ARMA

When selected, the Use second-order sections check box instructs the tool tostore the converted filter structure as a collection of second order sections

Page 222: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 222/870

5-14

store the converted filter structure as a collection of second-order sectionsrather than as a monolithic higher-order structure. The subordinate Scale

menu lets you select from the following options.

• None (default)

• L- 2 (L 2 norm)

• L- i nf i ni t y (L ∞ norm)

The ordering of the second-order sections is optimized for the selected scalingoption. (The t f 2sos function that performstheconversion is called with option' down' for L 2 norm scaling, and with option ' up' for L ∞ norm scaling.)

For example:

• Press the Convert structure button to open the Convert structure dialog

box.

• Select Di rect f ormI in the list of fi lter structures.

Converting the Filter Structure

• Select the Use second-order sections check box.

• Select L- i nf i ni t y from the Scale menu for L ∞ norm scaling.

Page 223: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 223/870

5-15

5 Filter Design and Analysis Tool

Importing a Filter Design

The Import Filter region allows you to import a filter by specifying the filtercoefficients, either by entering them explicitly or by referring to variables intheM ATL AB workspace. Y ou can accessthis region by selecting Import Filter

from the Filter menu, or by pressing Ctrl+I.

The imported filter can be in any of the representations listed in the Filter

Structure menu, and described in “Filter Structures” below:

• Di rect f orm I

• Di rect f orm I I

• Di r ect f or m I t r ansposed

• Di r ect f orm I I t r ansposed

• Di r ect f or m I I ( Second- or der secti ons)

• St at e- space

• Lat t i ce al l pass

• Lat t i ce MA mi n. phase

• Lat t i ce MA max. phase

•Lat t i ce ARMA

• Quant i zed f i l t er ( Qf i l t obj ect ) — available only when Filter Design

Page 224: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 224/870

5-16

Quant i zed f i l t er ( Qf i l t obj ect ) available only when Filter Design Toolbox is installed

Select thefrequency units fromamongthefollowing options in theUnitsmenu,and specify the value of the sampling frequency in the Fs field.

To import the filter, press the Import Filter button. The Display Region isautomatically updated when the new filter has been imported.

Importing a Filter Design

Filter Structures The structure that you choosedetermines thetypeof coefficients that you needto specify in the text fields to the right:

Direct FormFor Di r ect For mI , Di rect FormI I , Di r ect For mI t ransposed, and Di r ect

For mI I t r ansposed, specify the filter by its transfer function representation:

• The Numerator field specifies a variable name or value for the numerator

coefficient vectorb

, which containsm+1

coefficients in descending powers of z.

• The Denominator field specifies a variable name or value for thedenominator coefficient vector a, which contains n+1 coefficients indescending powers of z. For F I R filters, the Denominator is 1.

F ilters in transfer function form can beproduced by all of theSignal Processing Toolbox filter design functions (e.g., f i r 1, f i r 2, r emez , but t er , yul ewal k). See“Transfer F unction” on page 1-33 for more information.

Direct Form II (Second-Order Sections)

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 225: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 225/870

5-17

For Di r ect f or mI I ( Second- or der sect i ons) , specify the filter by itssecond-order section representation:

The Gain field specifies a variable name or a value for the gain g, and the SOS

Matrix field specifies a variable name or a value for theL -by-6 SOS matrix

H z( ) g H k z( )

k 1=

L

∏ gb0k b1kz 1– b2kz 2–+ +

1 a1kz 1– a2kz 2–+ +----------------------------------------------------------

k 1=

L

∏= =

S OS

b01 b11 b21 1 a11 a21

b02 b12 b22 1 a12 a22

b0L

b1L

b2L

1 a1L

a2L

=

5 Filter Design and Analysis Tool

whose rows contain the numerator and denominator coefficients bik and aik of the second-order sections of H(z).

Filters in second-order section form can be produced by functions such ast f 2sos, zp2sos, ss2sos, and sosf i l t . See “Second-Order Sections (SOS)” on

page 1-38 for more information.

State-Space

For St ate- Space, specify the filter by its state-space representation:

The A, B, C, and D fields each specify a variable name or a value for thematrices in this system.

Filters in state-space form can be produced by functions such as t f 2ss andzp2ss. See “State-Space” on page 1-35 for more information.

Lattice

For Lat t i ce al l pass, Lat t i ce MA, and Lat t i ce ARMA filters, specify the filterby its lattice representation:

• For Lat t i ceal l pass, the Lattice coeff field specifies the lattice (reflection)

x· A x B u+=

y Cx Du+=

Page 226: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 226/870

5-18

pcoefficients, k(1) to k( N) , were N is the filter order.

• For Lat t i ce MA (minimum or maximum phase), the Lattice coeff fieldspecifies the lattice (reflection) coefficients, k(1) to k( N) , were N is the filterorder.

• For Lat t i ce ARMA, the Lattice coeff field specifies the lattice (reflection)

coefficients, k(1) to k( N) , and the Ladder coeff field specifies the laddercoefficients, v(1) to v( N+1) , were N is the filter order.

Filters in lattice form can be produced by t f 2l at c . See “L attice Structure”onpage 1-38 for more information.

Quantized Filter (Qfilt Object)

For Quant i zedf i l t er , specify thefilter as a Qfilt object. Seeqf i l t in theF ilter

Design Toolbox for more information.

Exporting a Filter Design

Exporting a Filter Design

You can save your filter design by:

• Exporting the filter coefficients to the MA TL AB workspace

• Exporting the filter coefficients to a text file

• Exporting the filter coefficients to a MAT-file

To save your filter coefficients to a file or the workspace, select Export underthe File menu.

L et’s export the filter coefficients to the workspace.

Exporting Filter Coefficients to the Workspace To save filter coefficients as variables in the MATL AB workspace:

• Select Export from the File menu. The Export dialog box appears.

• Select Workspace from the Export To menu.

• Assign variable names using the text boxes in the Variable Names region.

• Press the OK button.

Page 227: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 227/870

5-19

5 Filter Design and Analysis Tool

Exporting Filter Coefficients to a Text File To save filter coefficients to a text file:

• Select Export from the File menu. The Export dialog box appears.

• Select Text-file from the Export To menu.

• Press the OK button. The Export Filter Coefficients to a Text-file dialogbox appears.

• Choose a filename and press Save.

The coefficients are saved in the text file that you specified, and the MA TL ABEditor opens to display the file.

Page 228: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 228/870

5-20

Saving and Opening Filter Design Sessions

Saving and Opening Filter Design Sessions

You can save your filter design session as a MAT-file and return to the samesession another time.

Select theSavesession button tosaveyour session as a MAT-file. Thefirsttime you save a session, a Save Filter Design File browser opens, promptingyou for a session name.

For example save this design session as Test Fi l t er f da in your current

Page 229: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 229/870

5-21

For example, save this design session as Test Fi l t er . f da in your currentworking directory by typing Test Fi l t er in the File name field.

The. f d a extension is added automatically to all filter design sessions you save.

Note You can also use the Save session and Save session as menu items in

the File menu to save a session. This dialog opens every time you select theSave As menu item.

You can load existing sessions into the Filter Design and Analysis Tool byselecting the Open session button, . A Load Filter Design File browseropens that allows you to select from your previously saved filter designsessions.

5 Filter Design and Analysis Tool

Page 230: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 230/870

5-22

6

SPTool: A SignalProcessing GUI Suite

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

SPTool: An Interactive Signal Processing Environment 6-3

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

Overview of the Signal Browser: Signal Analysis . . . 6-6

Overview of the Filter Designer: Filter Design . . . . 6-8

Overview of the Filter Viewer: Filter Analysis . . . . 6-11

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

Getting Help . . . . . . . . . . . . . . . . . . . . 6-17

Using SPTool: Filtering and Analysis of Noise . . . . . 6-18

Page 231: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 231/870

Using SPTool: Filtering and Analysis of Noise . . . . . 6 18

Importing a Signal into SPTool . . . . . . . . . . . 6-19

Designing a Filter . . . . . . . . . . . . . . . . . 6-22

Applying a Filter to a Signal . . . . . . . . . . . . . 6-24

Analyzing Signals: Opening the Signal Browser . . . . 6-26

Spectral Analysis in the Spectrum Viewer . . . . . . 6-29

Exporting Signals, Filters, and Spectra . . . . . . . . 6-32

Designing a Filter with the Pole/Zero Editor . . . . . 6-34

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

6 SPTool: A Signal Processing GUI Suite

Overview

SPT ool is a graphical user interface (GUI ) for analyzing and manipulatingdigital signals, filters, and spectra. The first few sections of this chapter givean overview of SPT ool and its associated GUI s:

• “SPTool: An I nteractive Signal Processing Environment”

• “Opening SPTool”

• “Overview of the Signal Browser: Signal Analysis”

• “Overview of the Filter Designer: Filter Design”

• “Overview of the Filter Viewer: Filter Analysis”

• “Overview of the Spectrum Viewer: Spectral Analysis”

• “Getting Help”

The rest of this chapter illustrates in detail how to use the GUI -basedinteractive tools by walking through some examples:

• “Using SPTool: Filtering and Analysis of Noise”

• “I mporting a Signal into SPTool”

• “Designing a Filter”

• “Applying a Filter to a Signal”

• “Analyzing Signals: Opening the Signal Browser”

Page 232: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 232/870

6-2

y g g p g g

• “Spectral Analysis in the Spectrum Viewer”

• “Exporting Signals, Filters, and Spectra”

• “Designing a Filter with thePole/Zero Editor”

• “Redesigning a Filter Using the Magnitude Plot”

• “Accessing F ilter Parameters in a Saved Filter”• “Accessing Parameters in a Saved Spectrum”

• “I mporting Filters and Spectra into SPTool”

• “L oading Variables from the Disk”

• “Selecting Signals, Filters, and Spectra in SPTool”

• “Editing Signals, Filters, or Spectra in SPTool”

“Setting Preferences”• “Making Signal Measurements: Using Markers”

SPTool: An Interactive Signal Processing Environment

SPTool: An Interactive Signal Processing Environment

SPTool is an interactive GUI for digital signal processing that can be used to:

• Analyze signals.

• Design filters.• Analyze (view) filters.

• Filter signals.

• Analyze signal spectra.

You can accomplish these tasks using four GUI s that you access from withinSPTool:

• The Signal Browser is for analyzing signals. You can also play portions of signals using your computer’s audio hardware.

• The Filter Designer is for designing or editing thefollowing types of FI R andI I R digital filters:

- L owpass

- Highpass

- Bandpass

- Bandstop

Most of the Signal Processing Toolbox filter design methods available at the

Page 233: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 233/870

6-3

command lineare also available in theF ilter Designer. Additionally, you candesign a filter by using the Pole-Zero Editor to graphically place poles andzeros on the z-plane.

• The Filter Viewer is for analyzing filter characteristics. You can analyze afilter’s:

- Magnitude response

- Phase response

- Group delay

- Pole/zero plot

- I mpulse response

- Step response

6 SPTool: A Signal Processing GUI Suite

• The Spectrum Vi ewer is for spectral analysis. You can usethe SignalProcessing Toolbox spectral estimation methods to estimate the powerspectral density of a signal.

SPTool Data Structures You can use SPT ool to analyzesignals, filters, or spectra that you createat theMATL AB command line.

You can bring signals, filters, or spectra from theMAT LAB workspace into theSPTool workspace using theImport item under theFile menu. Signals, filters,or spectra that you create in (or import into) the SPTool workspace exist asMAT LAB structures.SeetheM ATL AB documentation for more information onMATLAB structures.

When you usetheExport item under theFile menu tosavesignals, filters, andspectra that you create or modify in SPTool, these are also saved as MATLABstructures.

Page 234: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 234/870

6-4

Opening SPTool

Opening SPTool

To open SP Tool, type

spt ool

The SPT ool interface is shown below.

Open the Filter Viewer to

analyze selected filters.

Open the Filter

Designer

Apply a selected

filter to a selected

Open the Spectrum

Viewer to analyze

selected spectra.

Open the Spectrum

Viewer without

computing a spectral

estimate.

Select one or more items in any

of the three lists for use withmost SPTool operations.

Open the Signal Browser.

Open the Spectrum

Viewer and create thepower spectraldensity estimate of

the selected signal.

Open the Filter

Designer to edit any

Page 235: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 235/870

6-5

When you first open SP Tool, it contains a collection of default signals, filters,and spectra. Y ou can specify your own preferences for what signals, filters, andspectra you want to see when SPTool opens. See “Setting Preferences”on page

6-50 for more details.

You can access four other GUI s from SPT ool:

• Signal Browser from the Signals list View button

• Filter Designer from the Filters list New Design or Edit Design button

• Filter Viewer from the Filters list View button

• Spectrum Viewer from the Spectra list View, Create, or Update button

Designer.signal.selected filters.

6 SPTool: A Signal Processing GUI Suite

Overview of the Signal Browser: Signal Analysis

You can use the Signal Browser to display and analyze signals listed in theSignals list box in SPTool.

Using the Signal Browser you can:• Analyze and compare vector or array (matrix) signals.

• Zoom in on portions of signal data.

• Measure a variety of characteristics of signal data.

• Compare multiple signals.

• Play portions of signal data on audio hardware.

Print signal plots.

Opening the Signal Browser You can open the Signal Browser from SPT ool by:

1 Selecting one or more signals in the Signals list in SPTool

2 Pr essing the View button under the Signals list

The Signal B rowser has the following components:

• A display region for analyzing signals including markers for measuring

Page 236: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 236/870

6-6

• A display region for analyzing signals, including markers for measuring,comparing, or playing signals

• A toolbar providing convenient access to frequently used functions:

- Zoom buttons for getting a closer look at signal features

- A button for printing signal plots

- A button for playing portions of a selected signal through audio equipment

• A “panner” that displays the entire signal length, highlighting the portioncurrently active in the display region

Overview of the Signal Browser: Signal Analysis

Toggle markers on or off

Panner

Display region

Context-sensitive help

Play button foraudio signals

Signal Display

buttons

Print button

Choose the display color and line

style of a selected signal.Select one of several

loaded signals.

Zoombuttons

Page 237: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 237/870

6-7

Marker measurements

6 SPTool: A Signal Processing GUI Suite

Overview of the Filter Designer: Filter Design

The Filter Designer provides an interactive graphical environment for thedesign of digital I I R and FI R filters based on specifications that you enter on amagnitude or pole-zero plot.

Note You can also use the Fi lter Design and Analysis Tool (FDATool)described in Chapter 5, “Filter Design and Analysis Tool,” for filter design andanalysis.

Filter Types You can design fi lters of the following types using the Filter Designer:

• Bandpass

• Lowpass

• Bandstop

• Highpass

FIR Filter Methods You can use the following filter methods to design F I R filters:

Page 238: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 238/870

6-8

• Equiripple

• Least squares

• Window

IIR Filter Methods You can use the following filter methods to design I I R filters:

• Butterworth

• Chebyshev type I

• Chebyshev type I I

• Elliptic

Overview of the Filter Designer: Filter Design

Pole/ Zero Editor You can use the Pole/Zero Editor to design arbitrary FI R and I I R filters byplacing and moving poles and zeros on the complex z-plane.

Spectral Overlay Feature You can also superimposespectra on a filter’s magnitude response to see if thefiltering requirements are met.

Opening the Filter DesignerOpen the Filter Designer from SPT ool by either:

• Pressing the New Design button in the Filters list in SPTool

• Selecting a filter you want to edit from the Filters list in SPTool, and thenpressing the Edit Design button

Zoombuttons Zoomon passbandOverlay existing spectra on top

of filter response.

Page 239: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 239/870

6-9

Automaticdesign checkbox

Specificationsregion for

setting filter parameters

Magnitude response and pole-zero display areaMeasurementsregion displaysfilter characteristics

Apply the specifications,

or revert to the previous

specifications.

6 SPTool: A Signal Processing GUI Suite

The Filter Designer has the following components:

• A menu for selecting filters from the list in SPTool

• A menu for selecting different filter design methods (algorithms)

• A plot display region for graphically adjusting filter magnitude responses

• Measurement lines for measuring the magnitude response parameters of afilter

• A pole-zero plot display region for graphically editing filter designs bymanipulating transfer function poles and zeros

• Zoom buttons for navigating the displays

• A Specifications region for viewing andmodifying the design parameters orpole-zero locations of the current filter

• A Measurements region for viewing the response characteristics andstability of the current filter

Page 240: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 240/870

6-10

Overview of the Filter Viewer: Filter Analysis

Overview of the Filter Viewer: Filter Analysis

You can use theF ilter Viewer to analyzethefollowingresponse characteristicsof selected filters:

Magnitude response• Phaseresponse

• I mpulse response

• Step response

• Group delay

• Pole and zero locations

The Filter Viewer can display up to six different response characteristics plotsfor a selected filter at any time. The F ilter Viewer provides features for:

• Zooming

• Measuri ng filter responses

• Overl aying filter responses

• Modifying display parameters such as frequency ranges or magnitude units

Opening the Filter Viewer You can open the Filter Viewer from SPT ool by:

Page 241: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 241/870

6-11

1 Selecting one or more filters in the Filters list in SPTool

2 Pressing the View button under the Filters list

When you first open theF ilter Viewer, it displaysthedefault plot configurationfor the selected filter(s).

6 SPTool: A Signal Processing GUI Suite

Context-sensitive

help

Plotsregion, includingmenus for modifying

display characteristics

Frequency Axisregion

Filter IDregion

Markersregion

Markerbuttons

Zoombuttons

Line display

preferences buttons

Check up to six boxes

to display different

filter response plots.

Toggle markers

on or off.

Select one of severalloaded signals.

Page 242: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 242/870

6-12

The filters’ magnitude and phase plots are displayed by default. I n addition,the frequency is displayed with a linear scale on the interval [ 0, Fs/ 2] .

The Filter Viewer has the following components:

• A Plots region for selecting the response plots you want to display in thedisplay area, and for specifying some frequency response displaycharacteristics

• A Frequency Axis region for specifying frequency scaling in the display area

• Marker buttons for making filter response measurements and comparisons

• A filter identification region that displays information about the currentlyselected filter(s)

Overview of the Filter Viewer: Filter Analysis

• A display area for analyzing one or more frequency response plots for theselected filter(s)

• Zoom buttons to navigate the displays

Page 243: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 243/870

6-13

6 SPTool: A Signal Processing GUI Suite

Overview of the Spectrum Viewer: Spectral Analysis

You can use the Spectrum Viewer for estimating and analyzing a signal’spower spectral density (PSD). Y ou can use the PSD estimates to understand asignal’s frequency content.

Using the Spectrum Viewer you can:

• Analyze and compare spectral density plots.

• Use different spectral estimation methods to create spectra:

- Burg(pburg)

- Covariance (pcov)

- FFT (f f t )

- Modified covariance (pmcov)

- MTM (multitaper method) (pmt m)

- MUSIC (pmusi c)

- Welch (pwel ch)

- Yule-Walker AR (pyul ear )

• Modify power spectral density parameters such as FFT length, window type,

and sample frequency.• Print spectral plots.

Opening the Spectrum Viewer

Page 244: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 244/870

6-14

Opening the Spectrum Viewer To open the Spectrum Viewer and create a PSD estimatefrom SPT ool:

1 Select a signal from the Signal list box in SP Tool.

2 Press the Create button in the Spectra list.

3 Press the Apply button in the Spectrum Viewer.

To open the Spectrum Viewer with a PSD estimate already listed in SPT ool:

1 Select a PSD estimate from the Spectra list box in SPTool.

2 Press the View button in the Spectra list.

Overview of the Spectrum Viewer: Spectral Analysis

For example:

1 Select mt l b in the default Signals list in SPTool.

2 Press the Create button in SP Tool to open the Spectrum Viewer.

3 Press the Apply button in the Spectrum Viewer to plot the spectrum.

Signal ID Zoombuttons

Parameters

region

Line display buttons Context-sensitive help

Inherit PSD

estimationparameters

fromother

PSDs.

Create ormodify a PSDestimate.

Select one of several

loaded signals.

Page 245: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 245/870

6-15

The Spectrum Viewer has the following components:

• A signal identification region that provides information about the signalwhose power spectral density estimate is displayed

• A Parameters region for modifying the PSD parameters

• A display region for analyzing spectra

• Zoom buttons for navigating plotted spectra

Display region

Discard any

changes.

6 SPTool: A Signal Processing GUI Suite

• Marker buttons and li ne-display buttons for making spectral measurementsand comparisons

• Spectrum management controls:

- Inherit from menu to inherit PSD specifications fromanother PSD objectlisted in the menu

- Revert button to revert to the named PSD’s original specifications

- Apply button for creating or updating PSD estimates

• Menu options for modifying plot display characteristics

• Menu options and buttons for printing PSD plots

Page 246: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 246/870

6-16

Getting Help

Getting Help

Usethe What’s this? button to find out more information about a particularregion of the GUI .

Context-Sensitive Help: The What’s This? Button To find information on a particular region of the Signal Browser, FilterDesigner, Filter Viewer, or Spectrum Viewer:

1 Press the What’s this? button, .

2 Click on the region of the GUI you want information on.

You can also use the What’s this? menu item in the Help menu to launchcontext-sensitive help.

Page 247: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 247/870

6-17

6 SPTool: A Signal Processing GUI Suite

Using SPTool: Filtering and Analysis of Noise

The following sections provide an example of using the GUI -based interactivetools to:

• Design and implement an FI R bandpass digital filter.

• Apply the filter to a noisy signal.

• Analyze signals and their spectra.

The steps include:

• Creating a noisy signal in theMATL AB workspace and importing it intoSPTool

Designing a bandpass filter using the Filter Designer• Applying the filter to the original noise signal to create a bandlimited noise

signal

• Comparing the time domain information of the original and filtered signalsusing the Signal Browser

• Comparing the spectra of both signals using the Spectrum Viewer

• Exporting the filter design to the MATL AB workspace as a structure

• Accessing the filter coefficients from the exported MAT LAB structure

Page 248: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 248/870

6-18

Using SPTool: Filtering and Analysis of Noise

Importing a Signal into SPTool

To import a signal into SPT ool from the workspace or disk, the signal must beeither:

• A special MATL AB signal structure, such as that saved from a previousSPTool session

• A signal created as a variable (vector or matrix) in the MATL AB workspace

For this example, create a new signal at the command line and then import itas a structure into SPTool.

1 Create a random signal in the MA TL AB workspace by typing

randn( ' state ' , 0) ;x = r andn( 5000, 1) ;

2 I f SPT ool is not already open, open SPT ool by typing

spt ool

The SPT ool window is displayed.

3 Select Import from theFile menu in SPTool. The Import to SPTool dialogopens.

Page 249: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 249/870

6-19

6 SPTool: A Signal Processing GUI Suite

Notice that the variable x is displayed in the Workspace Contents list. (If it is not, select the From Workspaceradio button to display thecontents of the workspace.)

SelectFromWorkspaceto display all MATLAB

workspace variables

SelectFromDisk to load the

contents of a MAT-file into the

FileContentslist.

Workspace Contents

(orFile Contents) list

Import signals,

filters, or spectra

SPTool structures appear in

square brackets. Vectors and

matrices are not in brackets.

Move selected items fromthe

Workspace Contents orFile

Contentslist to theDatafield.

Edit the samplingfrequency.

Edit the signalname.

Page 250: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 250/870

6-20

4 Select the signal and import it into the Data field:

a Make sure that Signal is selected in the Import As pull-down menu.

b Select the signal variable x in the Workspace Contents list.c Click on the arrow to the left of the Data field or type x in the Data field.

d Type 5000 in the Sampling Frequency field.

e Name the signal by typingnoi se in the Name field.

f Press OK .

At this point, the signal noi se[ vect or ] is selected in SPTool’s Signals list.

Using SPTool: Filtering and Analysis of Noise

Note You can import filters and spectra intoSP Tool in much thesameway asyou import signals. See “I mporting Filters and Spectra into SPTool” on page6-43 for specific details.

You can also import signals from MAT-files on your disk, rather than from theworkspace. See “L oading Variables from the Disk” on page 6-47 for moreinformation.

Typehel p spt ool for information about importi ng from the command line.

Page 251: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 251/870

6-21

6 SPTool: A Signal Processing GUI Suite

Designing a Filter

You can import an existing filter into SPT ool, or you can design and edit a newfilter using the Filter Designer.

I n this example:

1 Open a default filter in the Filter Designer.

2 Specify an equiripple bandpass FI R filter.

Opening the Filter Designer To open the Filter Designer, press the New Design button in SPTool. This

opens the Filter Designer with a default filter named f i l t 1.

Specifying the Bandpass FilterDesign an equiripple bandpass FI R filter with the following characteristics:

• Sampling frequency of 5000 Hz

• Stopband frequency ranges of [0 500] Hz and [1500 2500] Hz

• Passband frequency range of [750 1250] Hz

• Ripple in the passband of 0.01 dB

• Stopband attenuation of 75 dB

To modify your filter in the Filter Designer to meet these specifications:

Page 252: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 252/870

6-22

1 Change the filter sampling frequency to 5000 by entering this value in theSampling Frequency text box.

2 Select Equi r i ppl e FI R from the Algorithm list.

3 Select bandpass from the Type list.

4 Set the passband edge frequencies by entering750 for Fp1and 1250 for Fp2.

5 Set the stopband edge frequencies by entering 500 for Fs1and 1500 for Fs2.

Designing a Filter

6 Type 0. 01 into the Rp field and 75 into the Rs field.

Rp sets themaximumpassband ripple andRs sets the stopbandattenuationfor the filter.

7 Press the Apply button to design the new filter.

When the new filter is designed, the magnitude response of the filter isdisplayed with a solid line in the display region.

Page 253: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 253/870

6-23

The resulting filter is an order-78 bandpass equiripple filter.

Note You can use the solid line to modify your filter design. See “Redesigninga Fi lter U sing the Magnitude Plot” on page 6-37 for more information.

6 SPTool: A Signal Processing GUI Suite

Applying a Filter to a Signal

When you apply a filter to a signal, you create a new signal in SPT oolrepresenting the filtered signal.

To apply the filter f i l t 1 you just created to the signal noi se:

1 Select SPTool from the Window menu in the F ilter Designer.

2 Select the signal noi se[ vect or ] from the Signals list and select the filter(named f i l t1[ des i gn] ) from the Filters list, as shown below.

3 Press A l to appl the filter f i l t 1 to the signal i

Page 254: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 254/870

6-24

3 Press Apply to apply the filter f i l t 1 to the signal noi se.

The Apply Filter dialog box is displayed.

TheAlgorithmlist provides a

choice of several filter structures.

Type a newsignal name here.

Applying a Filter to a Signal

4 K eep the default filter structure selected in the Algorithm list. Name thenew signal by typing bl noi se in the Output Signal field in this dialog box.

5 Press OK to close the Apply Filter dialog box.

The filter is applied to the selected signal and the filtered signal

bl noi se[ vector] is listed in the Signals list in SPTool.

Page 255: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 255/870

6-25

6 SPTool: A Signal Processing GUI Suite

Analyzing Signals: Opening the Signal Browser

You can analyzeand print signals using theSignal Browser. You can also playthe signals if your computer has audio output capabiliti es.

For example, compare the signal noi se to the filtered signal bl noi se:

1 Shift+click on thenoi se and bl noi se signals in the Signals list of SPTool toselect both signals.

2 Press the View button under the Signals list.

The Signal Browser is activated and both signals are displayed in thedisplay region. (The names of both signals are shown above the display

region.) I nitially, theoriginal noi se signal covers up the bandlimitedbl noi se signal.

3 Push the selection button on the toolbar, , to select the bl noi se signal.

The display area is updated. Now you can see the bl noi se signalsuperimposed on top of the noi se signal. The signals are displayed in

different colors in both the display region and the panner. You can changethe color of the selected signal using the Line Properties button on thetoolbar, .

Page 256: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 256/870

6-26

Analyzing Signals: Opening the Signal Browser

Playing a SignalWhen you press thePlay button in theSignal Browser toolbar, , theactivesignal is played on the computer’s audio hardware.

1 To hear a portion of the active (selected) signal:

Usethevertical markers toselect a portion of thesignal you want toplay

Page 257: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 257/870

6-27

a Usethevertical markers toselect a portion of thesignal you want toplay.Vertical markers are enabled by the and buttons.

bPress the Play button.

2 To hear the other signal:

a Select thesignal as in step 3 above. You can alsoselect the signal directlyin the display region.

b Press the Play button again.

6 SPTool: A Signal Processing GUI Suite

Printing a Signal You can print from the Signal Browser using the Print button, .

You can use the line display buttons to maximize the visual contrast betweenthe signals by setting the line color for noi se to gray and the line color forbl noi se to white. Do this before printing two signals together.

Note You can follow the same rules to print spectra, but you can’t print fil terresponses directly from SPTool.

Use the Signal Browser region in the Preferences dialog box in SPTool tosuppress printing of both the panner and the marker settings.

To print both signals, press the Print button in the Signal Browser toolbar.

Page 258: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 258/870

6-28

Spectral Analysis in the Spectrum Viewer

Spectral Analysis in the Spectrum Viewer

You can analyze the frequency content of a signal using the Spectrum Viewer,which estimates and displays a signal’s power spectral density.

For example, to analyze and compare the spectra of noi se and bl noi se:

1 Create a power spectral density object, spect 1, that is associated with thesignal noi se, and a second power spectral density object, spect 2, that isassociated with the signal bl noi se.

2 Open the Spectrum Viewer to analyze both of these spectra.

3 Print both spectra.

Creating a PSD Object From a Signal

1 Click on SPT ool, or select SPTool from theWindow menu of anyactive openGUI . SPTool is now theactive window.

2 Select the noi se[vector] signal in the Signals list of SPTool.

3Press

Createin the

Spectralist.

The Spectrum Viewer is activated, and a power spectral density object(spect 1) corresponding to the noi se signal is created in the Spectra list. The power spectral density is not computed or displayed yet.

4 Press Apply in the Spectrum Viewer to compute and display the power

Page 259: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 259/870

6-29

4 Press Apply in the Spectrum Viewer to compute and display the powerspectral density estimate spect 1 using the default parameters.

The power spectral density of the noi se signal is displayed in the displayregion. The identifying information for the power spectral density’sassociated signal (noi se) is displayed above the Parameters region.

The power spectral density estimate spect 1 is within 2 or 3 dB of 0, so thenoise has a fairly “flat” power spectral density.

6 SPTool: A Signal Processing GUI Suite

5 F ollow steps 1 through 4 for the bandlimited noise signal bl noi se to createa second power spectral density estimatespect 2.

Thepower spectral density estimatespect 2 is flat between 750 and 1250 Hzand has 75 dB less power in the stopband regions of f i l t 1.

Opening the Spectrum Viewer with Two Spectra

1 Reactivate SPT ool again, as in step 1 above.

2 Shift+click on spect 1 and spect 2 in the Spectra list to select them both.

3 Press View in the Spectra list to reactivate the Spectrum Viewer anddisplay both spectra together.

Page 260: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 260/870

6-30

Spectral Analysis in the Spectrum Viewer

Printing the SpectraBefore printing the two spectra together, use the color and line style selectionbutton, , to differentiate the two plots by line style, rather than by color.

To print both spectra:

1 Press the Print Preview button, , in the toolbar on the SpectrumViewer.

2 From the Spectrum Viewer Print Preview window, drag the legend out of the display region so that it doesn’t obscure part of the plot.

3 Press the Print button in the Spectrum Viewer Print Preview window.

Page 261: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 261/870

6-31

6 SPTool: A Signal Processing GUI Suite

Exporting Signals, Filters, and Spectra

You can export SPT ool signals, filters, and spectra as structures to theMAT LAB workspace or to your disk.

I n each case you:

1 Select the items in SPTool you want to export.

2 Select Export from the File menu.

Opening the Export Dialog Box To save the filter f i l t 1 you just created in this example, open the Export

dialog box with f i l t 1 preselected:

1 Select f i l t 1 in the SPTool Filters list.

2 Select Export from the File menu.

The Export dialog box opens with f i l t 1 preselected.

Select items to export fromtheExport List.

Export filters as objects that

canbeusedwiththeControl

Page 262: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 262/870

6-32

can be used with the Control

SystemToolbox.

Exporting Signals, Filters, and Spectra

Exporting a Filter to the MATLAB Workspace

To export the filter f i l t 1 to the MATL AB workspace:

1 Select f i l t 1 and deselect all other items using Ctrl+click.

2 Press the Export to Workspace button.

Page 263: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 263/870

6-33

6 SPTool: A Signal Processing GUI Suite

Designing a Filter with the Pole/ Zero Editor

To design a filter transfer function using theFilter Designer’s Pole/Zero Editor:

1 Select the Pol e/ Zer o Edi t or option from theAlgorithm list.

This opens the Pole/Zero Editor in the Fil terDesigner display.

2 Enter the desired filter gain in the Gain edit box.

3 Select a pole or zero (or conjugatepair) by selecting one of the (pole) or(zero) symbols on the plot.

4 Choosethe coordinates to work in by specifying Pol ar or Rect angul ar fromthe Coordinates list.

5 Specify the new location(s) of the selected pole, zero, or conjugate pair bytyping values into the Mag and Angle fields (for angular coordinates) or X

and Y (for rectangular coordinates) fields. Alternatively, position the polesand zeros by dragging the and symbols.

6 UsetheConjugatepair check box tocreatea conjugatepair froma lonepoleor zero, or to break a conjugate pair into two individual poles or zeros.

Design a new filter or edit an existing filter in the same way.

Page 264: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 264/870

6-34

Tip K eep the Filter Viewer open while designing a filter with the Pole/ZeroEditor. Any changes that you make to the filter transfer function in the

Pole/Zero Editor are then simultaneously reflected in the response plots of theFilter Viewer.

Designing a Filter with the Pole/ Zero Editor

Positioning Poles and Zeros You can use your mouse to move poles and zeros around the pole/zero plot andmodify your fi lter design:

• Add poles or zeros using thetoolbar buttons for pole placement, , and zeroplacement, .

• Erase poles and zeros using the eraser button, .

• Moveboth members of a conjugate pair simultaneously bymanipulating justone of the poles or zeros.

To ungroup conjugates, select thedesired pair and uncheck Conjugate pair inthe Specifications region on the Filter Designer.

Pole button foradding poles

Zero button foradding zeros

Eraser button for deletingpoles or zeros

Drag button for

moving poles

and zeros aroundon the plot.

Page 265: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 265/870

6-35

When you place two or more poles (or twoor more zeros) directly on top of eachother, a number is displayed next to the symbols (on the left for poles, and ontheright for zeros) indicating thenumber of polesor zeros at that location (e.g.,

for three zeros). This number makes it easy to keep track of all the polesand zeros in the plot area, even when several are superimposed on each otherand are not visually differentiable. Note, however, that this number does not

indicate the multiplicity of the poles or zeros to which i t i s attached.

6 SPTool: A Signal Processing GUI Suite

To detect whether or not a set of poles or zeros aretruly multiples, usethezoomtools to magnify the region around the poles or zeros in question. Becausenumerical limitations usually prevent any set of poles or zeros from sharingexactly the same value, at a high enough zoom level even truly multiple polesor zeros appear distinct from each other.

A common way to assess whether a particular group of poles or zeros containsmultiples is by comparing the mutual proximity of the group members againsta selected threshold value. As an example, ther esi duez function definesa poleor zero as being a multiple of another pole or zero if the absolute distanceseparating them is less than 0.1% of the larger pole or zero’s magnitude.

Page 266: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 266/870

6-36

Redesigning a Filter Using the Magnitude Plot

Redesigning a Filter Using the Magnitude Plot

After designing a filter in the Filter Designer, you can redesign it by draggingthe specification lines on the magnitude plot. Use the specification lines tochange passband ri pple, stopband attenuation, and edge frequencies.

I n the following example, create a Chebyshev filter and modify it by draggingthe specification lines:

1 Select Chebyshev Type I I I R from the Algorithm menu.

2 Select hi ghpass from the Type menu.

3 Type 2000 in the Sampling Frequency field.

4 Set the following parameters:

a Fp =800

b Fs =700

c Rp =2. 5

d Rs =35

5 Check Minimum Order sotheF ilter Designer can calculatethelowest filterorder that produces the desired characteristics.

6 Press Apply to compute the filter and update the response plot.

7 Position the cursor over the horizontal fi lter specification line for thestopband. This is the first (leftmost) horizontal specification line you see.

Page 267: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 267/870

6-37

The cursor changes to the up/down drag indicator.

8 Drag the line until the Rs (stopband attenuation) field reads 100.

Note The Order value in the Measurements region changes because ahigher filter order is needed to meet the new specifications.

6 SPTool: A Signal Processing GUI Suite

Accessing Filter Parameters in a Saved Filter

The MAT L AB structures created by SPT ool have several associated fields,many of which arealso MAT LAB structures. See theMATL AB documentationfor general information about MATLAB structures.

For example, after exporting a filter f i l t 1 to the MA TL AB workspace, type

f i l t 1

to display the fields of the MAT L AB filter structure. The t f , Fs , and specs

fields of the structure contain the information that describes the fil ter.

The tf Field: Accessing Filter Coefficients

The t f field is a structure containing the transfer function representation of the filter. Use this field to obtain the filter coefficients:

• f i l t 1. t f . numcontains the numerator coefficients.

• f i l t 1. t f . den contains the denominator coefficients.

The vectors contained in thesestructures represent polynomials in descendingpowers of z. The numerator and denominator polynomials are used to specifythe transfer function

where:

• b is a vector containing the coefficients from the t f . numfield.

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 na 1+( )z n–+ + +

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

Page 268: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 268/870

6-38

• a is a vector containing the coefficients from the t f . den field.

• m is the numerator order.• n is the denominator order.

You can change the filter representation from the default transfer function toanother form by using the t f 2ss or t f2zp functions.

The Fs Field: Accessing Filter Sample Frequency

TheFs

field contains the sampling frequency of the filter in hertz.

Accessing Filter Parameters in a Saved Filter

The specs Field: Accessing other Filter Parameters The specs field is a structure containing parameters that you specified for thefilter design. The first field, specs. cur r ent Modul e, contains a stringrepresenting themost recent design method selected fromtheFilter Designer’sAlgorithm list before you exported the filter. The possible contents of the

curr ent Modul e field and the corresponding design methods are shown below.

Following thespecs. cur r ent Modul e field, there may be up to seven additionalfields, with labels such as specs. f dr emez, specs. f df i r l s, etc. The designspecifications for the most recently exported fil ter are contained in the fieldwhose label matches the curr ent Modul e string. For example, if the specs

structure is

f i l t 1 specs

Table 6-1: Filter Specifications currentModule Field Values

Contents of the currentModule field Design Method

f dbut t er Butterworth IIR

f dcheby1 Chebyshev Type I I I R

f dcheby2 Chebyshev Type I I I I R

f del l i p EllipticIIR

f df i r l s L east Squares FI R

f dkai ser K aiser Window F I R

f dr emez Equiripple FI R

Page 269: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 269/870

6-39

f i l t 1. specs

ans

curr ent Modul e: ' f dr emez'

f dr emez: [ 1x1 st r uct ]

thefilter specifications arecontained in thef dr emez field, which is itself a datastructure.

The specifications include the parameter values from the Specifications

region of the Filter Designer, such as band edges and filter order. For example,

6 SPTool: A Signal Processing GUI Suite

the filter above has the following specifications stored inf i l t 1. specs. f dr emez.

f i l t 1. specs. f dr emez

ans =

set Or der Fl ag: 0t ype: 3

f : [ 0 0. 2000 0. 3000 0. 5000 0. 6000 1]

m: [ 6x1 doubl e]

Rp: 0. 0100

Rs: 75

wt : [ 3. 2371 1 3. 2371]

or der : 78

Because certain filter parameters are unique to a particular design, thisstructure has a different set of fields for each filter design.

The table below describes the possible fields associated with the filter designspecification field (the specs field) that can appear in the exported structure.

Table 6-2: SPTool Structure Specifications for Filters

Parameter Description

Bet a K aiser window β parameter.

f Contains a vector of band-edge frequencies, normalized sothat 1 Hz corresponds to half the sample frequency.

Fpass Passband cutoff frequencies. Scalar for lowpass andhighpass designs, two-element vector for bandpass and

Page 270: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 270/870

6-40

highpass designs, two element vector for bandpass andbandstop designs.

Fst op Stopband cutoff frequencies. Scalar for lowpass andhighpass designs, two-element vector for bandpass andbandstop designs.

m The response magnitudes corresponding to the band-edgefrequencies in f .

order Filter order.

Accessing Filter Parameters in a Saved Filter

Rp Passband ripple (dB)

Rs Stopband attenuation (dB)

setOr der Fl ag Contains 1 if the filter order was specified manually (i.e.,the Minimum Order box in the Specifications regionwas not checked). Contains 0 if the filter order wascomputed automatically.

t ype Contains 1 for lowpass, 2 for highpass, 3 for bandpass, or4 for bandstop.

w3db -3 dB frequency for Butterworth I I R designs.

wi nd Vector of K aiser window coefficients.

Wn Cutoff frequency for the K aiser window FI R filter whenset OrderF l ag = 1.

wt Vector of weights, one weight per frequency band.

Table 6-2: SPTool Structure Specifications for Filters (Continued)

Parameter Description

Page 271: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 271/870

6-41

6 SPTool: A Signal Processing GUI Suite

Accessing Parameters in a Saved Spectrum

The following structure fields describe the spectra saved by SPT ool.

You can access the information in these fields as you do with every MATL ABstructure.

For example, if you export an SPTool PSD estimate spect 1 to the workspace,type

t 1 P

Field Description

P The spectral power vector.

f The spectral frequency vector.

conf i d A structure containing the confidence intervals data:

• The conf i d. l evel field contains the chosenconfidence level.

• The conf i d. Pc field contains the spectral powerdata for the confidence intervals.

• The conf i d. enabl e field contains a 1 if confidencelevels are enabled for the power spectral density.

si gnal Label The name of the signal from which the power spectraldensity was generated.

Fs The associated signal’s sample rate.

Page 272: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 272/870

6-42

spect 1. P

to obtain the vector of associated power values.

Importing Filters and Spectra into SPTool

Importing Filters and Spectra into SPTool

I n addition to importing signals into SPT ool, you can import filters or spectrainto SPT ool from either the workspace or from a file.

The procedures are very similar to those explained in:

• “I mporting a Signal into SPT ool” on page 6-19 for loading variables from theworkspace

• “Loading Variables from the Disk” on page 6-47 for loading variables fromyour disk

Importing FiltersWhen you import filters, first select theappropriatefilter form from theForm

list.

Select a filter

structure.

Page 273: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 273/870

6-43

6 SPTool: A Signal Processing GUI Suite

Each filter form requires different variables:

• For Tr ansf er Funct i on, you specify the filter by its transfer functionrepresentation:

- The Numerator field specifies a variable name or value for the numeratorcoefficient vector b, which contains m+1 coefficients in descending powers

of z.

- The Denominator field specifies a variable name or value for thedenominator coefficient vector a, which contains n+1 coefficients indescending powers of z.

•For State Space, you specify the filter by its state-space representation:

The A-Matrix, B-Matrix, C-Matrix, and D-Matrix fields specify a variable

name or a value for each matrix in this system.

• For Zeros, Pol es, Gai n, you specify the filter by its zero-pole-gain

representation:

- The Zeros field specifies a variable name or value for the zeros vector z,which contains the locations of m zeros.

- The Poles field specifies a variable name or value for the zeros vector p,which contains the locations of n poles

H z( )B z( )

A z( )-----------

b 1( ) b 2( )z 1–L b m 1+( )z m–+ + +

a 1( ) a 2( )z

1–L

a n 1+( )z

n–

+ + +

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

x· Ax B u+=

y Cx Du+=

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 274: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 274/870

6-44

which contains the locations of n poles.

- The Gain field specifies a variable name or value for the gain k.

• For 2nd Or der Sect i ons you specify the fil ter by its second-order section

representation:

H z( ) H k z( )

k 1=

L

∏b0k b1kz 1– b2kz 2–+ +

1 a1kz 1– a2kz 2–+ +----------------------------------------------------------

k 1=

L

∏= =

Importing Filters and Spectra into SPTool

The SOS Matrix field specifies a variable name or a valuefor theL -by-6SOSmatrix

whose rows contain the numerator and denominator coefficients bik and aik

of the second-order sections of H(z).

• For every filter you specify a variable name or a value for the filter’ssampling frequency in the Sampling Frequency field.

Note I f you import a filter that was not created in SPTool, you can only editthat filter using the Pole/Zero Editor.

Importing SpectraWhen you import a power spectral density (PSD), you specify:

• A variable name or a value for the PSD vector in the PSD field

• A variable name or a value for the frequency vector in the Freq. Vector field

sos

b01 b11 b21 1 a11 a21

b02 b12 b22 1 a12 a22

b0L b1L b2L 1 a1L a2L

=

Page 275: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 275/870

6-45

6 SPTool: A Signal Processing GUI Suite

The PSD values in the PSD vector correspond to the frequencies containedin the Freq. Vector vector; the two vectors must have the same length.

Page 276: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 276/870

6-46

Loading Variables from the Disk

Loading Variables from the Disk

To import variables representing signals, filters, or spectra from a MAT -file onyour disk:

1 Select the From Disk radio button and do either of the following:

- Type the name of the file you want toimport intotheMAT-file Name fieldand press either the Tab or the Enter key on your keyboard.

- Select Browse, and then find and select thefile you want to import usingthe Select File to Open dialog. Press OK to close that dialog.

I n either case, all variables in theM AT-file you selected are displayed in theFile Contents list.

2 Select the variables to be imported into SPT ool.

You can now import one or more variables from the File Contents list intoSPT ool, as long as these variables are scalars, vectors, or matrices.

Page 277: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 277/870

6-47

6 SPTool: A Signal Processing GUI Suite

Selecting Signals, Filters, and Spectra in SPTool

All signals, filters, or spectra listed in SPT ool exist as special MAT LABstructures. You can bring data representing signals, filters, or spectra intoSPT ool from theMA TL AB workspace. I n general, you can select one or severalitems in a given list box. An item is selected when it is highlighted.

The Signals list shows all vector and array signals in the current SPToolsession.

The Filters list shows all designed and imported filters in the current SPT oolsession.

The Spectra list shows all spectra in the current SPTool session.

You can select a single data object in a list, a range of data objects in a list, or

multiple separate data objects in a list. You can also have data objectssimultaneously selected in different lists:

• To select a single item, click on it. All other items in that l ist box becomedeselected.

• To add or remove a range of items, Shift+click on the items at the top andbottom of thesection of thelist that you want to add. You can alsodrag yourmouse pointer to select these items.

• To add a single data object to a selection or removea single data object froma multiple selection, Ctrl+click on the object.

Page 278: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 278/870

6-48

Editing Signals, Filters, or Spectra in SPTool

Editing Signals, Filters, or Spectra in SPTool

You can edit selected items in SPT ool by:

1 Selecting the names of the signals, filters, or spectra you want to edit.

2 Selecting the appropriate Edit menu item:- Duplicate to copy an item in an SPTool list

- Clear to delete an item in an SPTool list

- Name to rename an item in an SPTool l ist

- Sampling Frequency to modify the sampling frequency associated with

either a signal (and its associated spectra) or filter in an SPT ool list

The pull-down menu next to each menu item shows thenames of all selecteditems.

You can also edit the following signal characteristics by right-clicking in thedisplay region of the Signal Browser, the Filter Viewer, or the SpectrumViewer:

• The signal name

• The sampling frequency

• The line style properties

Note I f you modify the sampling frequency associated with a signal’sspectrum using the right-cli ck menu on the Spectrum Viewer display region,the sampling frequency of the associated signal is automatically updated.

Page 279: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 279/870

6-49

6 SPTool: A Signal Processing GUI Suite

Setting Preferences

UsePreferencesfrom theSP Tool File menu to customize displays andcertainparameters for SPT ool and its four component GU I s. The new settings aresaved on disk and are used when you restart SP Tool from MATL AB.

In the Preferences regions, you can:• Select colors and markers for all displays.

• Select colors and line styles for displayed signals.

• Configure labels, and enable/disable markers, panner, and zoom in theSignal Browser.

• Configure display parameters, and enable/disable markers and zoom in theSpectrum Viewer.

• Configure filter and display parameters, and enable/disable zoom in theFilter Viewer.

• Configure tiling preferences in the Filter Viewer.

• Specify FF T length, and enable/disable mouse zoom and grid in the F ilter

Designer.

• Enable/disable use of a default session file.

• Export filters for use with the Control System Toolbox.

• Enable/disable search for plug-ins at start-up.

When you first select Preferences, the Preferences dialog box opens withMarkers selected by default. You can:

• Change the settings for markers from this panel of the Preferences dialog.

• Choose any of the other categories listed to customize its settings.

Page 280: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 280/870

6-50

Click once on any listed category in the left pane of the Preferences dialog toselect it.

Making Signal Measurements: Using Markers

Making Signal Measurements: Using Markers

You can use the markers on the Signal Browser, the Filter Viewer, or theSpectrum Viewer to make measurements on any of the following:

• A signal in the Signal Browser

• A filter response in the Filter Viewer• A power spectral density plotted in the Spectrum Viewer

To make a measurement:

1 Select a line to measure (or play, if you are in the Signal Browser).

2 Select one of the marker buttons, , , , , , , to apply a

marker to the displayed signal.

3 Position a marker in the main display area by grabbing it with your mouseand dragging:

a Select a marker setting. I f you choose the Vertical, Track , or Slopebuttons, you can drag a marker to the right or l eft. I f you choosetheHorizontal button, you can drag a marker up or down.

b Move the mouse over the marker (1 or 2) that you want to drag.

The hand cursor with the marker number inside it is displayed whenyour mouse passes over a marker.

c Drag the marker to where you want it on the signal.

As you drag a marker, the bottom of the Signal Browser shows the currentposition of both markers. Depending on which marker setting you select,some or all of the following fields are displayed: x1, y1, x2, y2, dx, dy, m.

Page 281: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 281/870

6-51

These fields are also displayed when you print from the Signal Browser,unless you suppress them.

Y ou can also position a marker by typing its x1 and x2 or y1 and y2 values inthe region at the bottom.

6 SPTool: A Signal Processing GUI Suite

Page 282: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 282/870

6-52

7

Function Reference

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

Alphabetical Listing of Functions . . . . . . . . . . 7-16

Page 283: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 283/870

7 Function Reference

This chapter contains detailed descriptions of all Signal P rocessing Toolboxfunctions. I t is divided into two sections:

• “Function Category List” – a list of functions, grouped by subject area

• “Alphabetical List of Functions” – reference pages in alphabetical order

Page 284: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 284/870

7-2

Function Category List

Function Category List

The tables below list all of the Signal Processing Toolbox functions by category.

Filter Analysis

abs Absolute value (magnitude).

angl e Phase angle.

f r eqs Frequency response of analog filters.

f r eqspace Frequency spacing for frequency response.

f r eqz Compute the frequency response of digital filters.

f r eqzpl ot Plot frequency response data.

gr pdel ay Compute the average filter delay (group delay).

i mpz Compute the impulse response of digital filters.

unwr ap Unwrap phase angles.

zpl ane Zero-pole plot.

Filter Implementation

conv Convolution and polynomial multiplication.

conv2 Two-dimensional convolution.

Page 285: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 285/870

7-3

deconv Deconvolution and polynomial division.

f f t f i l t FFT-based F I R filtering using the overlap-add method.

f i l t er Filter data with a recursive (I I R) or nonrecursive (FI R)filter.

f i l t er 2 Two-dimensional digital filtering.

7 Function Reference

f i l t f i l t Zero-phase digital filtering.

f i l t i c Find initial conditions for a transposed direct form I I filterimplementation.

l at cf i l t L attice and lattice-ladder filter implementation.

medf i l t 1 One-dimensional median filtering.

sgol ayf i l t Savitzky-Golay filtering.

sosf i l t Second-order (biquadratic) I I R digital filtering.

upf i r dn Upsample, apply an F I R filter, and downsample.

FIR Digital Filter Design

convmt x Convolution matrix.

cr emez Complex and nonlinear-phase equiripple FI R filter design.

f i r 1 Design a window-based finite impulse response filter.

f i r 2 Design a frequency sampling-based finite impulse response

filter.

f i r c l s Constrained least square FI R filter design for multibandfilters.

f i r c l s 1 Constrained least square filter design for lowpass andhi h li h FI R filt

Filter Implementation (Continued)

Page 286: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 286/870

7-4

highpass linear phase FI R filters.

f i r l s L east square linear-phase FI R filter design.

f i r r c os Raised cosine FI R filter design.

i nt f i l t Interpolation FIR filter design.

kai ser or d Estimate parameters for an FI R filter design with K aiser

window.

Function Category List

r emez Compute the Parks-McClellan optimal F I R filter design.

r emezor d Parks-McClellan optimal FI R filter order estimation.

sgol ay Savitzky-Golay filter design.

IIR Digital Filter Design—Classical and Direct

but t er Butterworth analog and digital filter design.

cheby1 Chebyshev type I filter design (passband ripple).

cheby2 Chebyshev type I I filter design (stopband ripple).

el l i p Elliptic (Cauer) filter design.

maxf l at Generalized digital Butterworth filter design.

prony Prony’s method for time-domain I I R fil ter design.

st mcb Compute a linear model using Steiglitz-McBride iteration.

yul ewal k Recursive digital filter design.

IIR Filter Order Estimation

buttordCalculate the order and cutoff frequency for a Butterworthfilt

FIR Digital Filter Design (Continued)

Page 287: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 287/870

7-5

Calculate the order and cutoff frequency for a Butterworthfilter.

cheb1ord Calculate the order for a Chebyshev type I filter.

cheb2ord Calculate the order for a Chebyshev type I I filter.

el l i pord Calculate the minimum order for elliptic filters.

7 Function Reference

Analog Lowpass Filter Prototypes

bessel ap Bessel analog lowpass filter prototype.

but t ap Butterworth analog lowpass filter prototype.

cheb1ap Chebyshev type I analog lowpass filter prototype.

cheb2ap Chebyshev type I I analog lowpass filter prototype.

el l i pap Elliptic analog lowpass filter prototype.

Analog Filter Design

bessel f Bessel analog filter design.

but t er Butterworth analog and digital filter design.

cheby1 Chebyshev type I fil ter design (passband ripple).

cheby2 Chebyshev type I I fil ter design (stopband ripple).

el l i p Elliptic (Cauer) filter design.

Analog Filter Transformation

l p2bp Transform lowpass analog filters to bandpass.

l p2bsTransform lowpass analog filters to bandstop

Page 288: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 288/870

7-6

Transform lowpass analog filters to bandstop.l p2hp Transform lowpass analog filters to highpass.

l p2l p Change the cut-off frequency for a lowpass analog fil ter.

Function Category List

Filter Discretization

bi l i near Bili near transformation method for analog-to-digital filter

conversion.

i mpi nvar I mpulse invariance method for analog-to-digital filter

conversion.

Linear System Transformations

l at c2t f Convert lattice filter parameters to transfer function form.

pol yst ab Stabilize a polynomial.pol yscal e Scale the roots of a polynomial.

r esi duez z-transform partial-fraction expansion.

sos2ss Convert digital filter second-order section parameters tostate-space form.

sos2t f Convert digital filter second-order section data to transfer

function form.

sos2zp Convert digital filter second-order sections parameters tozero-pole-gain form.

ss2sos Convert digital filter state-space parameters tosecond-order sections form.

ss2tf Convert state-space filter parameters to transfer function

form.

Page 289: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 289/870

7-7

form.

ss2zp Convert state-space filter parameters to zero-pole-gainform.

t f 2l at c Convert transfer function filter parameters to lattice fil terform.

7 Function Reference

t f 2sos Convert digital filter transfer function data to second-order

sections form.

t f 2ss Convert transfer function fi lter parameters to state-space

form.t f 2zp Convert transfer function filter parameters to

zero-pole-gain form.

zp2sos Convert digital filter zero-pole-gain parameters tosecond-order sections form.

zp2ss Convert zero-pole-gain filter parameters to state-space

form.zp2t f Convert zero-pole-gain filter parameters to transfer

function form.

Windows

bart l et t Compute a Bartlett window.

bl ackman Compute a Blackman window.

boxcar Compute a rectangular window.

chebwi n Compute a Chebyshev window.

hammi ng Compute a Hamming window.

hann Compute the Hann (Hanning) window

Linear System Transformations (Continued)

Page 290: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 290/870

7-8

hann Compute the Hann (Hanning) window.

kai ser Compute a K aiser window.

t r i ang Compute a tri angular window.

Function Category List

Transforms

czt Chirp z-transform.

dct Discrete cosine transform (DCT).

df t mt x Discrete Fourier transform matrix.

f f t Compute the one-dimensional fast Fourier transform.

f f t 2 Compute the two-dimensional fast Fourier transform.

f f t shi f t Rearrange the outputs of the FFT functions.

hi l bert Computethediscrete-time analytic signal using theH ilbert

transform.

i dct I nverse discrete cosine transform.

i f f t One-dimensional inverse fast Fourier transform.

i f f t 2 Two-dimensional inverse fast Fourier transform.

Cepstral Analysis

cceps Complex cepstral analysis.

i cceps I nverse complex cepstrum.

r ceps Real cepstrum and minimum phase reconstruction.

Page 291: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 291/870

7-9

Statistical Signal Processing and Spectral Analysis

cohere Estimate magnitude squared coherence function betweentwo signals.

corr coef Compute the correlation coefficient matrix.

7 Function Reference

cor r mt x Compute a data matrix for autocorrelation matrix

estimation.

cov Compute the covariance matrix.

csd Estimate the cross spectral density (CSD) of two signals.

pburg Estimate the power spectral density using the Burgmethod.

pcov Estimate the power spectral density using the covariancemethod.

pei g Estimate the pseudospectrum using the eigenvector

method.

peri odogr am Estimate the power spectral density (PSD) of a signal usinga periodogram.

pmcov Estimate the power spectral density using the modifiedcovari ance method.

pmt m Estimate the power spectral density using the multitaper

method (MTM).

pmusi c Estimate the power spectral density using MUSI Calgorithm.

psdpl ot Plot power spectral density (PSD) data.

pwel ch Estimate the power spectral density (PSD) of a signal usingWelch’s method.

pyul ear Estimate the power spectral density using the Yule-Walker

Statistical Signal Processing and Spectral Analysis (Continued)

Page 292: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 292/870

7-10

pyul ear Estimate the power spectral density using the Yule WalkerAR method.

root ei g Estimate frequency and power content using theeigenvector method.

r oot musi c Estimate frequency and power content using the rootMUSIC algorithm.

Function Category List

t f e Estimate the transfer function from input and output.

xcorr Estimate the cross-correlation function.

xcorr2 Estimate the two-dimensional cross-correlation.

xcov Estimate the cross-covari ance function (equal to

mean-removed cross-correlation).

Parametric Modeling

arbur g Compute an estimate of AR model parameters using theBurg method.

arcov Compute an estimate of AR model parameters using thecovariance method.

ar mcov Compute an estimate of AR model parameters using themodified covariance method.

ar yul e Compute an estimate of AR model parameters using the Yule-Walker method.

i dent Seethe System I dentification Toolbox documentation.

i nvf r eqs I dentify continuous-time filter parameters from frequencyresponse data.

i nvf r eqz I dentify discrete-time fil ter parameters from frequency

response data.

Statistical Signal Processing and Spectral Analysis (Continued)

Page 293: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 293/870

7-11

prony Prony’s method for time domain I I R filter design.

st mcb Compute a linear model using Steiglitz-McBride iteration.

7 Function Reference

Linear Prediction

ac2pol y Convert an autocorrelation sequence to prediction

polynomial.

ac2r c Convert an autocorrelation sequence to reflection

coefficients.i s2rc Convert inverse sine parameters to reflection coefficients.

l ar2rc Convert log area ratio parameters to reflection coefficients.

l evi nson Compute the Levinson-Durbin recursion.

l pc Compute li near prediction filter coefficients.

l s f 2pol y Convert line spectral frequencies to a prediction filtercoefficients.

pol y2ac Convert a prediction filter polynomial to an autocorrelationsequence.

pol y2l sf Convert prediction fil ter coefficients to line spectral

frequencies.

pol y2r c Convert a prediction filter polynomial to reflectioncoefficients.

r c2ac Convert reflection coefficients to an autocorrelationsequence.

rc2i s Convert reflection coefficients to inverse sine parameters.

r c2l ar Convert reflection coefficients to log area ratio parameters.

r c2pol y Convert reflection coefficients to a prediction fil terpolynomial

Page 294: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 294/870

7-12

polynomial.

r l evi nson Compute the reverse L evinson-Durbin recursion.

schurrc Compute reflection coefficients from an autocorrelationsequence.

Function Category List

Multirate Signal Processing

deci mat e Decrease the sampling rate for a sequence (decimation).

i nterp I ncrease sampling rate by an integer factor (interpolation).

i nt er p1 One-dimensional data interpolation (table lookup).

r esampl e Change sampling rate by any rational factor.

spl i ne Cubic spline interpolation.

upf i r dn Upsample, apply an F I R filter, and downsample.

Waveform Generation

chi rp Generate a swept-frequency cosine.

di r i c Compute the Dirichlet or periodic sinc function.

gauspul s Generate a Gaussian-modulated sinusoidal pulse.

gmonopul s Generate a Gaussian monopulse.

pul st r an Generate a pulse train.

r ectpul s Generate a sampled aperi odic rectangle.

sawt oot h Generate a sawtooth or triangle wave.

s i nc Sinc function.

square Generate a square wave.

t r i pul s Generate a sampled aperiodic triangle.

Page 295: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 295/870

7-13

t r i pul s Generate a sampled aperiodic triangle.

vco Voltage controlled oscillator.

7 Function Reference

Specialized Operations

buf f er Buffer a signal vector into a matrix of data frames.

cel l 2sos Convert a cell array for second-order sections to asecond-order section matrix.

cpl xpai r Group complex numbers into complex conjugate pairs.

demod Demodulation for communications simulation.

dpss Discrete prolate spheroidal sequences (Slepian sequences).

dpsscl ear Remove discrete prolate spheroidal sequences fromdatabase.

dpssdi r Discrete prolate spheroidal sequences database directory.dpssl oad L oad discrete prolate spheroidal sequences from database.

dpsssave Savediscrete prolate spheroidal sequences in database.

eqt f l engt h Make the lengths of a transfer function's numerator anddenominator equal.

modul at e Modulation for communications simulation.

seqperi od Compute the period of a sequence.

sos2cel l Convert a second-order section matrix to cell arrays.

specgr am Time-dependent frequency analysis (spectrogram).

stem Plot discrete sequence data.

st r i ps Strip plot.

udecode Decode 2n-level quantized integer inputs to floating-point

Page 296: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 296/870

7-14

q g p g poutputs.

uencode Quantize and encode floating-point inputs to integer

outputs.

Function Category List

Graphical User Interfaces

f dat ool Open the Filter Design and Analysis Tool.

spt ool I nteractive digital signal processing tool (SPTool).

Page 297: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 297/870

7-15

abs

7absPurpose Absolute value (magnitude).

Syntax y = abs( x)

Description y =abs( x) returns the absolute value of the elements of x. I f x is complex, abs

returns the complex modulus (magnitude).

abs( x) = sqr t ( r eal ( x) . 2 + i mag( x) . 2)

I f x is a MATL AB string, abs returns the numeric values of the ASCI Icharacters in the string. Thedisplay format of the string changes; the internalrepresentation does not.

The abs function is part of the standard MATL AB language.

Example Calculate the magnitude of the FFT of a sequence.t = ( 0: 99) / 100; % t i me vect or

x = si n( 2*pi *15*t ) + s i n( 2*pi *40*t ) ; % si gnal

y = f f t ( x) ; % comput e DFT of x

m = abs( y) ; % magni t ude

Plot the magnitude.

f = ( 0: l engt h( y) - 1) ' / l engt h( y) *100; % f r equency vector

pl ot ( f , m)

See Also angl e Phase angle.

Page 298: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 298/870

7-16

ac2poly

7ac2polyPurpose Convert an autocorrelation sequence to a prediction filter polynomial.

Syntax a = ac2pol y( r )

[ a, ef i nal ] = ac2pol y( r )

Description a =ac2pol y(r ) finds the prediction filter polynomial a corresponding to the

autocorrelation sequence r . a is the same length as r , and a(1) =1. Theprediction filter polynomial represents the coefficients of the prediction fil terwhose output produces a signal whose autocorrelation sequence isapproximately the same as the given autocorrelation sequence r .

[a, ef i nal ] =ac2pol y(r ) returns the final prediction error ef i nal ,determined by running the filter for l engt h( r) steps.

Remarks You can apply this function to real or complex data.

Example Consider the autocorrelation sequence

r = [ 5. 0000 - 1. 5450 - 3. 9547 3. 9331 1. 4681 - 4. 7500] ;

The equivalent prediction filter polynomial is

[ a, ef i nal ] = ac2pol y( r )

a =1. 0000 0. 6147 0. 9898 0. 0004 0. 0034 - 0. 0077

ef i nal =

0. 1791

See Also ac2r c Convert an autocorrelation sequence to reflection

coefficients.pol y2ac Convert a prediction filter polynomial to an

Page 299: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 299/870

7-17

References [1] K ay, S.M. Modern Spectral Estimation. Englewood Cliffs, NJ :

Prentice-Hall, 1988.

autocorrelation sequence.

r c2pol y Convert reflection coefficients to a prediction fil ter

polynomial.

ac2rc

7ac2rcPurpose Convert an autocorrelation sequence to reflection coefficients.

Syntax [ k, r 0] = ac2r c( r )

Description [ k, r0] =ac2rc(r) finds the reflection coefficients k corresponding to theautocorrelation sequence r . r 0 contains the initial zero-lag autocorrelation.

These reflection coefficients can be used to specify the lattice prediction filterthat produces a sequence with approximately the sameautocorrelationsequence as the given sequence r .

Remarks You can apply this function to real or complex data.

See Also

References [1] K ay, S.M. Modern Spectral E stimation. Englewood Cliffs, NJ :Prentice-Hall, 1988.

ac2pol y Convert an autocorrelation sequence to a predictionfilter polynomial.

pol y2r c Convert a prediction filter polynomial to reflectioncoefficients.

r c2ac Convert reflection coefficients to an autocorrelationsequence.

Page 300: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 300/870

7-18

angle

7anglePurpose Phase angle.

Syntax p = angl e(h)

Description p =angl e(h) returns the phase angles, in radians, of the elements of complexvector or array h. The phase angles lie between -π and π.

For complex sequence h =x +iy =meip, the magnitude and phaseare given by

m = abs(h)

p = angl e(h)

To convert to the original h from its magnitude and phase, type

i = sqr t ( - 1)

h = m. *exp( i *p)

The angl e function is part of the standard MATL AB language.

Example Calculate the phase of the FFT of a sequence.

t = ( 0: 99) / 100; % t i me vect or

x = si n( 2*pi *15*t ) + s i n( 2*pi *40*t ) ; % si gnal

y = f f t ( x) ; % comput e DFT of x

p = unwr ap( angl e( y) ) ; % phase

Plot the phase.

f = ( 0: l engt h( y) - 1) ' / l engt h( y) *100; % f requency vect or

pl ot ( f , p)

Algorithm angl e can be expressed as

angl e( x) = i mag( l og( x) ) = at an2( i mag( x) , real ( x) )

See Also abs Absolute value (magnitude).

Page 301: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 301/870

7-19

arburg

7arburgPurpose Compute an estimate of AR model parameters using the Burg method.

Syntax a = arburg( x, p)

[a, e] = arburg(x, p)

[a, e, k] = arburg(x, p)

Description a =ar bur g( x, p) uses the Burg method to fit a pth order autoregressive (AR)model to the input signal, x, by minimizing (least squares) the forward andbackward prediction errors while constraining the AR parameters to satisfythe L evinson-Durbin recursion. x is assumed to be theoutput of an AR systemdriven by white noise. Vector a contains the normalized estimate of the AR

system parameters, A(z), in descending powers of z.

Since the method characterizes the input data using an all-pole model, the

correct choice of the model order p is important.

[ a, e] =ar bur g( x, p) returns thevarianceestimate, e, of thewhitenoiseinputto the AR model.

[ a, e, k] =ar bur g( x, p) returns a vector, k, of reflection coefficients.

See Also

H z( )e

A z( )

------------e

1 a2z 1– … a p 1+( )z p–+ + +

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

ar cov Compute an estimate of AR model parameters usingthe covariance method.

ar mcov Compute an estimate of AR model parameters usingthe modified covari ance method.

ar yul e Compute an estimate of AR model parameters using

the Yule-Walker method.l pc Compute li near predictive recursion coefficients.

pburg Compute the power spectrum estimate using the

Page 302: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 302/870

7-20

pburg Compute the power spectrum estimate using theBurg method.

prony Prony’s method for time-domain I I R filter design.

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 =ar cov(x, p) uses the covariance method to fit a pth order autoregressive

(AR) model to the input signal, x, which is assumed to be the output of an ARsystem driven by white noise. This method minimizes the forward predictionerror in the least-squares sense. Vector a contains the normalized estimate of the AR system parameters, A(z), in descending powers of z.

Because the method characterizes the input data using an all-pole model, thecorrect choice of the model order p is important.

[ a, e] =ar cov(x, p) returns the variance estimate, e, of thewhite noiseinputto the AR model.

See Also

H z( )e

A z( )------------

e

1 a2z1–

… a p 1+( )zp–

+ + +

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

ar bur g Compute an estimate of AR model parameters using

the Burg method.

ar mcov Compute an estimate of AR model parameters usingthe modified covari ance method.

ar yul e Compute an estimate of AR model parameters usingthe Yule-Walker method.

l pc Compute li near predictive recursion coefficients.

pcov Estimate the power spectrum using the covariancemethod.

prony Prony’s method for I I R filter design.

Page 303: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 303/870

7-21

armcov

7armcovPurpose Compute an estimate of AR model parameters using the modified covariance

method.

Syntax a = ar mcov( x, p)

[ a, e] = armcov( x, p)

Description a =armcov( x, p) uses the modified covariance method to fit a pth orderautoregressive (AR) model to the input signal, x, which is assumed to be theoutput of an AR system driven by white noise. This method minimizes theforward and backward prediction errors in the least-squares sense. Vector a

contains the normalized estimate of the AR system parameters, A(z), in

descending powers of z.

Because the method characterizes the input data using an all-pole model, thecorrect choice of the model order p is important.

[ a, e] =armcov( x, p) returns thevarianceestimate, e, of thewhitenoiseinputto the AR model.

See Also

H z( )e

A z( )

------------e

1 a2z1–

… a p 1+( )zp–

+ + +

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

ar bur g Compute an estimate of AR model parameters usingthe Burg method.

ar cov Compute an estimate of AR model parameters usingthe covariance method.

ar yul e Compute an estimate of AR model parameters usingthe Yule-Walker method.

l pc Compute li near predictive recursion coefficients.

pmcov Estimate the power spectrum using the modifiedcovari ance method.

P ’ th d f I I R filt d i

Page 304: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 304/870

7-22

prony Prony’s method for I I R filter design.

aryule

7aryulePurpose Compute an estimate of AR model parameters using the Yule-Walker method.

Syntax a = aryul e(x, p)

[ a, e] = ar yul e( x, p)

[ a, e, k] = ar yul e( x, p)

Description a =ar yul e( x, p) uses the Y ule-Walker method, alsocalled the autocorrelationmethod, to fit a pth order autoregressive (AR) model to the windowed inputsignal, x, by minimizing the forward prediction error in the least-squaressense. This formulation leads to the Y ule-Walker equations, which are solvedby the L evinson-Durbin recursion. x is assumed to be the output of an AR

system driven by white noise. Vector a contains the normalized estimate of theAR system parameters, A(z), in descending powers of z.

Because the method characterizes the input data using an all-pole model, the

correct choice of the model order p is important.

[ a, e] =ar yul e( x, p) returns thevarianceestimate, e, of thewhite noiseinputto the AR model.

[ a, e, k] =ar yul e( x, p) returns a vector, k, of reflection coefficients.

See Also

H z( ) eA z( )------------ e

1 a2z1–

… a p 1+( )zp–

+ + +----------------------------------------------------------------------= =

ar bur g Compute an estimate of AR model parameters using

the Burg method.

arcov Compute an estimate of AR model parameters usingthe covariance method.

ar mcov Compute an estimate of AR model parameters usingthe modified covari ance method.

l pc Compute li near predictive recursion coefficients.

Page 305: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 305/870

7-23

prony Prony’s method for I I R filter design.

pyul ear Estimate the power spectrum using the Yule-Walkerautoregressive approach.

bartlett

7bartlettPurpose Compute a Bartlett window.

Syntax w = bar t l et t ( n)

Description w=bart l et t ( n) returns an n-point Bartlett window in the column vector w,where n must be a positive integer. The coefficients of a Bartlett window are

computed as foll ows:• For n odd

•For n even

The Bartlett window is very similar to a triangular window as returned by thet r i ang function. The Bartlett window alwaysends with zeros at samples 1 and

n, however, while the triangular window is nonzero at thosepoints. For n odd,the center n- 2 points of bart l et t ( n) are equivalent to t r i ang( n- 2) .

Note I f you specify a one-point window (set n=1), the value 1 is returned.

Example w = bar t l et t ( 64) ;pl ot ( w)

t i t l e( ' Bar t l et t Wi ndow' )

w k 1+[ ]

2k

n 1–------------- 0 k

n 1–

2-------------≤ ≤,

22 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 306: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 306/870

7-24

bartlett

See Also

References [1] Oppenheim, A.V., and R.W. Schafer. Discrete-TimeSi gnal Processing.Englewood Cliffs, NJ : Prentice-Hall, 1989, pp. 447-448.

0 10 20 30 40 50 60 700

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1Bartlett Window

bl ackman Compute a Bl ackman window.

boxcar Compute a rectangular window.

chebwi n Compute a Chebyshev window.

hammi ng Compute a Hamming window.

hann Compute a Hann window.

kai ser Compute a K aiser Window.t r i ang Compute a triangular window.

Page 307: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 307/870

7-25

besselap

7besselapPurpose Bessel analog lowpass filter prototype.

Syntax [ z , p, k] = bessel ap(n)

Description [ z , p, k] =bessel ap( n) returns thepoles and gain of an order n Bessel analoglowpass filter prototype. n must be less than or equal to 25. The function

returns the poles in the length n column vector p and the gain in scalar k. z isan empty matrix because there are no zeros. The transfer function is

bessel ap normalizes the poles and gain so that at low frequency and highfrequency theBessel prototypeis asymptotically equivalent totheButterworthprototype of the same order [1]. The magnitudeof the filter is less than

at the unity cutoff frequency Ωc =1.

Analog Bessel filters are characterized by a group delay that is maximally flatat zero frequency and almost constant throughout the passband. The groupdelay at zero frequency is

Algorithm bessel ap finds the filter roots from a look-up table constructed using theSymbolic Math Toolbox.

See Also

Al th S b li M th T lb d t ti

H s( )k

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

1 2 ⁄

2n( )!

2nn!--------------

1 n ⁄

bessel f Bessel analog filter design.

but t ap Butterworth analog lowpass filter prototype.

cheb1ap Chebyshev type I analog lowpass filter prototype.

cheb2ap Chebyshev type I I analog lowpass filter prototype.el l i pap Ell iptic analog lowpass filter prototype.

Page 308: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 308/870

7-26

Al so see the Symbolic Math Toolbox documentation.

References [1] Rabiner, L .R., and B. Gold. Theory and Application of Digital Signal

Processing. Englewood Cliffs, NJ : Prentice-Hall, 1975. Pgs. 228-230.

besself

7besself Purpose Bessel analog filter design.

Syntax [ b, a] = bessel f ( n, Wn)

[b, a] = bessel f ( n, Wn, ' f t ype' )

[ z, p, k] = bessel f ( . . . )

[A, B, C, D] = bess el f ( . . . )

Description bessel f designs lowpass, bandpass, highpass, and bandstop analog Besselfilters. Analog Bessel fi lters are characterized by almost constant group delayacross the entire passband, thus preserving the waveshape of filtered signals

in the passband. Digital B essel filters do not retain this quality, and bessel f

therefore does not support the design of digital Bessel filters.

[ b, a] =bessel f ( n, Wn) designs an order n lowpass analog filter with cutoff

frequency Wn. I t returns the filter coefficients in the length n+1 row vectors band a, with coefficients in descending powers of s, derived from the transferfunction

Cutoff frequency is thefrequency at which themagnitude response of thefilterbegins to decrease significantly. For bessel f , the cutoff frequency Wn must be

greater than 0. The magnitude responseof a Bessel filter designed by bessel f

is always less than at the cutoff frequency, and it decreases as theordern increases.

I f Wn is a two-element vector, Wn =[ w1 w2] with w1 <w2, then bessel f ( n, Wn)

returns an order 2*n bandpass analog filter with passband w1 <ω <w2.

[ b, a] =bessel f ( n, Wn, ' f t ype' ) designs a highpass or bandstop filter, where

the string ' f t ype' is:

• ' hi gh' for a highpass analog filter with cutoff frequency Wn

• ' stop' for an order 2*n bandstop analog fil ter if Wn is a two-element vector

H s( )B s( )

A s( )-----------

b 1( )sn b 2( )sn 1–L b n 1+( )+ + +

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

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

1 2 ⁄

Page 309: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 309/870

7-27

stop for an order 2 n bandstop analog fil ter if Wn is a two element vector,Wn = [ w1 w2]

The stopband is w1 <ω <w2.

besself

With different numbers of output arguments, bessel f directly obtains otherreali zationsof theanalogfilter. Toobtain zero-pole-gain form, usethree outputarguments as shown below.

[ z , p, k] = bessel f (n, Wn) or

[ z , p, k] = bessel f (n, Wn, ' f t ype' ) returns thezeros and poles in length n or

2*n column vectors z and p and the gain in the scalar k.

To obtain state-space form, use four output arguments as shown below.

[ A, B, C, D] = bessel f ( n, Wn) or

[ A, B, C, D] = bessel f ( n, Wn, ' f t ype' ) where A, B, C, and Dare

and u is the input, x is the state vector, and y is the output.

Example Design a fifth-order analog lowpass Bessel filter that suppresses frequenciesgreater than 10,000 rad/s and plot the frequency response of the filter usingf r eqs.

[ b, a] = bessel f ( 5, 10000) ;f r eqs( b, a) % Pl ot f r equency r esponse

x· Ax B u+=

y Cx Du+=

Page 310: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 310/870

7-28

besself

Limitations L owpass Bessel filters have a monotonicall y decreasing magnitude response,as do lowpass Butterworth filters. Compared to the Butterworth, Chebyshev,and elliptic filters, the Bessel filter has the slowest rolloff and requires the

highest order to meet an attenuation specification.

For high order filters, the state-space form is the most numerically accurate,followed by the zero-pole-gain form. The transfer function coefficient form isthe least accurate; numerical problems can arise for fil ter orders as low as 15.

Algorithm bessel f performs a four-step algorithm:

1 I t finds lowpass analog prototype poles, zeros, and gain using thebessel ap

function.

2 I t converts the poles, zeros, and gain into state-space form.

3 I t transformsthelowpass filter into a bandpass, highpass, or bandstop filter

with desired cutoff frequencies using a state-space transformation.

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 311: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 311/870

7-29

q g p

4 I t converts the state-space filter back to transfer function or zero-pole-gainform, as required.

besself

See Also bessel ap Bessel analog lowpass filter prototype.

but t er Butterworth analog and digital filter design.

cheby1 Chebyshev type I filter design (passband ripple).

cheby2 Chebyshev type I I filter design (stopband ripple).

el l i p Elliptic (Cauer) filter design.

Page 312: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 312/870

7-30

bilinear

7bilinearPurpose Bilinear transformation method for analog-to-digital filter conversion.

Syntax [ z d, pd, kd] = bi l i near ( z, p, k, f s)

[ zd, pd, kd] = bi l i near ( z, p, k, f s , Fp)

[ numd, dend] = bi l i near ( num, den, f s)

[ numd, dend] = bi l i near ( num, den, f s, Fp)

[ Ad, Bd, Cd, Dd] = bi l i near( A, B, C, D, f s)[ Ad, Bd, Cd, Dd] = bi l i near( A, B, C, D, f s , Fp)

Description The bilinear transformation is a mathematical mappingof variables. I n digitalfiltering, it is a standard method of mapping thes or analog plane into thez ordigital plane. I t transformsanalog filters, designed using classical filter designtechniques, into their discrete equivalents.

The bilinear transformation maps the s-plane into thez-plane by

This transformation maps the jΩ axis (from Ω =-∞ to +∞) repeatedly aroundthe unit circle ( , from ω =−π to π) by

bi l i near can accept an optional parameter Fp that specifies prewarping. Fp, inhertz, indicates a “match” frequency, that is, a frequency for which thefrequency responses before and after mapping match exactly. I n prewarpedmode, the bilinear transformation maps the s-plane into the z-plane with

H z( ) H s( )s 2f s

z 1–

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

=

e j ω

ω 2tan 1– Ω

2f

s

--------è ø =

H z( ) H s( )s

2πf p

πf pf s----è ø tan

------------------------z 1–( )z 1+( )

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

=

Page 313: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 313/870

7-31

bilinear

With the prewarping option, bi l i near maps the jΩ axis (from Ω =-∞ to +∞)repeatedly around theunit circle ( , from ω =−π to π) by

I n prewarped mode, bi l i near matches the frequency 2πf p (in radians persecond) in the s-plane to the normalized frequency 2πf p/f s (in radians persecond) in the z-plane.

The bi l i near function works with three different li near system

representations: zero-pole-gain, transfer function, and state-space form.

Zero-Pole-Gain

[ zd, pd, kd] =bi l i near ( z ,p, k, f s) and

[ zd, pd, kd] =bi l i near ( z , p, k, f s , Fp) convert the s-domain transfer functionspecified by z, p, and k to a discrete equivalent. I nputs z and p are columnvectors containing the zeros and poles,k is a scalar gain, and f s is thesamplingfrequency in hertz. bi l i near returns the discreteequivalent in column vectorszd

andpd

and scalarkd

.Fp

is the optional match frequency, in hertz, forprewarping.

Transfer Function

[ numd, dend] =bi l i near ( num, den, f s) and

[ numd, dend] =bi l i near ( num, den, f s, Fp) convert an s-domain transferfunction given bynumand den toa discreteequivalent. Row vectors numand den

specify the coefficients of the numerator and denominator, respectively, indescending powers of s.

e j ω

ω 2tan 1–Ω π

f pf s----

è ø tan

2πf p-----------------------------

è ø

=

num s( ) num 1( )snnL n um n n( )s nu m nn 1+( )+ + +

Page 314: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 314/870

7-32

num s( )

den s( )--------------------

num 1( )s n um n n( )s nu m nn 1+( )+ + +

den 1( )sndL den nd( )s den nd 1+( )+ + +

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

bilinear

f s is thesampling frequency in hertz. bi l i near returns thediscrete equivalentin row vectors numd and dend in descending powers of z (ascending powersof z-1). Fp is the optional match frequency, in hertz, for prewarping.

State-Space

[ Ad, Bd, Cd, Dd] =bi l i near( A, B, C, D, f s) and

[ Ad, Bd, Cd, Dd] =bi l i near( A, B, C, D, f s , Fp) convert the continuous-timestate-space system in matrices A, B, C, D,

to the discrete-time system

f s is thesampling frequency in hertz. bi l i near returns thediscrete equivalent

in matrices Ad, Bd, Cd, Dd. Fp is the optional match frequency, in hertz, forprewarping.

Algorithm bi l i near uses one of two algorithms depending on the format of the inputlinear system you supply. One algorithm works on the zero-pole-gain formatand the other on thestate-space format. For transfer function representations,bi l i near converts to state-space form, performs the transformation, andconverts the resulting state-space system back to transfer function form.

Zero-Pole-Gain Algorithm

For a system in zero-pole-gain form, bi l i near performs four steps:

1 I f Fp is present, k =2*pi *Fp/ t an( pi *Fp/ f s) ; otherwisek =2*f s.

2 I t strips any zeros at ±∞ using

z = z( f i nd( f i ni t e( z) ) ) ;

x· Ax B u+=

y Cx Du+=

x n 1+[ ] Adx n[ ] Bdu n[ ]+=

y n[ ] Cdx n[ ] Ddu n[ ]+=

Page 315: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 315/870

7-33

z z( f i nd( f i ni t e( z) ) ) ;

bilinear

3 I t transforms the zeros, poles, and gain using

pd = ( 1+p/ k) . / ( 1- p/ k) ;

zd = (1+z/ k) . / ( 1- z / k ) ;

kd = real (k*prod( f s- z ) . / prod( f s -p) ) ;

4 I t adds extra zeros at -1 so the resulting system has equivalent numeratorand denominator order.

State-Space Algorithm

For a system in state-space form, bi l i near performs two steps:

1 I f Fp is present, k =2*pi *Fp/ t an( pi *Fp/ f s) ; else k =2*f s.

2 I t computes Ad, Bd, Cd, and Dd in terms of A, B, C, and Dusing

bi l i near implements these relations using conventional MAT LABstatements. The scalar r is arbitrary; bi l i near uses to ensure goodquantization noise properties in the resulting system.

Diagnostics bi l i near requires that the numerator order be no greater than thedenominator order. I f this is not the case, bi l i near displays

Numerator cannot be hi gher order t han denomi nat or .

For bi l i near to distinguish between the zero-pole-gain and transfer function

linear system formats, thefirst twoinput parameters must be vectors with thesame orientation in these cases. I f this is not the case, bi l i near displays

Ad I1

k

---

è ø

A+

è ø

I1

k

---

è ø

A–

è ø

1–

=

Bd2k

r------- I

1k---

è ø A–

è ø

1–

B=

Cd r C I1k---

è ø A–è ø

1–

=

Dd1k---

è ø C I

1k---

è ø A–è ø

1–

B D+=

r 2 k ⁄ =

Page 316: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 316/870

7-34

, p y

Fi r st t wo ar gument s must have t he same or i ent at i on.

bilinear

See Also

References [1] Parks, T.W., and C.S. Burrus. Digital Filter Design. New York: J ohn Wiley

& Sons, 1987. Pgs. 209-213.

[2] Oppenheim, A.V., and R.W. Schafer. Discrete-TimeSi gnal Processing.Englewood Cliffs, NJ : Prentice-Hall, 1989. Pgs. 415-430.

i mpi nvar Analog to digital conversion using the impulseinvari ance method.

l p2bp Transform lowpass analog filters to bandpass.

l p2bs Transform lowpass analog filters to bandstop.

l p2hp Transform lowpass analog filters to highpass.

l p2l p Change the cut-off frequency for lowpass analogfilters.

Page 317: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 317/870

7-35

blackman

7blackmanPurpose Compute a Blackman window.

Syntax w = bl ackman( n)

w = bl ackman( n, ' sf l ag' )

Description w=bl ackman( n) returns then-point symmetric Blackman window in the

column vector w, where n is a positive integer.

w=bl ackman( n, ' sf l ag' ) returns an n-point Blackman window using thewindow sampling specified by ' sf l ag' , which can be either ' per i odi c' or' symmetr i c' (the default). When ' per i odi c ' is specified, bl ackman computesa length n+1 window and returns the first n points.

Note I f you specify a one-point window (set n=1), the value 1 is returned.

Algorithm The equation for computing the coefficients of a Blackman window is

Blackman windows have slightly wider central lobes and less sideband leakage

than equivalent length Hamming and Hann windows.

Examples w = bl ackman( 64) ;

pl ot ( w)

t i t l e( ' Bl ackman Wi ndow' )

w k 1+[ ] 0.42 0.5 2πk

n 1–-------------

è ø cos– 0.08 4π

k

n 1–-------------

è ø cos+ k 0= … n 1–, , ,=

Page 318: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 318/870

7-36

blackman

See Also

References [1] Oppenheim, A.V., and R.W. Schafer. Discrete-TimeSi gnal Processing.Englewood Cliffs, NJ : Prentice-Hall, 1989, pp. 447-448.

0 10 20 30 40 50 60 700

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1Blackman Window

bart l et t Compute a Bartlett window.

boxcar Compute a rectangular window.

chebwi n Compute a Chebyshev window.

hammi ng Compute a Hamming window.

hann Compute a Hann window.

kai ser Compute a K aiser window.

t r i ang Compute a triangular window.

Page 319: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 319/870

7-37

boxcar

7boxcarPurpose Compute a rectangular window.

Syntax w = boxcar( n)

Description w=boxcar ( n) returns a rectangular window of length n in thecolumn vector w. This function is provided for completeness; a rectangular window is equivalentto no window at all.

Algorithm w = ones(n, 1) ;

See Also

References [1] Oppenheim, A.V., and R.W. Schafer. Discrete-TimeSi gnal Processing.Englewood Cli ffs, NJ : Prentice-Hall, 1989, pp. 447-448.

bart l et t Compute a Bartlett window.

bl ackman Compute a Blackman window.

chebwi n Compute a Chebyshev window.

hammi ng Compute a Hamming window.

hann Compute a Hann window.

kai ser Compute a K aiser window.

t r i ang Compute a triangular window.

Page 320: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 320/870

7-38

buffer

7bufferPurpose Buffer a signal vector into a matrix of data frames.

Syntax y = buf f er ( x, n)

y = buf f er ( x, n, p)

y = buf f er ( x, n, p, opt )

[ y, z ] = buf f er ( . . . )

[ y, z, opt ] = buf f er ( . . . )

Description y =buf f er ( x, n) partitions a length-L signal vector x into nonoverl apping data

segments (frames) of length n. Each data frame occupies one column of matrixoutput y, which has n rows and cei l ( L / n) columns. I f L is not evenly divisibleby n, the last column is zero-padded to length n.

y =buf f er ( x, n, p) overlaps or underlaps successive frames in the outputmatrix by p samples:

• For 0 <p <n (overlap), buf f er repeats the final p samples of each frame atthe beginning of the following frame. For example, if x =1: 30 and n =7, anoverlap of p =3 looks like this.

The first frame starts with p zeros (the default initial condition), and the

number of columns in y is cei l ( L / ( n- p) ) .

y =

0 2 6 10 14 18 22 26

0 3 7 11 15 19 23 27

0 4 8 12 16 20 24 281 5 9 13 17 21 25 29

2 6 10 14 18 22 26 30

3 7 11 15 19 23 27 0

4 8 12 16 20 24 28 0

Page 321: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 321/870

7-39

buffer

• For p <0 (underlap), buf f er skips p samples between consecutive frames.For example, if x =1: 30 and n =7, a buffer with underlap of p =- 3 looks likethis.

The number of columns in y is cei l ( L / ( n- p) ) .

y =buf f er ( x, n, p, opt ) specifi es a vector of samples to precede x(1) in an

overlapping buffer, or thenumber of initial samples to skip in an underlappingbuffer:

• For 0 <p <n (overlap), opt specifiesa length-p vector to insert before x(1) in

thebuffer. This vector can beconsideredan initial condition, which is neededwhen the current bufferi ng operation is one in a sequence of consecutivebuffering operations. To maintain the desired frame overlap from onebufferto the next, opt should contain the final p samples of the previous buffer in

the sequence. See “Continuous Buffering” below.• By default, opt is zer os( p, 1) for an overlapping buffer. Set opt to

' nodel ay' to skip the initial condition and begin filling the bufferimmediately with x(1) . I n this case, L must be l engt h( p) or longer. Forexample, if x =1: 30 and n =7, a buffer with overlap of p =3 looks like this.

y =

1 11 21

2 12 22

3 13 234 14 24

5 15 25

6 16 26

7 17 27

8 18 289 19 29

10 20 30

skipped

y =

1 5 9 13 17 21 25

2 6 10 14 18 22 263 7 11 15 19 23 27

4 8 12 16 20 24 28

5 9 13 17 21 25 29

6 10 14 18 22 26 30

7 11 15 19 23 27 0

Page 322: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 322/870

7-40

• For p <0 (underlap), opt is an integer value in the range [ 0, - p] specifyingthenumber of initi al input samples,x(1: opt ) , toskip before adding samples

7 11 15 19 23 27 0

buffer

to thebuffer. The first valuei n thebuffer is therefore x( opt +1) . By default,opt is zero for an underlapping buffer.

This option is especially useful when the current buffering operation i s onein a sequence of consecutive buffering operations. To maintain the desiredframe underlap from one buffer to the next, opt should equal the difference

between the total number of points to skip between frames (p) and thenumber of points that were available to be skipped in the previous input tobuf f er . I f the previous input had fewer than p points that could be skippedafter fil ling the final frame of that buffer, the remaining opt points need tobe removed from the first frame of the current buffer. See “Continuous

Buffering” below for an example of how this works in practice.

[y, z] =b u f f e r ( . . . ) partitions the length-L signal vector x into frames of length n, and outputs only the full frames in y. I f y is an overlapping buffer, ithas n rows and mcolumns, where

m = f l oor ( L/ ( n- p) ) % When l engt h( opt ) =p

or

m = f l oor ( ( L- n) / ( n- p) ) +1 % When opt =' nodel ay'

I f y is an underlapping buffer, it has n rows and mcolumns, where

m = f l oor ( ( L-opt ) / ( n- p) ) + ( r em( ( L-opt ) , ( n- p) ) >= n)

I f thenumber of samples in theinput vector (after theappropriateoverlappingor underlapping operations) exceeds the number of places available in the

n-by-mbuffer, the remaining samples in x are output in vector z, which for anoverlapping buffer has length

l engt h( z) = L - m*( n- p) % When l engt h( opt ) =p

or

l engt h( z) = L - ( ( m- 1) *( n- p) +n) % When opt =' nodel ay'

and for an underlapping buffer has length

l ength( z) = ( L- opt ) - m*(n- p)

Page 323: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 323/870

7-41

buffer

Output z shares the same orientation (row or column) as x. If there are noremaining samples in the input after the buffer with the specified overlap orunderlap is filled, z is an empty vector.

[ y, z , opt ] =buf f er ( . . . ) returns thelast p samples of a overlappingbuffer in

output opt . I n an underlapping buffer, opt is the difference between the totalnumber of points toskip between frames (- p) and thenumber of points in x that

were available to be skipped after filling the last frame:

• For 0 <p <n (overlap), opt (as an output) contains thefinal p samples in thelast frame of thebuffer. This vector can be used as the initial condition for asubsequent buffering operation in a sequence of consecutive bufferingoperations. This allows thedesired frame overlap to be maintained from one

buffer to the next. See “Continuous Buffering” below.

• For p <0 (underlap), opt (as an output) is the difference between the total

number of points to skip between frames (- p) and the number of points in xthat were available to be skipped after filling the last frame.

opt = m* (n- p) + opt - L % z i s t he empt y vect or .

where opt on the right-hand sideis the input argument tobuf f er , and opt

on the left-hand side is the output argument. Here mis the number of columns in the buffer, which is

m = f l oor( ( L-opt ) / ( n- p) ) + ( rem( ( L- opt ) , ( n- p) ) >=n)

Note that for an underlapping buffer output opt is always zero whenoutput z contains data.

The opt output for an underlapping buffer is especially useful when the

current buffering operation is one in a sequence of consecutive bufferingoperations. The opt output from each buffering operation specifies thenumber of samples that need to be skipped at the start of the next bufferingoperation to maintain the desired frame underlap from one buffer to the

next. I f fewer than p points were available to be skipped after fillingthefinalframe of the current buffer, the remaining opt points need to be removed

from the first frame of the next buffer.

I n a sequence of buffering operations, the opt output from each operationshould be used as theopt input to the subsequent buffering operation This

Page 324: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 324/870

7-42

should be used as theopt input to the subsequent buffering operation. Thisensures that the desired frame overlap or underlap is maintained from buffer

buffer

to buffer, as well as from frame to frame within the same buffer. See“Continuous Buffering” below for an example of how this works in practice.

Continuous Buffering

I n a continuous buffering operation, the vector input to the buf f er functionrepresents one frame in a sequence of frames that make up a discrete signal.

Thesesignal frames can originatein a frame-based data acquisition process, or

within a frame-based algorithm like the FFT.

As an example, you might acquire data from an A/D card in frames of 64samples. I n the simplest case, you could rebuffer the data into frames of 16samples; buf f er with n =16 creates a buffer of four frames from each64-element input frame. The result is that thesignal of frame size 64 has beenconverted to a signal of frame size 16; no samples were added or removed.

I n the general case where the original signal frame size, L, is not equallydivisible by thenew frame size, n, theoverflow from thelast frame needs to becaptured and recycled into the following buffer. You can do this by iteratively

calling buf f er on input x with the two-output-argument syntax.

[ y, z] = buf f er ( [ z; x] , n) % x i s a col umn vect or .

[ y, z ] = buf f er ( [ z, x] , n) % x i s a r ow vect or .

This simply captures any buffer overflow in z, and prepends the data to thesubsequent input in thenext call tobuf f er . Again, theinput signal, x, of frame

size L, has been converted to a signal of frame sizen without any insertion ordeletion of samples.

Note that continuous buffering cannot be done with the single-output syntaxy = buf f er ( . . . ) , becausethelast frameof y in this caseis zero padded, whichadds new samples to the signal.

Continuous buffering in the presence of overlap and underlap is handled withthe opt parameter, which is used as both an input and output to buf f er . Thefollowing two examples demonstrate how the opt parameter should be used.

Page 325: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 325/870

7-43

buffer

Examples Example 1: Continuous Overlapping Buffers

First create a buffer containing 100 frames, each with 11 samples.

dat a = buf f er ( 1: 1100, 11) ; % 11 sampl es per f r ame

I magine that theframes (columns) in thematrix called data arethesequentialoutputs of a data acquisition board sampling a physical signal: dat a( : , 1) isthe first D/A output, containing the first 11 signal samples; dat a( : , 2) is thesecond output, containing the next 11 signal samples, and so on.

You want to rebuffer this signal from the acquired frame size of 11 to a framesize of 4 with an overlap of 1. To dothis, you will repeatedly call buf f er tooperate on each successive input frame, using the opt parameter to maintainconsistency in the overlap from one buffer to the next.

Set the buffer parameters.

n = 4; % New f r ame si zep = 1; % Over l ap

opt = - 5; % Val ue of y( 1)

z = [ ] ; % I ni t i al i ze t he car r y- over vect or .

Now repeatedly call buf f er , each time passing in a new signal frame fromdat a. Note that overflow samples (returned in z) are carried over andprepended to the input in the subsequent call to buf f er .

f or i =1: si ze( dat a, 2) , % Loop over each sour ce f r ame ( col umn) .

x = dat a( : , i ) ; % A si ngl e f r ame of t he D/ A out put

[ y, z, opt ] = buf f er ( [ z ; x] , n, p, opt ) ;

di sp( y) ; % Di spl ay t he buf f er of dat a.

pause

end

Page 326: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 326/870

7-44

buffer

Here’s what happens during the first four iterations.

Notethat thesizeof theoutput matrix, y, can vary by a single column from oneiteration to the next. This is typical for buffering operations with overlap orunderlap.

[1: 11]i =1

5– 3 6

1 4 7

2 5 8

3 6 9

Iteration Input frame [ z; x] ' opt (input) opt (output) Output buffer ( y) Overflow ( z)

[10 11]–5 9

i =2 [10 11 12: 22] 9 21

9 12 15 18

10 13 16 19

11 14 17 20

12 15 18 21

[22]

i =3 [22 23: 33] 21 33

21 24 27 30

22 25 28 3123 26 29 32

24 27 30 33

[ ]

33 36 39

34 37 40

35 38 41

36 39 42

[43 44]42[34: 44]i =4 33

Page 327: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 327/870

7-45

buffer

Example 2: Continuous Underlapping Buffers

Again create a buffer containing 100 frames, each with 11 samples.

dat a = buf f er ( 1: 1100, 11) ; % 11 sampl es per f r ame

Again, imagine that dat a( : , 1) is the first D/A output, containing the first 11signal samples; dat a( : , 2) is the second output, containing the next 11 signalsamples, and so on.

You want to rebuffer this signal from the acquired frame size of 11 to a framesize of 4 with an underlap of 2. To do this, you will repeatedly call buf f er tooperate on each successive input frame, using the opt parameter to maintainconsistency in the underlap from one buffer to the next.

Set the buffer parameters.

n = 4; % New f r ame si ze

p = - 2; % Under l apopt = 1; % Ski p t he f i rst i nput el ement , x( 1) .

z = [ ] ; % I ni t i al i ze t he car ry -over vector .

Now repeatedly call buf f er , each time passing in a new signal frame from

dat a. Note that overflow samples (returned in z) are carried over andprepended to the input in the subsequent call to buf f er .

f or i =1: s i ze( dat a, 2) , %Loop over each source f rame ( col umn) .

x = dat a( : , i ) ; % A si ngl e f r ame of t he D/ A out put

[ y, z, opt ] = buf f er ( [ z ; x] , n, p, opt ) ;

di sp( y) ; % Di spl ay t he buf f er of dat a.

pause

end

Page 328: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 328/870

7-46

buffer

Here’s what happens during the first three iterations.

Diagnostics Error messages are displayed when p ≥ n or l engt h( opt ) ≠ l engt h( p) in anoverlapping buffer case.

Fr ame over l ap P must be l ess t han t he buf f er si ze N.

I ni t i al condi t i ons must be speci f i ed as a l engt h- P vect or .

[1: 11]i =1

2 8

3 94 10

5 11

Iteration Input frame [z; x] ' opt (input) opt (output) Output buffer ( y) Overflow ( z)

[ ]1 2

i =2 [12: 22] 2 0

14

15

16

17

[20 21 22]

i =3 [20 21 22 23: 33] 0 0

20 26

21 27

22 28

23 29

[32 33]

6 –

7 –

1 –

18

19

12

13

– –

24 30

25 31

skip

skip

skip

skip

skip

skip

Page 329: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 329/870

7-47

See Also r eshape Reshapearray.

buttap

7buttapPurpose Butterworth analog lowpass filter prototype.

Syntax [ z , p, k] = but t ap(n)

Description [ z , p, k] =but t ap( n) returns the poles and gain of an order n Butterworthanalog lowpass filter prototype. The function returns the poles in the length n

column vector p and the gain in scalar k. z is an empty matrix because there

are no zeros. The transfer function is

Butterworth filters are characterized by a magnitude response that ismaximally flat in thepassband and monotonic overall. I n thel owpass case, thefirst 2n–1 derivatives of the squared magnitude responseare zero at ω =0. The

squared magnitude response function is

corresponding to a transfer function with poles equally spaced around a circlein the left half plane. The magnitude response at the cutoff frequency ω0 isalways regardless of thefilter order. but t ap sets ω0 to1 for a normalizedresult.

Algorithm z = [ ] ;

p = exp( sqr t ( - 1) * (pi * (1: 2: 2*n- 1) / (2*n) +pi / 2) ) . ' ;

k = r eal ( pr od( - p) ) ;

See Also

References [1] Parks, T.W., and C.S. Burrus. Digital Filter Design. New York: J ohn Wiley

H s( )z s( )

p s( )----------

k

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

H ω( ) 2 1

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

1 2 ⁄

bessel ap Bessel analog lowpass filter prototype.

but t er Butterworth analog and digital filter design.

cheb1ap Chebyshev type I analog lowpass filter prototype.cheb2ap Chebyshev type I I analog lowpass filter prototype.

el l i pap Ell iptic analog lowpass filter prototype.

Page 330: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 330/870

7-48

& Sons, 1987. Chapter 7.

butter

7butterPurpose Butterworth analog and digital filter design.

Syntax [ b, a] = but ter( n, Wn)

[b, a] = but t er ( n, Wn, ' f type' )

[b, a] = but t er ( n, Wn, ' s' )

[b, a] = but t er ( n, Wn, ' f type' , ' s' )

[ z, p, k] = but t er ( . . . )

[A, B, C, D] = but t er ( . . . )

Description but t er designs lowpass, bandpass, highpass, and bandstop digital and analogButterworth filters. Butterworth filters are characterized by a magnituderesponse that is maximally flat in the passband and monotonic overall.

Butterworth filters sacrifice rolloff steepness for monotonicity in thepass- and

stopbands. Unless the smoothness of the Butterworth filter is needed, an

elliptic or Chebyshev filter can generally providesteeper rolloff characteristicswith a lower fi lter order.

Digital Domain

[ b, a] =but t er( n, Wn) designs an order n lowpass digital Butterworth filterwith cutoff frequency Wn. I t returns the filter coefficients in length n+1 rowvectors b and a, with coefficients in descending powers of z.

Cutoff frequency is that frequency where the magnitude response of the filteris . For but t er , the normalized cutoff frequency Wn must be a numberbetween 0 and 1, where 1 corresponds to the Nyquist frequency, π radians persample.

I f Wn is a two-element vector, Wn =[ w1 w2] , but t er returns an order 2*n digitalbandpass filter with passband w1 <ω <w2.

H z( )B z( )

A z( )-----------

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

1 a 2( )z 1–L a n 1+( )z n–+ + +

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

1 2 ⁄

Page 331: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 331/870

7-49

butter

[ b, a] =but t er ( n, Wn, ' f t ype' ) designs a highpass or bandstop filter, wherethe string ' f t ype' is either:

• ' hi gh' for a highpass digital fi lter with cutoff frequency Wn

• ' stop' for an order 2*n bandstop digital filter if Wn is a two-element vector,

Wn =[ w1 w2] . The stopband is w1 <ω <w2.

With different numbers of output arguments, but t er directly obtains other

realizations of the filter. To obtain zero-pole-gain form, use three outputarguments as shown below.

[ z , p, k] =but t er( n, Wn) or

[ z , p, k] = but t er ( n, Wn, ' f type' ) returns the zeros and poles in length n

column vectors z and p, and the gain in the scalar k.

To obtain state-space form, use four output arguments as shown below.

[ A, B, C, D] =but t er( n, Wn) or

[ A, B, C, D] = but ter( n, Wn, ' f type' ) where A, B, C, and Dare

and u is the input, x is the state vector, and y is the output.

Analog Domain

[ b, a] =but t er ( n, Wn, ' s' ) designs an order n lowpass analog Butterworthfilter with cutoff frequency Wn. I t returnsthefilter coefficientsin thelength n+1

row vectors b and a, in descending powers of s, derived from the transferfunction

but t er ’s cutoff frequency Wn must be greater than 0.

I f Wn is a two-element vector with w1 <w2, but t er ( n, Wn, ' s' ) returns an order

x n 1+[ ] Ax n[ ] B u n[ ]+=

y n[ ] Cx n[ ] Du n[ ]+=

H s( )B s( )

A s( )-----------

b 1( )sn b 2( )sn 1–L b n 1+( )+ + +

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

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

Page 332: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 332/870

7-50

, ( )

2*n bandpass analog filter with passband w1 <ω <w2.

butter

[ b, a] =but t er ( n, Wn, ' f type' , ' s' ) designs a highpass or bandstop filter.

With different numbers of output arguments, but t er directly obtains otherrealizations of theanalogfilter. Toobtain zero-pole-gain form, usethreeoutputarguments as shown below.

[z , p, k] =but t er ( n, Wn, ' s' ) or

[ z , p, k] = but t er ( n, Wn, ' f t ype' , ' s' ) returns the zeros and poles in lengthn or 2*n column vectors z and p and the gain in the scalar k.

To obtain state-space form, use four output arguments as shown below.

[ A, B, C, D] =but t er ( n, Wn, ' s' ) or

[ A, B, C, D] = butt er( n, Wn, ' f type' , ' s' ) where A, B, C, and Dare

and u is the input, x is the state vector, and y is the output.

Examples Example 1

For data sampled at 1000 Hz, design a 9th-order highpass Butterworth filterwith cutoff frequency of 300 Hz.

[ b, a] = but t er ( 9, 300/ 500, ' hi gh' ) ;

The filter’s frequency response is

f r eqz( b, a, 128, 1000)

x· Ax B u+=

y Cx Du+=

Page 333: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 333/870

7-51

butter

Example 2

Design a 10th-order bandpass Butterworth filter with a passband from 100 to200 Hz and plot its impulse response, or unit sample response.

n = 5; Wn = [ 100 200] / 500;

[ b, a] = but t er ( n, Wn) ;

[ y, t ] = i mpz(b, a, 101) ;

st em( t , y)

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

−600

−400

−200

0

200

Frequency (Hz)

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

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

−300

−200

−100

0

100

Frequency (Hz)

M a g n i t u d e ( d B )

−0.2

−0.15

−0.1

−0.05

0

0.05

0.1

0.15

0.2

Page 334: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 334/870

7-52

0 10 20 30 40 50 60 70 80 90 100−0.25

butter

Limitations For high order filters, the state-space form is the most numerically accurate,

followed by the zero-pole-gain form. The transfer function coefficient form isthe least accurate; numerical problems can arise for fil ter orders as low as 15.

Algorithm but t er uses a five-step algorithm:

1 I t findsthel owpass analog prototypepoles, zeros,and gain using thebut t ap

function.2 I t converts the poles, zeros, and gain into state-space form.

3 I t transformsthelowpass filter into a bandpass, highpass, or bandstop filterwith desired cutoff frequencies, using a state-space transformation.

4 For digital filter design, but t er uses bi l i near to convert the analog filterinto a digital fil ter through a bilinear transformation with frequencyprewarping. Careful frequency adjustment guarantees that the analog

filters and the digital filters will have the same frequency responsemagnitude at Wn or w1 and w2.

5 I t converts the state-space filter back to transfer function or zero-pole-gainform, as required.

See Also bessel f Bessel analog filter design.

but t ap Butterworth analog lowpass filter prototype.

buttord Calculate the order of a Butterworth filter.

cheby1 Chebyshev type I filter design (passband ripple).

cheby2 Chebyshev type I I filter design (stopband ripple).

el l i p Elliptic (Cauer) filter design.

maxf l at Generalized Butterworth filter design.

Page 335: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 335/870

7-53

buttord

7buttordPurpose Calculate the order and cutoff frequency for a Butterworth fi lter.

Syntax [ n, Wn] = but t ord(Wp, Ws, Rp, Rs)

[ n, Wn] = but t or d( Wp, Ws, Rp, Rs, ' s' )

Description but t or d calculates theminimum order of a digital or analog Butterworth filter

required to meet a set of filter design specifications.

Digital Domain

[ n, Wn] =but t ord( Wp, Ws, Rp, Rs) returns the lowest order, n, of the digitalButterworth filter that loses no more than Rp dB in the passband and has atleast Rs dB of attenuation in the stopband. The scalar (or vector) of corresponding cutoff frequencies, Wn, is also returned. Use the outputarguments n and Wn in but t er .

Choosethe input arguments to specify thestopbandandpassbandaccording tothe following table.

Table 7-1: Description of Stopband and Passband Filter Parameters

Wp Passband corner frequency Wp, the cutoff frequency, is a scalaror a two-element vector with values between 0 and 1, with 1corresponding to the normalized Nyquist frequency, π radians

per sample.

Ws Stopband corner frequency Ws, is a scalar or a two-elementvector with values between 0 and 1, with 1 corresponding to

the normalized Nyquist frequency.

Rp Passband ripple, in decibels. This value is the maximumpermissible passband loss in decibels.

Rs Stopband attenuation, in decibels. This value is the number of decibels the stopband is down from the passband.

Page 336: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 336/870

7-54

buttord

Usethe following guide to specify filters of different types.

I f your fil ter specifications call for a bandpass or bandstop filter with unequal

ripple in each of the passbands or stopbands, design separate lowpass andhighpass filters according to the specifications in this table, and cascade thetwo filters together.

Analog Domain

[ n, Wn] =but t ord(Wp, Ws, Rp, Rs, ' s' ) finds the minimum order n and cutoff frequencies Wn for an analog Butterworth filter. You specify the frequencies Wp

and Ws similar to Table 7-1, Description of Stopband and Passband FilterParameters, only in this case you specify the frequency in radians per second,and the passband or the stopband can be infinite.

Usebut t or d for lowpass, highpass, bandpass,andbandstopfilters asdescri bedin Table 7-2, F ilter Type Stopband and Passband Specifications.

Table 7-2: Filter Type Stopband and Passband Specifications

Filter Type Stopband and Passband Conditions Stopband Passband

Lowpass Wp <Ws, both scalars ( Ws, 1) ( 0, Wp)

Highpass Wp >Ws, both scalars( 0, Ws) ( Wp, 1)

Bandpass Theinterval specified by Ws contains

the one specified by Wp

(Ws(1) < Wp( 1) < Wp( 2) < Ws(2) ).

( 0, Ws( 1) )

and( Ws( 2) , 1)

( Wp(1) , Wp(2) )

Bandstop Theinterval specified by Wp contains

the one specified by Ws

(Wp( 1) < Ws(1) < Ws(2) < Wp( 2) ).

( 0, Wp( 1) )

and( Wp( 2) , 1)

( Ws( 1) , Ws( 2) )

Page 337: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 337/870

7-55

buttord

Examples Example 1

For data sampled at 1000 Hz, design a lowpass filter with less than 3 dB of ripple in the passband, defined from 0 to 40 Hz, and at least 60 dB of attenuation in the stopband, defined from 150 Hz to the Nyquist frequency(500 Hz). Plot the filter’s frequency response.

Wp = 40/ 500; Ws = 150/ 500;

[ n, Wn] = but t or d( Wp, Ws, 3, 60)

n =

5

Wn =

0. 0810

[ b, a] = but t er ( n, Wn) ;

f r eqz( b, a, 512, 1000) ; t i t l e( ' n=5 But t er wor t h Lowpass Fi l t er ' )

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

−400

−300

−200

−100

0

Frequency (Hz)

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

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

−300

−200

−100

0

100

Frequency (Hz)

M a g n i t u d e ( d B )

n=5 Butterworth Lowpass Filter

Page 338: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 338/870

7-56

buttord

Example 2

Next design a bandpass filter with passband of 60 Hz to200 Hz, with less than3 dB of ripple in thepassband, and 40 dB attenuation in thestopbandsthat are50 Hz wide on both sides of the passband.

Wp = [ 60 200] / 500; Ws = [ 50 250] / 500;

Rp = 3; Rs = 40;

[ n, Wn] = but t or d( Wp, Ws, Rp, Rs)

n =

16

Wn =

0. 1198 0. 4005

[ b, a] = but t er ( n, Wn) ;

f r eqz( b, a, 128, 1000)

t i t l e( ' n=16 But t er wor t h Bandpass Fi l t er ' )

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

−2000

−1500

−1000

−500

0

500

Frequency (Hz)

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

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

−400

−300

−200

−100

0

100

Frequency (Hz)

M a g n i t u d e ( d B )

n=16 Butterworth Bandpass Filter

Page 339: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 339/870

7-57

buttord

Algorithm but t or d’s order prediction formula is described in [1]. I t operates in theanalog

domain for both analog and digital cases. F or the digital case, it converts thefrequency parameters to the s-domain before estimating the order and naturalfrequency, and then converts back to the z-domain.

but t or d initially develops a lowpass filter prototype by transforming thepassband frequencies of the desired filter to 1 rad/s (for lowpass and highpassfilters) and to -1 and 1 rad/s (for bandpass and bandstop filters). I t thencomputes theminimum order required for a lowpassfil ter tomeet thestopbandspecification.

See Also

References [1] Rabiner, L .R., and B. Gold. Theory and Application of Digital Signal

Processing. Englewood Cliffs, NJ : Prentice-Hall, 1975. Pg. 227.

but t er Design a Butterworth analog or digital filter.

cheb1ord Calculate the order for a Chebyshev type I filter.

cheb2ord Calculate the order for a Chebyshev type I I filter.

el l i pord Calculate the order for an elliptic filter.

kai ser or d Estimate K aiser window FI R filter parameters.

Page 340: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 340/870

7-58

cceps

7ccepsPurpose Complex cepstral analysis.

Syntax xhat = cceps(x)

[ xhat , nd] = cceps(x)

[ xhat , nd, xhat 1] = cceps(x)

[ . . . ] = cceps( x, n)

Description Cepstral analysis is a nonlinear signal processing technique that is appliedmost commonly in speech processing and homomorphic filtering [1].

xhat =cceps( x) returns the complex cepstrum of the (assumed real)

sequence x. The input is altered, by the application of a linear phase term, tohave no phasediscontinuity at ±π radians. That is, it is circularly shifted (afterzero padding) by somesamples, if necessary, to have zero phase at π radians.

[ xhat , nd] =cceps( x) returns the number of samples nd of (circular) delayadded to x prior to finding the complex cepstrum.

[ xhat , nd, xhat 1] =cceps(x) returns a second complex cepstrum, computedusing an alternate rooting algorithm, in xhat1. The alternate method([1] p.795) is useful for short sequences that can berooted anddonot havezeroson the unit circle. For these signals, xhat1 can provide a verification of xhat .

[ . . . ] =cceps( x, n) zero pads x to length n and returns the length n complexcepstrum of x.

Algorithm cceps, in i ts basic form, is an M -file implementation of algorithm 7.1 in [2]. A

lengthy Fortran program reduces to three lines of M AT LAB code:

h = f f t ( x) ;

l ogh = l og( abs( h) ) +sqr t ( - 1) *rcunwr ap( angl e( h) ) ;

y = r eal ( i f f t ( l ogh) ) ;

r cunwr ap is a special version of unwr ap that subtracts a straight line from thephase.

Page 341: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 341/870

7-59

cceps

See Also

References [1] Oppenheim, A.V., and R.W. Schafer. Discrete-TimeSi gnal Processing.

Englewood Cli ffs, NJ : Prentice-Hall, 1989.[2]IEEE. Pr ograms for Digital Signal Pr ocessing. I EE E Press. New York: J ohn

Wiley & Sons, 1979.

i cceps I nverse complex cepstrum.

hi l bert Hilbert transform.

r ceps Real cepstrum and minimum phase reconstruction.

unwr ap Unwrap phase angles.

Page 342: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 342/870

7-60

cell2sos

7cell2sosPurpose Convert a cell array for second-order sections to a second-order section matrix.

Syntax m = cel l 2sos(c )

Description m = cel l 2sos(c ) changes a 1-by-L cell array c consisting of 1-by-2 cell arraysintoan L -by-6 second-order section matrix m. Matrix mtakes the same form asthe matrix generated by t f 2sos. You can use m = cel l 2sos(c ) to invert the

results of c =sos2cel l ( m) .

c must be a cell array of the form

c = b1 a1 b2 a2 . . . bL aL

whereboth bi and ai are row vectors of at most length 3, and i =1, 2, ..., L .The

resulting matrix mis given by

m = [ b1 a1; b2 a2; . . . ; bL aL]

See Also sos2cel l Convert second-order section matrices to cell arrays.

t f 2sos Convert transfer functions to second-order sections.

Page 343: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 343/870

7-61

cheb1ap

7cheb1apPurpose Chebyshev type I analog lowpass filter prototype.

Syntax [ z, p, k] = cheb1ap( n, Rp)

Description [ z , p, k] =cheb1ap( n, Rp) returns thepoles and gain of an order n Chebyshevtype I analoglowpass filter prototype with Rp dB of ripple in thepassband. Thefunction returns the poles in the length n column vector p and the gain in

scalar k. z is an empty matrix, because there are no zeros. The transferfunction is

Chebyshev type I filters are equiripple in the passband and monotonic in thestopband. The poles are evenly spaced about an ellipse in the left half plane. The Chebyshev type I cutoff frequency is set to 1.0 for a normalized result.

This is thefrequency at which thepassband ends and thefilter has magnituderesponse of 10-Rp/20.

See Also

References [1] Parks, T.W., and C.S. Burrus. Digital Filter Design. New York: J ohn Wiley& Sons, 1987. Chapter 7.

H s( )z s( )

p s( )----------

k

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

ω0

bessel ap Bessel analog lowpass filter prototype.

but t ap Butterworth analog and digital filter design.

cheb2ap Chebyshev type I analog lowpass filter prototype.

cheby1 Chebyshev type I filter design (passband ripple).

el l i pap Ell iptic analog lowpass filter prototype.

Page 344: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 344/870

7-62

cheb1ord

7cheb1ordPurpose Calculate the order for a Chebyshev type I filter.

Syntax [ n, Wn] = cheb1or d( Wp, Ws, Rp, Rs)

[ n, Wn] = cheb1or d( Wp, Ws, Rp, Rs, ' s' )

Description cheb1ord calculates theminimum order of a digital or analog Chebyshev type I

filter required to meet a set of filter design specifications.

Digital Domain

[ n, Wn] =cheb1or d(Wp, Ws, Rp, Rs) returns thelowest order n of the Chebyshevtype I filter that loses no more than Rp dB in the passband and has at leastRs dB of attenuation in the stopband. The scalar (or vector) of corresponding

cutoff frequencies Wn, is also returned. Usethe output arguments n and Wn withthe cheby1 function.

Choosethe input arguments to specify thestopbandandpassband according tothe following table.

Table 7-3: Description of Stopband and Passband Filter Parameters

Wp Passband corner frequency Wp, the cutoff frequency, is a scalaror a two-element vector with values between 0 and 1, with 1corresponding to the normalized Nyquist frequency, π radians

per sample.

Ws Stopband corner frequency Ws, is a scalar or a two-elementvector with values between 0 and 1, with 1 corresponding to

the normalized Nyquist frequency.

Rp Passband ripple, in decibels. This value is the maximumpermissible passband loss in decibels.

Rs Stopband attenuation, in decibels. This value is the number of decibels the stopband is down from the passband.

Page 345: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 345/870

7-63

cheb1ord

Use the following guide to specify filters of different types.

I f your fil ter specifications call for a bandpass or bandstop filter with unequal

ripple in each of the passbands or stopbands, design separate lowpass andhighpass filters according to the specifications in this table, and cascade thetwo filters together.

Analog Domain

[ n, Wn] =cheb1ord(Wp, Ws, Rp, Rs, ' s' ) finds the minimum order n and cutoff frequencies Wn for an analog Chebyshev type I filter. Y ou specify thefrequencies Wp and Ws similar to Table 7-3, Description of Stopband andPassband Fil ter P arameters, only in this case you specify the frequency inradians per second, and the passband or the stopband can be infinite.

Usecheb1ord for lowpass, highpass, bandpass, and bandstop filters asdescribed in Table 7-4, Filter Type Stopband and Passband Specifications.

Examples For data sampled at 1000 Hz, design a lowpass filter with less than 3 dB of

ripple in the passband defined from 0 to 40 Hz and at least 60 dB of ri pple inthe stopband defined from 150 Hz to the Nyquist frequency (500 Hz).

Wp = 40/ 500; Ws = 150/ 500;

Rp = 3; Rs = 60;

[ n, Wn] = cheb1or d( Wp, Ws, Rp, Rs)

Table 7-4: Filter Type Stopband and Passband Specifications

Filter Type Stopband and Passband Conditions Stopband Passband

Lowpass Wp <Ws, both scalars ( Ws, 1) ( 0, Wp)

Highpass Wp >Ws, both scalars ( 0, Ws) ( Wp, 1)

Bandpass Theinterval specified by Ws contains

the one specified by Wp

(Ws(1) < Wp( 1) < Wp( 2) < Ws(2) ).

( 0, Ws( 1) )

and( Ws( 2) , 1)

( Wp(1) , Wp( 2))

Bandstop Theinterval specified by Wp contains

the one specified by Ws

(Wp( 1) < Ws(1) < Ws(2) < Wp( 2) ).

( 0, Wp( 1) )

and( Wp( 2) , 1)

( Ws( 1) , Ws( 2) )

Page 346: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 346/870

7-64

cheb1ord

n =

4

Wn =

0. 0800

[ b, a] = cheby1( n, Rp, Wn) ;

f r eqz( b, a, 512, 1000) ;

t i t l e( ' n=4 Chebyshev Type I Lowpass Fi l t er ' )

Next design a bandpass filter with a passband of 60 Hz to 200 Hz, with lessthan 3 dB of ripple in the passband, and 40 dB attenuation in the stopbandsthat are 50 Hz wide on both sides of the passband.

Wp = [ 60 200] / 500; Ws = [ 50 250] / 500;

Rp = 3; Rs = 40;

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

n =7

Wn =

0. 1200 0. 4000

[ b, a] = cheby1( n, Rp, Wn) ;

f r eqz( b, a, 512, 1000) ;

t i t l e( ' n=7 Chebyshev Type I Bandpass Fi l t er ' )

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

−300

−200

−100

0

Frequency (Hz)

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

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

−250

−200

−150

−100

−50

0

Frequency (Hz)

M a g n i t u d e ( d B )

n=4 Chebyshev Type I Lowpass Filter

Page 347: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 347/870

7-65

cheb1ord

Algorithm cheb1ord uses theChebyshev lowpassfil ter order prediction formula describedin [1]. The function performs its calculations in the analog domain for bothanalog and digital cases. For the digital case, it converts the frequencyparameters to the s-domain before the order and natural frequency estimationprocess, and then converts them back to the z-domain.

cheb1ord initially develops a lowpass filter prototype by transforming thepassband frequencies of thedesired filter to1 rad/s (for low- or highpassfilters)or to -1 and 1 rad/s (for bandpass or bandstop filters). I t then computes theminimum order required for a lowpass filter to meet the stopband specification.

See Also

References [1] Rabiner, L .R., and B. Gold. Theory and Application of Digital Signal

Processing. Englewood Cliffs, NJ : Prentice-Hall, 1975. Pg. 241.

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

−1000

−500

0

500

Frequency (Hz)

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

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

−400

−300

−200

−100

0

Frequency (Hz)

M a g n i t u d e ( d B )

n=7 Chebyshev Type I Bandpass Filter

but t or d Calculate the order for a Butterworth filter.

cheby1 Design a Chebyshev type I filter (passband ripple).

cheb2ord Calculate the order for a Chebyshev type I I filter.

el l i pord Calculate the order for an elliptic filter.

kai ser or d Estimate K aiser window FI R filter parameters.

Page 348: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 348/870

7-66

cheb2ap

7cheb2apPurpose Chebyshev type I I analog lowpass filter prototype.

Syntax [ z , p, k] = cheb2ap( n, Rs)

Description [z , p, k] =cheb2ap( n, Rs) finds the zeros, poles, and gain of an order n

Chebyshev type I I analog lowpass filter prototype with stopband ripple Rs dBdown from the passband peak value. cheb2ap returns the zeros and poles in

length n column vectors z and p and the gain in scalar k. I f n is odd, z is lengthn- 1. The transfer function is

Chebyshev typeI I filters are monotonic in the passband and equiripple in thestopband. The pole locations are the inverse of the pole locations of cheb1ap,whose poles are evenly spaced about an ellipse in the left half plane. The

Chebyshev type I I cutoff frequency ω0 is set to 1 for a normalized result. Thisis the frequency at which the stopband begins and the filter has magnituderesponse of 10-Rs/20.

Algorithm Chebyshev type I I filters are sometimes called inverseChebyshev filtersbecause of their relationship to Chebyshev type I filters. Thecheb2ap functionis a modification of the Chebyshev type I prototype algorithm:

1 cheb2ap replaces the frequency variable ω with 1/ω, turning the lowpassfilter into a highpass filter while preserving the performance at ω =1.

2 cheb2ap subtracts the filter transfer function from unity.

See Also

References [1] Parks, T.W., and C.S. Burrus. Digital Filter Design. New York: J ohn Wiley& Sons, 1987. Chapter 7.

H s( )z s( )

p s( )---------- k

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

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

bessel ap Bessel analog lowpass filter prototype.

but t ap Butterworth analog lowpass filter prototype.

cheb1ap Chebyshev type I analog lowpass filter prototype.

cheby2 Chebyshev type I I filter design (stopband ripple).

el l i pap Elliptic analog lowpass filter prototype.

Page 349: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 349/870

7-67

cheb2ord

7cheb2ordPurpose Calculate the order for a Chebyshev type I I filter.

Syntax [ n, Wn] = cheb2or d( Wp, Ws, Rp, Rs)

[ n, Wn] = cheb2or d( Wp, Ws, Rp, Rs, ' s' )

Description cheb2ord calculates the minimum order of a digital or analog Chebyshev

type I I filter required to meet a set of filter design specifications.

Digital Domain

[ n, Wn] =cheb2ord( Wp, Ws, Rp, Rs) returns thelowest order n of the Chebyshevtype I I filter that l oses no more than Rp dB in the passband and has at leastRs dB of attenuation in the stopband. The scalar (or vector) of correspondingcutoff frequencies Wn, is also returned. Use the output arguments n and Wn incheby2.

Choosethe input arguments to specify thestopbandandpassband according tothe following table.

Table 7-5: Description of Stopband and Passband Filter Parameters

Wp Passband corner frequency Wp, the cutoff frequency, is a scalaror a two-element vector with values between 0 and 1, with 1corresponding to the normalized Nyquist frequency, π radians

per sample.

Ws Stopband corner frequency Ws, is a scalar or a two-elementvector with values between 0 and 1, with 1 corresponding to

the normalized Nyquist frequency.

Rp Passband ripple, in decibels. This value is the maximumpermissible passband loss in decibels.

Rs Stopband attenuation, in decibels. This value is the number of decibels the stopband is down from the passband.

Page 350: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 350/870

7-68

cheb2ord

Usethe following guide to specify filters of different types.

I f your fil ter specifications call for a bandpass or bandstop filter with unequal

ripple in each of the passbands or stopbands, design separate lowpass andhighpass filters according to the specifications in this table, and cascade thetwo filters together.

Analog Domain

[ n, Wn] =cheb2ord(Wp, Ws, Rp, Rs, ' s' ) finds the minimum order n and cutoff frequencies Wn for an analog Chebyshev type I I filter. You specify thefrequencies Wp and Ws similar to Table 7-5, Description of Stopband andPassband Filter P arameters, only in this caseyou specify the frequency inradians per second, and the passband or the stopband can be infinite.

Usecheb2ord for lowpass, highpass, bandpass, and bandstop filters asdescribed in Table 7-6, Filter Type Stopband and Passband Specifications.

Table 7-6: Filter Type Stopband and Passband Specifications

Filter Type Stopband and Passband Conditions Stopband Passband

Lowpass Wp <Ws, both scalars ( Ws, 1) ( 0, Wp)

Highpass Wp >Ws, both scalars ( 0, Ws) ( Wp, 1)

Bandpass Theinterval specified by Ws contains

the one specified by Wp

(Ws(1) < Wp( 1) < Wp( 2) < Ws(2) ).

( 0, Ws( 1) )

and( Ws( 2) , 1)

( Wp(1) , Wp(2) )

Bandstop Theinterval specified by Wp contains

the one specified by Ws

(Wp( 1) < Ws(1) < Ws(2) < Wp( 2) ).

( 0, Wp( 1) )

and( Wp( 2) , 1)

( Ws( 1) , Ws( 2) )

Page 351: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 351/870

7-69

cheb2ord

Examples Example 1

For data sampled at 1000 Hz, design a lowpass filter with less than 3 dB of ripple in the passband defined from 0 to 40 Hz, and at least 60 dB of attenuation in the stopband defined from 150 Hz to the Nyquist frequency(500 Hz).

Wp = 40/ 500; Ws = 150/ 500;

Rp = 3; Rs = 60;

[ n, Wn] = cheb2or d( Wp, Ws, Rp, Rs)

n =

4

Wn =

0. 2597

[ b, a] = cheby2( n, Rs, Wn) ;

f r eqz( b, a, 512, 1000) ;t i t l e( ' n=4 Chebyshev Type I I Lowpass Fi l t er ' )

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

−300

−200

−100

0

100

Frequency (Hz)

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

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

−100

−80

−60

−40

−20

0

Frequency (Hz)

M a g n i t u d e ( d B )

n=4 Chebyshev Type II Lowpass Filter

Page 352: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 352/870

7-70

cheb2ord

Example 2

Next design a bandpass filter with a passband of 60 Hz to 200 Hz, with lessthan 3 dB of ripple in the passband, and 40 dB attenuation in the stopbandsthat are 50 Hz wide on both sides of the passband.

Wp = [ 60 200] / 500; Ws = [ 50 250] / 500;

Rp = 3; Rs = 40;

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

n =

7

Wn =

0. 1019 0. 4516

[ b, a] = cheby2( n, Rs, Wn) ;

f r eqz( b, a, 512, 1000)

t i t l e( ' n=7 Chebyshev Type I I Bandpass Fi l t er ' )

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

−200

0

200

400

Frequency (Hz)

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

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

−250

−200

−150

−100

−50

0

50

Frequency (Hz)

M a g n i t u d e ( d B )

n=7 Chebyshev Type II Bandpass Filter

Page 353: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 353/870

7-71

cheb2ord

Algorithm cheb2ord uses theChebyshev lowpassfil ter order prediction formula described

in [1]. The function performs its calculations in the analog domain for bothanalog and digital cases. For the digital case, it converts the frequencyparameters to the s-domain before the order and natural frequency estimationprocess, and then converts them back to the z-domain.

cheb2ord initially develops a lowpass filter prototype by transforming thestopband frequencies of the desired filter to 1 rad/s (for low- and highpass

filters) and to -1 and 1 rad/s (for bandpass and bandstop filters). I t thencomputes the minimum order required for a lowpass fil ter to meet thepassband specification.

See Also

References [1] Rabiner, L .R., and B. Gold. Theory and Application of Digital Signal

Processing. Englewood Cliffs, NJ : Prentice-Hall, 1975. Pg. 241.

but t or d Calculate the order for a Butterworth filter.

cheb1ord Calculate the order for a Chebyshev type I filter.

cheby2 Design a Chebyshev type I I filter (stopband ripple).

el l i pord Calculate the order for an elliptic filter.

kai ser or d Estimate K aiser window FI R filter parameters.

Page 354: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 354/870

7-72

chebwin

7chebwinPurpose Compute a Chebyshev window.

Syntax w = chebwi n( n, r)

Description w=chebwi n( n, r ) returns the column vector wcontaining the length n

Chebyshev window whoseFourier transform sidelobe magnitude is r dB belowthe mainlobe magnitude.

Note I f you specify a one-point window (set n=1), the value 1 is returned.

Examples w = chebwi n( 64, 100) ;

pl ot ( w)

t i t l e( ' Chebyshev Wi ndow' )

0 10 20 30 40 50 60 700

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1Chebyshev Window

Page 355: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 355/870

7-73

chebwin

See Also

References [1]IEEE. Pr ograms for Digital Signal Pr ocessing. I EE E Press. New York: J ohnWiley & Sons, 1979. Program 5.2.

bart l et t Compute a Bartlett window.

bl ackman Compute a Blackman window.

boxcar Compute a rectangular window.

hammi ng Compute a Hamming window.

hann Compute a Hann window.

kai ser Compute a K aiser window.

t r i ang Compute a triangular window.

Page 356: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 356/870

7-74

cheby1

7cheby1Purpose Chebyshev type I filter design (passband ripple).

Syntax [ b, a] = cheby1( n, Rp, Wn)

[ b, a] = cheby1( n, Rp, Wn, ' f t ype' )

[ b, a] = cheby1( n, Rp, Wn, ' s' )

[ b, a] = cheby1( n, Rp, Wn, ' f t ype' , ' s' )

[ z , p, k] = cheby1( . . . )

[A, B, C, D] = cheby1( . . . )

Description cheby1 designs lowpass, bandpass, highpass, and bandstop digital and analogChebyshev type I filters. Chebyshev type I filters are equiripple in thepassband and monotonic in the stopband. Type I filters roll off faster thantype I I filters, but at the expense of greater deviation from unity in thepassband.

Digital Domain

[ b, a] =cheby1( n, Rp, Wn) designs an order n lowpass digital Chebyshev filterwith cutoff frequency Wn and Rp dB of ripple in the passband. I t returns thefilter coefficients in the length n+1 row vectors b and a, with coefficients in

descending powers of z.

Cutoff frequency is thefrequency at which themagnitude response of thefilteris equal to - Rp dB. For cheby1, the cutoff frequency Wn is a number between 0

and 1, where 1 corresponds to the Nyquist frequency, π radians per sample.Smaller valuesof passband ripple Rp leadtowider transition widths (shallowerrolloff characteristics).

I f Wn is a two-element vector, Wn =[ w1 w2] , cheby1 returns an order 2*n

bandpass filter with passband w1 < <w2.

H z( )B z( )

A z( )

-----------b 1( ) b 2( )z 1–

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

1 a 2( )z 1–L

a n 1+( )z n–+ + +

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

ω

Page 357: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 357/870

7-75

cheby1

[ b, a] =cheby1(n, Rp, Wn, ' f t ype' ) designs a highpass or bandstop filter,where the string ' f t ype' is either:

• ' hi gh' for a highpass digital fi lter with cutoff frequency Wn

• ' stop' for an order 2*n bandstop digital filter if Wn is a two-element vector,

Wn =[ w1 w2]

The stopband is w1 <ω <w2.

With different numbers of output arguments, cheby1 directly obtains otherrealizations of the filter. To obtain zero-pole-gain form, use three outputarguments as shown below.

[ z , p, k] =cheby1(n, Rp, Wn) or

[ z , p, k] =cheby1( n, Rp, Wn, ' f t ype' ) returns the zeros and poles in length n

column vectors z and p and the gain in the scalar k.

To obtain state-space form, use four output arguments as shown below.

[ A, B, C, D] =cheby1(n, Rp, Wn) or

[ A, B, C, D] =cheby1(n, Rp, Wn, ' f t ype' ) where A, B, C, and Dare

and u is the input, x is the state vector, and y is the output.

Analog Domain

[ b, a] =cheby1(n, Rp, Wn, ' s' ) designs an order n lowpass analog ChebyshevtypeI filter with cutoff frequency Wn. I t returns thefilter coefficients in lengthn+1 row vectors b and a, in descending powers of s, derived from the transfer

function

Cutoff frequency is the frequency at which the magnituderesponse of thefilteris -Rp dB. For cheby1, the cutoff frequency Wn must be greater than 0.

x n 1+[ ] Ax n[ ] B u n[ ]+=

y n[ ] Cx n[ ] Du n[ ]+=

H s( )B s( )

A s( )-----------

b 1( )sn b 2( )sn 1–L b n 1+( )+ + +

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

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

Page 358: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 358/870

7-76

cheby1

I f Wn is a two-element vector Wn =[ w1 w2] with w1 <w2, thencheby1( n, Rp, Wn, ' s' ) returns an order 2*n bandpass analog filter withpassband w1 <ω <w2.

[ b, a] =cheby1(n, Rp, Wn, ' f type' , ' s' ) designs a highpass or bandstop filter.

You can supply different numbers of output arguments for cheby1 to directlyobtain other realizations of theanalog filter. To obtain zero-pole-gain form, use

three output arguments as shown below.

[z , p, k] =cheby1(n, Rp, Wn, ' s' ) or

[ z , p, k] = cheby1( n, Rp, Wn, ' f t ype' , ' s' ) returns the zeros and poles inlength n or 2*n column vectors z and p and the gain in the scalar k.

To obtain state-space form, use four output arguments as shown below.

[ A, B, C, D] =cheby1( n, Rp, Wn, ' s' ) or

[ A, B, C, D] =cheby1( n, Rp, Wn, ' f t ype' , ' s' ) where A, B, C, and Dare definedas

and u is the input, x is the state vector, and y is the output.

Examples For data sampled at 1000 Hz, design a 9th-order lowpass Chebyshev type Ifilter with 0.5 dB of ripple in the passband and a cutoff frequency of 300 Hz.

[ b, a] = cheby1( 9, 0. 5, 300/ 500) ;

The frequency response of the filter is

f r eqz( b, a, 512, 1000)

x· Ax B u+=

y Cx Du+=

Page 359: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 359/870

7-77

cheby1

Design a 10th-order bandpass Chebyshev type I filter with a passband from100 to 200 Hz and plot its impulse response.

n = 10; Rp = 0. 5;

Wn = [ 100 200] / 500;

[ b, a] = cheby1( n, Rp, Wn) ;

[ y, t ] = i mpz(b, a, 101) ; stem( t , y)

0 50 100 150 200 250 300 350 400 450 500-1000

-800

-600

-400

-200

0

Frequency (Hertz)

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

0 50 100 150 200 250 300 350 400 450 500-300

-200

-100

0

100

Frequency (Hertz)

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

n = 9 Chebyshev Type I Lowpass Filter

0 10 20 30 40 50 60 70 80 90 100-0.2

-0.15

-0.1

-0.05

0

0.05

0.1

0.15Impulse Response of n = 10 Chebyshev Type I Filter

Page 360: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 360/870

7-78

cheby1

Limitations For high order filters, the state-space form is the most numerically accurate,followed by the zero-pole-gain form. The transfer function form is the leastaccurate; numerical problems can arise for fil ter orders as low as 15.

Algorithm cheby1 uses a five-step algorithm:

1 I t finds the lowpass analog prototype poles, zeros, and gain using thecheb1ap function.

2 I t converts the poles, zeros, and gain into state-space form.

3 I t transformsthelowpass filter into a bandpass, highpass, or bandstop filterwith desired cutoff frequencies, using a state-space transformation.

4 For digital filter design, cheby1 uses bi l i near to convert the analog filterinto a digital fil ter through a bilinear transformation with frequencyprewarping. Careful frequency adjustment guarantees that the analog

filters and the digital filters will have the same frequency response

magnitude at Wn or w1 and w2.5 I t converts the state-space filter back to transfer function or zero-pole-gain

form, as required.

See Also bessel f Bessel analog filter design.

but t er Butterworth analog and digital filter design.

cheb1ap Chebyshev type I analog lowpass filter prototype.

cheb1ord Calculate the order of a Chebyshev type I filter.

cheby2 Chebyshev type I I filter design (stopband ripple).

el l i p Elliptic (Cauer) filter design.

Page 361: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 361/870

7-79

cheby2

7cheby2Purpose Chebyshev type I I filter design (stopband ripple).

Syntax [ b, a] = cheby2( n, Rs, Wn)

[ b, a] = cheby2( n, Rs, Wn, ' f t ype' )

[ b, a] = cheby2( n, Rs, Wn, ' s' )

[ b, a] = cheby2( n, Rs, Wn, ' f t ype' , ' s' )

[ z , p, k] = cheby2( . . . )

[ A, B, C, D] = cheby2( . . . )

Description cheby2 designs lowpass, highpass, bandpass, and bandstop digital and analogChebyshev type I I filters. Chebyshev type I I filters are monotonic in thepassband and equiripple in the stopband. Type I I filters do not roll off as fastas type I fi lters, but are free of passband ripple.

Digital Domain

[ b, a] =cheby2(n, Rs, Wn) designs an order n lowpass digital Chebyshev typeI I filter with cutoff frequency Wn andstopbandripple Rs dB down from thepeakpassband value. I t returns the filter coefficients in the length n+1 row vectorsb and a, with coefficients in descending powers of z.

Cutoff frequency is the beginning of the stopband, where the magnituderesponse of the filter is equal to - Rs dB. For cheby2, the normalized cutoff frequency Wn is a number between 0 and 1, where 1 corresponds to theNyquist

frequency. L arger values of stopband attenuation Rs lead to wider transitionwidths (shallower rolloff characteristics).

I f Wn is a two-element vector, Wn =[ w1 w2] , cheby2 returns an order 2*n

bandpass filter with passband w1 <ω <w2.

[ b, a] =cheby2(n, Rs, Wn, ' f t ype' ) designs a highpass or bandstop filter,where the string ' f t ype' is either:

• ' hi gh' for a highpass digital fi lter with cutoff frequency Wn

• ' stop' for an order 2*n bandstop digital filter if Wn is a two-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 362: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 362/870

7-80

cheby2

With different numbers of output arguments, cheby2 directly obtains otherrealizations of the fil ter. To obtain zero-pole-gain form, use threeoutputarguments as shown below.

[z , p, k] =cheby2(n, Rs, Wn) or

[z , p, k] =cheby2(n, Rs, Wn, ' f t ype' ) returns the zeros and poles in length n

column vectors z and p and the gain in the scalar k.

To obtain state-space form, use four output arguments as shown below.

[ A, B, C, D] =cheby2(n, Rs, Wn) or

[ A, B, C, D] =cheby2( n, Rs, Wn, ' f t ype' ) where A, B, C, and Dare

and u is the input, x is the state vector, and y is the output.

Analog Domain

[ b, a] =cheby2( n, Rs, Wn, ' s' ) designs an order n lowpass analog Chebyshevtype I I filter with cutoff frequency Wn. I t returns the filter coefficients in thelength n+1 row vectors b and a, with coefficients in descending powers of s,

derived from the transfer function.

Cutoff frequency is thefrequency at which themagnitude response of thefilteris equal to - Rs dB. For cheby2, the cutoff frequency Wn must begreater than 0.

I f Wn is a two-element vector Wn =[ w1 w2] with w1 <w2, then

cheby2( n, Rs, Wn, ' s' ) returns an order 2*n bandpass analog filter withpassband w1 <ω <w2.

[ b, a] =cheby2( n, Rs, Wn, ' f type' , ' s' ) designs a highpass or bandstop filter.

With different numbers of output arguments, cheby2 directly obtains otherrealizations of theanalogfilter. Toobtain zero-pole-gain form, usethreeoutputarguments as shown below.

x n 1+[ ] Ax n[ ] B u n[ ]+=

y n[ ] Cx n[ ] Du n[ ]+=

H s( )B s( )

A s( )-----------

b 1( )sn b 2( )sn 1–L b n 1+( )+ + +

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

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

Page 363: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 363/870

7-81

cheby2

[ z , p, k] =cheby2( n, Rs, Wn, ' s' ) or

[ z , p, k] =cheby2( n, Rs, Wn, ' f t ype' , ' s' ) returns the zeros and poles inlength n or 2*n column vectors z and p and the gain in the scalar k.

To obtain state-space form, use four output arguments as shown below.

[ A, B, C, D] =cheby2( n, Rs, Wn, ' s' ) or

[ A, B, C, D] =cheby2( n, Rs, Wn, ' f t ype' , ' s' ) where A, B, C, and Dare

and u is the input, x is the state vector, and y is the output.

Examples For data sampled at 1000 Hz, design a ninth-order lowpass Chebyshev type I I

filter with stopband attenuation 20 dB down from the passband and a cutoff frequency of 300 Hz.

[ b, a] = cheby2( 9, 20, 300/ 500) ;

The frequency response of the filter is

f r eqz( b, a, 512, 1000)

x· Ax B u+=

y Cx Du+=

0 50 100 150 200 250 300 350 400 450 500-400

-300

-200

-100

0

100

Frequency (Hertz)

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

0 50 100 150 200 250 300 350 400 450 500-80

-60

-40

-20

0

20

Frequency (Hertz)

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

n = 9 Chebyshev Type II Filter

Page 364: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 364/870

7-82

cheby2

Design a fifth-order bandpass Chebyshev type I I filter with passband from100to 200 Hz and plot the impulse response of the filter.

n = 5; r = 20;

Wn = [ 100 200] / 500;

[ b, a] = cheby2( n, r , Wn) ;

[ y, t ] = i mpz(b, a, 101) ; stem( t , y)

Limitations For high order filters, the state-space form is the most numerically accurate,

followed by the zero-pole-gain form. The transfer function coefficient form isthe least accurate; numerical problems can arise for fil ter orders as low as 15.

Algorithm cheby2 uses a five-step algorithm:

1 I t finds the lowpass analog prototype poles, zeros, and gain using thecheb2ap function.

2 I t converts poles, zeros, and gain into state-space form.

3 I t transformsthelowpass filter into a bandpass, highpass, or bandstop filterwith desired cutoff frequencies, using a state-space transformation.

4 For digital filter design, cheby2 uses bi l i near to convert the analog filter

into a digital fil ter through a bilinear transformation with frequencyprewarping. Careful frequency adjustment guarantees that the analog

0 10 20 30 40 50 60 70 80 90 100-0.2

-0.15

-0.1

-0.05

0

0.05

0.1

0.15

0.2 Impulse Response of n = 5 Chebyshev Type II Filter

Page 365: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 365/870

7-83

cheby2

filters and the digital filters will have the same frequency responsemagnitude at Wn or w1 and w2.

5 I t converts the state-space filter back to transfer function or zero-pole-gainform, as required.

See Also bessel f Bessel analog filter design.

but t er Butterworth analog and digital filter design.

cheb2ap Chebyshev type I I analog lowpass filter prototype.cheb2ord Calculate the order of a Chebyshev type I I fil ter.

cheby1 Chebyshev type I filter design (passband ripple).

el l i p Elliptic (Cauer) filter design.

Page 366: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 366/870

7-84

chirp

7chirpPurpose Generate a swept-frequency cosine.

Syntax y = chi r p( t , f 0, t 1, f 1)

y = chi r p( t , f 0, t 1, f 1, ' met hod' )

y = chi r p( t , f 0, t 1, f 1, ' met hod' , phi )

Description y =chi rp( t , f 0, t 1, f 1) generates samples of a li near swept-frequency cosinesignal at the time instances defined in array t , where f 0 is the instantaneousfrequency at time 0, and f 1 is the instantaneous frequency at timet 1. f 0 andf 1 are both in hertz. I f unspecified, f 0 is 0, t 1 is 1, and f 1 is 100.

y =chi rp( t , f 0, t 1, f 1, ' met hod' ) specifies alternative sweep method options,

where met hod can be:

• l i near , which specifies an instantaneous frequency sweep f i(t) given by

where

β ensures that the desired frequency breakpoint f 1 at time t1 is maintained.

• quadr at i c, which specifies an instantaneous frequency sweep f i(t) given by

where

• l ogar i t hmi c specifies an instantaneous frequency sweep f i(t) given by

where

For a log-sweep, f 1 must be greater than f 0.

f i

t( ) f 0

βt+=

β f 1 f 0–( ) t1 ⁄ =

f i t( ) f 0 βt2+=

β f 1 f 0–( ) t1 ⁄ =

f i t( ) f 0

10βt+=

β log10 f 1 f 0–( )[ ] t1 ⁄ =

Page 367: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 367/870

7-85

chirp

y =chi rp( t , f 0, t 1, f 1, ' met hod' , phi ) allows an initial phasephi to bespecified in degrees. I f unspecified, phi is 0. Default values are substituted for

empty or omitted trail ing input arguments.

Examples Example 1

Compute the spectrogram of a chirp with linear i nstantaneous frequencydeviation.

t = 0: 0. 001: 2; % 2 secs @ 1kHz sampl e r at ey = chi r p( t , 0, 1, 150) ; % St ar t @ DC, cross 150Hz at t =1 sec

specgr am( y, 256, 1e3, 256, 250) % Di spl ay t he spect r ogr am

Example 2

Compute the spectrogram of a chirp with quadratic instantaneous frequency

deviation.

t = - 2: 0. 001: 2; % ±2 secs @ 1kHz sampl e rate

y = chi r p( t , 100, 1, 200, ' quadr at i c' ) ; %St ar t @100Hz, cross 200Hz

% at t =1 sec

specgr am(y, 128, 1e3, 128, 120) % Di spl ay t he spect r ogr am

Time

F r e q u e n c y

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.60

50

100

150

200

250

300

350

400

450

500

Page 368: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 368/870

7-86

chirp

See Also

Time

F r e q u e n c y

0 0.5 1 1.5 2 2.5 3 3.50

50

100

150

200

250

300

350

400

450

500

cos Compute the cosine of vector/matrix elements (see

the MATL AB documentation).

di r i c Compute the Dirichlet or periodic sinc function.

gauspul s Generate a Gaussian-modulated sinusoidal pulse.

pul str an Generate a pulse train.

r ectpul s Generate a sampled aperiodic rectangle.

sawt oot h Generate a sawtooth or triangle wave.

si n Compute the sine of vector/matrix elements (see theMAT L AB documentation).

s i nc Compute the sinc function.

square Generate a square wave.t r i pul s Generate a sampled aperiodic triangle.

Page 369: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 369/870

7-87

cohere

7coherePurpose Estimate magnitude squared coherence function between two signals.

Syntax Cxy = coher e( x, y)

Cxy = cohere(x , y, nf f t )

[Cxy, f ] = cohere(x, y, nf f t , f s )

Cxy = coher e( x, y, nf f t , f s, wi ndow)

Cxy = coher e( x, y, nf f t , f s, wi ndow, numover l ap)

Cxy = cohere(x ,y, . . . , ' df l ag' )

coher e( x, y)

Description Cxy =coher e( x, y) finds the magnitude squared coherence between length n

signal vectors x and y. The coherence is a function of the power spectra of xand y and the cross spectrum of x and y.

x and y must be the same length.

nf f t specifies the FF T length that cohere uses. This value determines thefrequencies at which the coherenceis estimated. f s is a scalar that specifies the

sampling frequency. wi ndowspecifies a windowing function and the number of samples cohere uses in its sectioning of thex and y vectors. numover l ap is thenumber of samples by which the window sectionsoverlap for both x and y. Any

arguments that you omit from the end of the parameter list use the defaultvalues shown below.

Cxy =coher e( x, y) uses the following default values:

• nf f t = mi n( 256, l ength(x) )

• f s = 2

• wi ndow is a periodic Hann window of length nf f t .

•numover l ap = 0

I f x is real, cohere estimates the coherence function at positive frequenciesonly; in this case, the output Cxy is a column vector of length nf f t / 2 +1 fornf f t even and ( nf f t +1) /2 for n odd. I f x or y is complex, cohere estimates thecoherence function at both positive and negative frequencies, and Cxy haslength nf f t .

Cxy f ( )P xy f ( ) 2

P xx f ( )P yy f ( )

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

Page 370: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 370/870

7-88

cohere

7 89

Cxy = cohere( x, y, nf f t ) uses the FF T length nf f t in estimating the powerspectrum for x. Specify nf f t as a power of 2 for fastest execution.

Cxy = cohere( x, y, nf f t , f s ) returns a vector f of frequencies at which thefunction evaluates the coherence. f s is the sampling frequency. f is the samesizeas Cxy, sopl ot ( f , Cxy) plots the coherence function versus properl y scaledfrequency. f s has no effect on the output Cxy; it is a frequency scalingmultiplier.

coher e( x, y, nf f t , f s, wi ndow) specifies a windowing function andthe numberof samples per section of the vectors x and y. I f you supply a scalar for wi ndow,cohere uses a Hann window of that length. The length of the window must beless than or equal to nf f t ; cohere zero pads the sections if the window lengthexceeds nf f t .

coher e( x, y, nf f t , f s, wi ndow, numover l ap) overlaps the sections of x by

numover l ap samples. You can use the empty matrix [ ] to specify the default value for any inputargument except x or y. For example,

cohere( x, y, [ ] , [ ] , kai ser( 128, 5) ) ;

uses 256 as the value for nf f t and 2 as the value for f s.

cohere( x, y, . . . , ' df l ag' ) specifies a detrend option, where ' df l ag' is:

• ' l i near ' , to removethebest straight-linefit fromtheprewindowed sections

of x and y

• ' mean' , to removethe mean from the prewindowed sections of x and y

• ' none' , for no detrending (default)

The ' df l ag' parameter must appear last in thelist of input arguments. cohere

recognizes a ' df l ag' string no matter how many intermediate arguments areomitted.

cohere with no output arguments plots the coherence estimate versus

frequency in the current figure window.

Page 371: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 371/870

7-89

cohere

7 90

Example Compute and plot the coherence estimatebetween two colored noisesequencesx and y.

randn( ' stat e' , 0) ;

h = f i r1(30, 0. 2, boxcar ( 31)) ;

h1 = ones(1, 10) / sqrt ( 10) ;

r = r andn( 16384, 1) ;

x = f i l t er ( h1, 1, r ) ;

y = f i l t er ( h, 1, x) ;

coher e( x, y, 1024, [ ] , [ ] , 512)

Diagnostics An appropriate diagnostic message is displayed when incorrect arguments areused.

Requi r es wi ndow' s l ength t o be no great er t han the FFT l engt h.

Requi r es NOVERLAP to be st r i ct l y l ess t han t he wi ndow l ength.

Requi r es posi t i ve i nt eger val ues f or NFFT and NOVERLAP.

Requi r es vect or ( ei t her r ow or col umn) i nput .Requi r es i nput s X and Y t o have t he same l ength.

0 0.2 0.4 0.6 0.8 1

0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

Frequency

C o h e r e n c e F u n c t i o n

E s t i m a t e

Page 372: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 372/870

7-90

cohere

7-91

Algorithm cohere estimates the magnitudesquared coherence function [1] using Welch’smethod of power spectrum estimation (see references [2] and [3]), as foll ows:

1 I t divides the signals x and y into separate overlapping sections, detrendseach section, and multiplies each section by wi ndow.

2 I t calculates the length nf f t fast F ourier transform of each section.

3 I t averages thesquares of thespectra of thex sections to form Pxx, averagesthe squares of the spectra of the y sections to form Pyy, and averages theproducts of the spectra of thex and y sections to form Pxy. I t calculates Cxy

by the following formula.

Cxy = abs( Pxy) . 2/ ( Pxx. *Pyy)

See Also

References [1] K ay, S.M. Modern Spectral Estimation. Englewood Cliffs, NJ :Prentice-Hall, 1988. Pg. 454.

[2] Rabiner, L.R., and B. Gold. Theory and Appli cation of Digital Si gnal

Processing. Englewood Cliffs, NJ : Prentice-Hall, 1975.

[3] Welch, P.D. “TheUseof Fast Fourier Transform for theE stimation of PowerSpectra: A Method Based on Time Averaging Over Short, Modified

Periodograms.” I EE E Tr ans. Audio E lectroacoust. Vol. AU-15 (J une 1967).Pgs. 70-73.

csd Estimate the cross spectral density (CSD) of twosignals.

pwel ch Power spectral density estimate using Welch’smethod.

t f e Transfer function estimate from input and output.

Page 373: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 373/870

7-91

conv

7-92

7convPurpose Convolution and polynomial multiplication.

Syntax c = conv(a, b)

Description c = conv(a, b) convolves vectors a and b. The convolution sum is

where N is themaximumsequence length. Theseries is indexed fromn +1andk +1 instead of the usual n and k because MATL AB vectors run from 1 to n

instead of from 0 to n-1.

The conv function is part of the standard MATL AB language.

Example The convolution of a = [ 1 2 3] and b = [ 4 5 6] isc = conv(a, b)

c =

4 13 28 27 18

Algorithm The conv function is an M -file that uses the f i l t er primitive. conv computestheconvolution operation as FI R filtering with an appropriatenumber of zeros

appended to the input.

See Also

c n 1+( ) a k 1+( )b n k–( )

k 0=

N 1–

å=

conv2 Two-dimensional convolution.

convmt x Convolution matrix.

convn N-dimensional convolution (see the MAT LABdocumentation).

deconv Deconvolution and polynomial division.

f i l t er Apply a filter to data.

r esi duez z-transform partial fraction expansion.

xcorr Cross-correlation function estimate.

Page 374: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 374/870

7 92

conv2

7-93

7conv2Purpose Two-dimensional convolution.

Syntax C = conv2( A, B)

C = conv2( A, B, ' shape' )

Description C = conv2( A, B) computes the two-dimensional convolution of matrices A

and B. I f oneof thesematrices describes a two-dimensional F I R filter, theothermatrix is filtered in two dimensions.

Each dimension of theoutput matrix C is equal in size to oneless than thesumof the corresponding dimensions of the input matrices. When[ ma, na] =si ze( A) and [ mb, nb] =si ze( B) ,

si ze(C) = [ ma+mb- 1, na+nb- 1]

C = conv2( A, B, ' shape' ) returns a subsection of the two-dimensionalconvolution with size specified by ' shape' , where:

• ' f ul l ' returns the full two-dimensional convolution (default)

• ' same' returns the central part of the convolution that is the same sizeas A

• ' val i d' returns only those parts of the convolution that are computedwithout the zero-padded edges. Using this option,

si ze(C) = [ ma- mb+1, na- nb+1] when si ze( A) >si ze( B)

conv2 executes most quickly when si ze( A) >si ze( B) .

The conv2 function is part of the standard MATL AB language.

Examples I n image processing, the Sobel edge-finding operation is a two-dimensionalconvolution of an input array with the special matrix

s = [1 2 1; 0 0 0; - 1 - 2 - 1] ;

Given any image, the following code extracts the horizontal edges.

h = conv2( I , s) ;

The following code extracts the vertical edges first, and then extracts bothhorizontal and vertical edges combined.

v = conv2( I , s' ) ;

v2 = ( sqr t ( h. 2 + v. 2) )

Page 375: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 375/870

7 93

conv2

7-94

See Also conv Convolution and polynomial multiplication.convn N-dimensional convolution (see the MAT LAB

documentation).

deconv Deconvolution and polynomial division.

f i l t er 2 Apply a two-dimensional filter to data.

xcorr Cross-correlation function estimate.

xcorr2Two-dimensional cross-correlation.

Page 376: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 376/870

convmtx

7-95

7convmtx

Purpose Convolution matrix.

Syntax A = convmt x( c, n)

A = convmt x( r , n)

Description A convolution matri x is a matrix, formed from a vector, whose inner product

with another vector is the convolution of the two vectors.

A = convmt x( c, n) where c is a length mcolumn vector returns a matrix A of size ( m+n- 1) -by-n. The product of A and another column vector x of length n isthe convolution of c with x.

A = convmt x( r , n) where r is a length mrow vector returns a matrix A of size

n-by-( m+n- 1) . The product of A and another row vector x of length n is theconvolution of r with x.

Example Generate a simple convolution matrix.

h = [1 2 3 2 1] ;

convmt x( h, 7)

ans =

1 2 3 2 1 0 0 0 0 0 0

0 1 2 3 2 1 0 0 0 0 0

0 0 1 2 3 2 1 0 0 0 0

0 0 0 1 2 3 2 1 0 0 00 0 0 0 1 2 3 2 1 0 0

0 0 0 0 0 1 2 3 2 1 0

0 0 0 0 0 0 1 2 3 2 1

Note that convmt x handles edge conditions by zero padding.

I n practice, it is more efficient to compute convolution using

y = conv(c , x)

than by using a convolution matrix.

n = l engt h(x) ;

y = convmt x( c, n) *x

Algorithm convmt x uses the function toepl i t z to generate the convolution matrix.

Page 377: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 377/870

convmtx

7-96

See Also conv Convolution and polynomial multiplication.convn N-dimensional convolution (see the MAT LAB

documentation).

conv2 Two-dimensional convolution.

df t mt x Discrete Fourier transform matrix.

Page 378: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 378/870

corrcoef

7-97

7corrcoef

Purpose Compute the correlation coefficient matrix.

Syntax C = corr coef ( X)

C = corr coef ( X, Y)

Description cor r coef returns a matrix of correlation coefficients calculated from an input

matrix whose rows are observations and whose columns are variables. I f C = cov(X) , then cor r coef ( X) is the matrix whose element (i, j) is

C = corr coef ( X) is the zeroth lag of the covariance function, that is, thezeroth lag of xcov( x, ' coef f ' ) packed into a square array.

C = corr coef ( X, Y) is thesame ascor r coef ( [ X Y] ) ; that is, it concatenates X

and Y in the row direction before its computation.

cor r coef removes the mean from each column before calculating the results.See the xcor r function for cross-correlation options.

The cor r coef function is part of the standard MATLAB language.

See Also

corrcoef i j,( )C i j,( )

C i i,( )C j j,( )-----------------------------------=

cov Covariance matrix.

mean Average value (see the MATL AB documentation).medi an Median value (see the MATL AB documentation).

st d Standard deviation (see the MATLABdocumentation).

xcorr Cross-correlation function estimate.

xcov Cross-covariance function estimate (equal to

mean-removed cross-correlation).

Page 379: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 379/870

corrmtx

7-98

7corrmtx

Purpose Compute a data matrix for autocorrelation matrix estimation.

Syntax X = cor r mt x( x, m)

X = corr mt x( x, m, ' met hod' )

[ X, R] = cor r mt x( . . . )

Description X = cor r mt x( x, m) returns an (n+m)-by-(m+1) rectangular Toeplitz matrix X,such that X' X is a (biased) estimate of the autocorrelation matrix for the

length n data vector x.

X = corr mt x( x, m, ' met hod' ) computes the matrix X according to the methodspecified by the string ' met hod' :

• ' aut ocor rel at i on' : (default) X is the (n+m)-by-(m+1) rectangular Toeplitz

matri x that generates an autocorrelation estimate for the length n datavector x, derived using prewindowed and postwindowed data, based on an

mth order prediction error model.• ' prewi ndowed' : X is the n-by-(m+1) rectangular Toeplitz matrix that

generates an autocorrelation estimatefor the length n data vector x, derivedusing prewindowed data, based on an mth order prediction error model.

• ' post wi ndowed' : X is the n-by-(m+1) rectangular Toeplitz matrix thatgenerates an autocorrelation estimatefor the length n data vector x, derivedusing postwindowed data, based on an mth order prediction error model.

•' covar i ance' : X is the (n-m)-by-(m+1) rectangular Toeplitz matrix thatgenerates an autocorrelation estimatefor the length n data vector x, derivedusing nonwindowed data, based on an mth order prediction error model.

• ' modi f i ed' : X is the 2(n-m)-by-(m+1) modified rectangular Toeplitz matrixthat generates an autocorrelation estimate for the length n data vector x,derived using forward and backward prediction error estimates, based on anmth order prediction error model.

[X, R] = cor r mt x( . . . ) alsoreturns the(m+1)-by-(m+1) autocorrelation matrixestimate R, calculated as X' *X.

Examples r andn( ' st at e' , 1) ; n=0: 99;

s=exp( i *pi / 2*n)+2*exp( i *pi / 4*n)+exp( i *pi / 3*n)+r andn( 1, 100) ;

X=cor r mt x( s, 12, ' mod' ) ;

Page 380: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 380/870

corrmtx

7-99

Algorithm The Toeplitz data matrix computed by corr mt x depends on the method youselect. The matrix determined by the autocorrelation (default) method is givenby the following matrix.

I n this matrix, m is the same as the input argument mto cor r mt x, and n is

l engt h( x) . Variations of this matrix are used toreturn theoutput X of cor r mt xfor each method:

• ' aut ocor r el at i on' : (default) X =X, above.

• ' prewi ndowed' : X is the n-by-(m+1) submatrix of X that is given by the

portion of X above the lower gray line.

• ' post wi ndowed' : X is the n-by-(m+1) submatrix of X that is given by theportion of X below the upper gray line.

• ' covar i ance' : X is the (n-m)-by-(m+1) submatrix of X that is given by theportion of X between the two gray lines.

• ' modi f i ed' : X is the 2(n-m)-by-(m+1) matrix Xmod shown below.

X

x 1( ) L 0

x m 1+( ) L x1)

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

x n( ) L x n m–( )

0 L x n( )

=

Page 381: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 381/870

corrmtx

7-100

See Also

References [1] Marple, S.L . Digital Spectral Analysis, Englewood Cliffs, NJ , Prentice-Hall,1987, pp. 216-223.

Xmod

x m 1+( ) L x1)

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

x n( ) L x n m–( )

x∗ 1( ) L x∗ m 1+( )

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

x∗ n m–( ) L x∗ n( )

=

pei g Estimate the pseudospectrum using the eigenvector

method.

pmusi c Estimate the pseudospectrum using the MUSI Calgorithm.

r oot ei g Estimate frequency content and signal power usingthe root eigenvector method.

r oot musi c Estimate frequency content and signal power usingthe root M USI C algorithm.

xcorr Compute the cross-correlation.

Page 382: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 382/870

cov

7-101

7cov

Purpose Compute the covariance matrix.

Syntax c = cov( x)

c = cov( x, y)

Description cov computes the covariance matrix. I f x is a vector, c is a scalar containing the

variance. F or an array where each row is an observation and each column avariable, cov( X) is the covariance matrix. di ag( cov(X) ) is a vector of

variances for each column, and sqr t ( di ag( cov( X) ) ) is a vector of standarddeviations.

cov(x) is the zeroth lag of the covariance function, that is, the zeroth lag of xcov( x) / ( n- 1) packed into a square array.

cov(x, y) where x and y are column vectors of equal length is equivalent tocov([x y])) , that is, it concatenates x and y in the row direction before its

computation.

cov removes the mean from each column before calculating the results.

The cov function is part of the standard MATL AB language.

Algorithm [ n, p] = si ze( x) ;

x = x- ones(n, 1) *( sum( x) / n) ;

y = x' *x/ ( n- 1) ;

See Also cor r coef Correlation coefficient matrix.

mean Average value (see the MATL AB documentation).

medi an Median value (see the MAT LAB documentation).

st d Standard deviation (see the MATL ABdocumentation).

xcor r Cross-correlation function estimate.

xcov Cross-covariance function estimate (equal tomean-removed cross-correlation).

Page 383: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 383/870

cplxpair

7-102

7cplxpair

Purpose Group complex numbers into complex conjugate pairs.

Syntax y = cpl xpai r ( x )

y = cpl xpai r ( x, t ol )

Description y = cpl xpai r ( x ) returns x with complex conjugate pairs grouped together.

cpl xpai r orders theconjugate pairs by increasing real part. Within a pair, theelement with negative imaginary part comes first. The function returns all

purely real values following all the complex pairs.

y = cpl xpai r ( x, t ol ) includes a tolerance, t ol , for determining whichnumbers are real and which are paired complex conjugates. By default,cpl xpai r uses a tolerance of 100*eps relative to abs(x( i ) ) . cpl xpai r forcesthe complex conjugate pairs to be exact complex conjugates.

The cpl xpai r function is part of the standard MATL AB language.

Example Order five poles evenly spaced around the unit circle into complex pairs.

cpl xpai r ( exp( 2*pi *sqrt ( - 1) * (0: 4) / 5) ' )

ans =

- 0. 8090 - 0. 5878i

- 0. 8090 + 0. 5878i

0. 3090 - 0. 9511i

0. 3090 + 0. 9511i1. 0000

Diagnostics I f there is an odd number of complex numbers, or if the complex numbers

cannot begrouped into complex conjugate pairs within thetolerance, cpl xpai r

generates the error message.

Compl ex numbers can' t be pai r ed.

Page 384: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 384/870

cremez

7-103

7cremez

Purpose Complex and nonlinear-phase equiripple FI R filter design.

Syntax b = cremez(n, f , ' f resp' )

b = cremez(n, f , ' f resp' , w)

b = cremez(n, f , ' f r esp' , p1, p2, . . . , w)

b = cremez(n, f , a, w)

b = cr emez( . . . , ' sym' )

b = cr emez( . . . , ' ski p_stage2' )

b = cr emez( . . . , ' debug' )

b = cremez( . . . , l gr i d)

[b, del t a, opt ] = cremez( . . . )

Description cr emez allows arbitrary frequency-domain constraints to be specified for thedesign of a possibly complex FI R filter. The Chebyshev (or minimax) filter erroris optimized, producing equiripple FI R filter designs.

b = cremez(n, f , ' f resp' ) returns a length n+1 F I R filter with the bestapproximation to the desired frequency response as returned by function

f resp. f is a vector of frequency band edge pairs, specified in the range -1and 1, where 1 corresponds to the normalized Nyquist frequency. Thefrequencies must be in increasing order, and f must haveeven l ength. Thefrequency bands span f ( k ) to f ( k+1) for k odd; the intervals f ( k+1) to f ( k+2)

for k odd are “transition bands” or “don’t care” regions during optimization.

b = cremez(n, f , ' f resp' , w) uses thereal, non-negativeweights in vector wtoweight thefit in each frequency band. The length of wis half thelength of f , sothere is exactly one weight per band.

b = cremez(n, f , ' f r esp' , p1, p2, . . . , . . . ) suppli es optional parametersp1, p2, . . . , to the frequency response function f r esp. Predefined ' f r esp'

frequency response functions are included for a number of common filterdesigns, as described below. For all of the predefined frequency responsefunctions, the symmetry option ' sym' defaults to ' even' if no negativefrequencies are contained in f and d =0; otherwise ' sym' defaults to ' none' .(See the ' sym' option below for details.) For all of the predefined frequencyresponsefunctions, d specifies a group-delay offset such that thefilter response

Page 385: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 385/870

cremez

7-104

has a group delay of n/ 2+d in units of the sample interval. Negative valuescreateless delay; positive values create more delay. By default d =0:

• l owpass, hi ghpass, bandpass, bandst op

These functions share a common syntax, exemplified below by the string' l owpass' .

b = cremez(n, f , ' l owpass' , . . . ) and

b = cremez(n, f , ' l owpass' , d, . . . ) design a linear-phase

(n/ 2+d delay) filter.

• mul t i band designs a linear-phase frequency response filter with arbitraryband amplitudes.

b = cremez(n, f , ' mul t i band' , a, . . . ) and

b = cremez(n, f , ' mul t i band' , a, d, . . . ) specify vector a containing

the desired amplitudes at the band edges in f . The desired amplitude atfrequencies between pairs of points f ( k ) and f ( k+1) for k odd is the line

segment connecting the points ( f ( k ) , a ( k ) ) and ( f ( k+1) , a( k+1) ) .

• di f f erent i at or designs a linear-phase differentiator. For these designs,zero-frequency must be in a transition band, and band weightingis set to beinversely proportional to frequency.

b = cremez(n, f , ' di f f erent i ator ' , f s, . . . ) and

b = cremez(n, f , ' di f f erent i ator ' , f s, d, . . . ) specify thesample ratef s used to determine the slopeof thedifferentiator response. I f omitted, f s

defaults to 1.• hi l bf i l t designs a linear-phase Hilbert transform filter response. For

Hil bert designs, zero-frequency must be in a transition band.

b = cr emez( n, f , ' hi l bf i l t ' , . . . ) and

b = cr emez(N, F, ' hi l bf i l t ' , d, . . . ) design a linear-phase(n/ 2+d delay) Hilbert transform filter.

b = cremez(n, f , a, w) is a synonym forb = cremez(n, f , ' mul t i band' , a, w) .

Page 386: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 386/870

cremez

7-105

b = cr emez( . . . , ' sym' ) imposes a symmetry constraint on the impulseresponse of the design, where ' sym' may be one of the following:

• ' none' indicates nosymmetry constraint. This is thedefault if any negativeband edge frequencies are passed, or if f r esp does not supply a default.

• ' even' indicates a real and even impulse response. This is the default forhighpass, lowpass, bandpass, bandstop, and multiband designs.

• ' odd' indicates a real and odd impulse response. This is the default for

Hilbert and differentiator designs.• ' r eal ' indicates conjugate symmetry for the frequency response

If any ' sym' option other than ' none' is specified, the band edges should onlybe specified over positivefrequencies; the negativefrequency region is fil led infrom symmetry. I f a ' sym' option is not specified, thef r esp function is queried

for a default setting.

b = cr emez( . . . , ' ski p_stage2' ) disables the second-stage optimizationalgorithm, which executes only when cr emez determines that an optimalsolution has not been reached by the standard Remez error-exchange.Disabling this algorithm mayincreasethe speed of computation, but mayincur

a reduction in accuracy. By default, the second-stage optimization is enabled.

b = cr emez( . . . , ' debug' ) enables the display of intermediate results duringthe filter design, where ' debug' may be one of ' t race' , ' pl ot s ' , ' bot h' , or

' of f ' . By default it is set to ' of f ' .

b = cremez( . . . , l gr i d) uses the integer l gr i d to control thedensity of thefrequency grid, which has roughly 2 next pow2( l gri d*n) frequency points.

The default value for l gr i d is 25. Note that the l gr i d argument must be a1-by-1 cell array.

Any combination of the ' sym' , ' skip_stage2' , ' debug' , and l gr i d options

may be specified.

[b, del t a] = cremez( . . . ) returns the maximum ripple height del ta.

Page 387: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 387/870

cremez

7-106

[b, del t a, opt ] = cremez( . . . ) returns a structure opt of optional resultscomputed by cr emez and contains the following fields.

User-definable functions may be used, instead of the predefined frequencyresponse functions for f r esp. The function is called from within cr emez usingthe following syntax

[ dh, dw] = f resp(n, f , gf , w, p1, p2, . . . )

where:

• n is the filter order.

f is thevector of frequency band edges that appear monotonically between -1and 1, where 1 corresponds to the Nyquist frequency.

• gf is a vector of grid points that have been linearly interpolated over each

specified frequency band by cr emez . gf determines the frequency grid atwhich the response function must be evaluated. This is the same datareturned by cr emez in the f gr i d field of theopt structure.

• wis a vector of real, positiveweights,oneper band, used duringoptimization.wis optional in thecall to cr emez; if not specified, it is set tounity weighting

before being passed to f resp.

• dh and dware the desired complex frequency response and band weightvectors, respectively, evaluated at each frequency in grid gf .

• p1, p2, . . . , are optional parameters that may be passed to f resp.

opt . f gr i d Frequency grid vector used for the filter design optimization

opt . des Desired frequency response for each point in opt . f gr i d

opt . wt Weighting for each point in opt . f gr i d

opt . H Actual frequency response for each point in opt . f gr i d

opt . er r or Error at each point in opt . f gr i d

opt . i extr Vector of indices into opt . f gr i d for extremal frequencies

opt . f ext r Vector of extremal frequencies

Page 388: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 388/870

cremez

7-107

Additionally, a preliminary call is made to f resp to determine the defaultsymmetry property ' sym' . This call is madeusing the syntax.

sym= f resp( ' def aul t s ' , n, f , [ ] , w, p1, p2, . . . )

The arguments may be used in determining an appropriate symmetry defaultas necessary. The function pr i vat e/ l owpass. mmaybe useful asa template forgenerating new frequency response functions.

Examples Example 1Design a 31-tap, linear-phase, lowpass filter.

b = cremez(30, [ - 1 - 0. 5 - 0. 4 0. 7 0. 8 1] , ' l owpass' ) ;

f r eqz(b, 1, 512, ' whol e' ) ;

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2−3500

−3000

−2500

−2000

−1500

−1000

−500

0

Normalized Frequency (×π rad/sample)

P h a s e (

d e g r e e s )

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2−100

−80

−60

−40

−20

0

20

Normalized Frequency (×π rad/sample)

M a g n i t u d e ( d B )

Page 389: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 389/870

cremez

7-108

Example 2Design a nonlinear-phase allpass FI R filter.

First select (or create) the function f resp that returns the desired frequencyresponse. For this example, f r esp is the al l pass. mfunction in the

s i gnal / s i gnal / pr i vat e directory which returns the frequency response of anonlinear-phase allpass filter. Copy al l pass. mto another location on theMAT LAB path before trying the example.

Before using cr emez with al l pass. mto generate the filter coefficients, callal l pass alone to create the desired response.

n = 22; % Fi l t er or der

f = [ - 1 1] ; % Fr equency band edges

w = [ 1 1] ; % Wei ght s f or opt i mi zat i on

gf = l i nspace( - 1, 1, 256) ; % Gr i d of f r equency poi nt s

d = al l pass( n, f , gf , w) ; % Desi r ed f r equency r esponse

Vector d now contains the complex frequency response that we desire for theFI R filter computed by cr emez .

Now compute the FI R fi lter that best approximates this response.

b = cremez(n, f , ' al l pass' , w, ' real ' ) ; %Approxi mat i on

f r eqz(b, 1, 256, ' whol e' ) ;

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2−1500

−1000

−500

0

500

Normalized Frequency (×π rad/sample)

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

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2−90

−80

−70

−60

−50

−40

−30

Normalized Frequency (×π rad/sample)

M a g n i t u d e ( d B )

Page 390: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 390/870

cremez

7-109

The f r eqz plot shows the frequency responseof the filter computed by cr emezto approximatethe desired response. Check the accuracy of the approximationby overlaying the desired frequency response on the plot.

subpl ot ( 2, 1, 1) ; hol d on

pl ot ( pi * (gf +1) , 20* l og10( abs( f f t shi f t ( d) ) ) , ' r - - ' )

subpl ot ( 2, 1, 2) ; hol d on

pl ot ( pi * (gf +1) , unwrap( angl e( f f t shi f t ( d) ) ) *180/ pi , ' r - - ' )

l egend( ' Appr oxi mat i on' , ' Desi r ed' )

Algorithm An extended version of the Remez exchange method is implemented for thecomplex case. This exchange method obtains the optimal filter when theequiripple nature of thefilter is restricted to have n+2 extremals. When it doesnot converge, thealgorithm switches to an ascent-descent algorithm that takesover to finish the convergence to the optimal solution. See the references for

further details.

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2−3000

−2000

−1000

0

Normalized Angular Frequency (×π rads/sample)

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

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2

−0.2

−0.1

0

0.1

0.2

Normalized Angular Frequency (×π rads/sample)

M a g n i t u d e ( d B )

ApproximationDesired

Page 391: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 391/870

cremez

7-110

See Also

References [1] K aram, L .J ., and J .H. McClellan. “Complex Chebyshev Approximation forFIR Filter Design.” I EE E Trans. on Ci rcuits and Systems I I . March 1995.

Pgs. 207-216.

[2] K aram, L .J . Design of Complex Digital FI R Fil ters in theChebyshev Sense.Ph.D. Thesis, Georgia I nstitute of Technology, March 1995.

[3] Demjanjov, V.F ., andV.N. Malozemov. I ntroduction toM inimax. New York:

J ohn Wiley & Sons, 1974.

f i r 1 FI R filter design using the window method.f i r 2 F I R filter design with arbitrary filter shapeusing the

window method.

f i r l s L inear phase FI R filter design using the

least-squares method.

r emez Parks-McClellan optimal FIR filter design.

Page 392: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 392/870

csd

7-111

7csd

Purpose Estimate the cross spectral density (CSD) of two signals.

Syntax Pxy = csd(x ,y)

Pxy = csd(x, y, nf f t )

[ Pxy, f ] = csd( x, y, nf f t , f s )

Pxy = csd( x, y, nf f t , f s , wi ndow)

Pxy = csd( x, y, nf f t , f s, wi ndow, numover l ap)

Pxy = csd( x, y, . . . , ' df l ag' )

[ Pxy, Pxyc, f ] = csd( x, y, nf f t , f s, wi ndow, numoverl ap, p)c s d (x , y , . . . )

Description Pxy = csd(x ,y) estimates the cross spectral density of the length n sequences

x and y using the Welch method of spectral estimation. Pxy = csd(x, y) usesthe following default values:

• nf f t = mi n( 256, l engt h( x) )

• f s = 2

• wi ndowis a periodic Hann window of length nf f t .

• numover l ap = 0

nf f t specifies the FFT length that csd uses. This value determines thefrequencies at which the cross spectrum is estimated. f s is a scalar thatspecifies the sampling frequency. wi ndowspecifies a windowing function andthe number of samples csd uses in its sectioning of the x and y vectors.numover l ap is the number of samples by which the sections overlap. Anyarguments omitted from the end of the parameter list use the default valuesshown above.

I f x and y are real, csd estimates the cross spectral density at positivefrequencies only; in this case, the output Pxy is a column vector of length

nf f t / 2 +1 for nf f t even and ( n f f t +1) /2 for nf f t odd. I f x or y is complex,csd estimates the cross spectral density at both positive and negative

frequencies and Pxy has length nf f t .

Pxy = csd(x, y, nf f t ) uses the FF T length nf f t in estimating the crossspectral density of x and y. Specify nf f t as a power of 2 for fastest execution.

[ Pxy, f ] = csd( x, y, nf f t , f s ) returns a vector f of frequencies at which thefunction evaluates the CSD. f is thesame size as Pxy, sopl ot ( f , Pxy) plots the

Page 393: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 393/870

csd

7-112

spectrum versus properly scaled frequency. f s has no effect on the output Pxy;it is a frequency scaling multiplier.

Pxy = csd( x, y, nf f t , f s , wi ndow) specifies a windowing function and thenumber of samples per section of thex vector. I f you supply a scalar for wi ndow,

csd uses a Hann window of that length. The length of thewindow must be lessthan or equal to nf f t ; csd zero pads the sections if thel ength of the window isless than nf f t . csd returns an error if thel ength of thewindow is greater than

nf f t .

Pxy = csd( x, y, nf f t , f s, wi ndow, numover l ap) overl aps thesections of x and y

by numover l ap samples.

You can use the empty matrix [ ] to specify the default value for any inputargument except x or y. For example,

csd( x, y, [ ] , 10000)

is equivalent to

csd( x)

but with a sampling frequency of 10,000 Hz instead of the default of 2 Hz.

Pxy = csd( x, y, . . . , ' df l ag' ) specifies a detrend option, where the string

' df l ag' is one of the following:

• ' l i near ' , to removethe best straight-line fit fromthe prewindowed sectionsof x and y

• ' mean' , to remove the mean from the prewindowed sections of x and y

• ' none' , for no detrending (default)

The df l ag parameter must appear l ast in the list of input arguments. csd

recognizes a df l ag string no matter how many intermediate arguments areomitted.

[ Pxy, Pxyc, f ] = csd( x, y, nf f t , f s, wi ndow, numover l ap, p) where p is a

positive scalar between 0 and1 returns a vector Pxyc that contains an estimateof the p*100 percent confidence interval for Pxy. Pxyc is a two-column matrixthe same length as Pxy. The interval [ Pxyc(: , 1) , Pxyc( : , 2) ] covers the true

Page 394: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 394/870

csd

7-113

CSD with probability p. pl ot ( f , [ Pxy Pxyc]) plots the cross spectrum insidethe p*100 percent confidence interval. I f unspecified, p defaults to 0.95.

c s d (x , y , . . . ) plots theCSD versus frequency in thecurrent figure window. I f the p parameter is specified, the plot i ncludes the confidence interval.

Example Generate two colored noise signals and plot their CSD with a confidenceinterval of 95%. Specify a length 1024 FFT, a 500 point triangular window with

no overlap, and a sampling frequency of 10 Hz.randn( ' state ' , 0) ;

h = f i r1( 30, 0. 2, boxcar ( 31) ) ;

h1 = ones(1, 10) / sqrt ( 10) ;

r = randn( 16384, 1) ;

x = f i l t er ( h1, 1, r ) ;

y = f i l t er ( h, 1, x) ;

csd( x, y, 1024, 10000, t r i ang( 500) , 0, [ ] )

Algorithm csd implements the Welch method of spectral density estimation (seereferences [1] and [2]):

1 I t applies the window specified by thewi ndowvector to each successivedetrended section.

2 I t transforms each section with an nf f t -point FFT.

0 1000 2000 3000 4000 5000−70

−60

−50

−40

−30

−20

−10

0

10

20

Frequency

C r o s s S p e c t r u m

M a g n i t u d e ( d B )

Page 395: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 395/870

csd

7-114

3I t forms the periodogram of each section by scaling the product of thetransform of the y section and the conjugate of the transformed x section.

4 I t averages the periodograms of the successive overlapping sections to formPxy, the cross spectral density of x and y.

The number of sections that csd averages is k, where k is

f i x( ( l engt h( x) - numover l ap) / ( l engt h( wi ndow) - numover l ap) )

Diagnostics An appropriate diagnostic message is displayed when incorrect arguments tocsd are used.

Requi r es wi ndow' s l ength t o be no great er t han the FFT l engt h.

Requi r es NOVERLAP to be st r i ct l y l ess t han t he wi ndow l ength.

Requi r es posi t i ve i nt eger val ues f or NFFT and NOVERLAP.

Requi r es vect or ( ei t her r ow or col umn) i nput .

Requi r es i nput s X and Y t o have t he same l ength.

Requi r es conf i dence par ameter t o be a scal ar bet ween 0 and 1.

See Also

References [1] Rabiner, L .R., and B. Gold. Theory and Application of Digital SignalProcessing. Englewood Cliffs, NJ : Prentice-Hall, 1975. Pgs. 414-419.

[2] Welch, P.D. “The Useof Fast Fourier Transform for theE stimation of PowerSpectra: A Method Based on T ime Averaging Over Short, ModifiedPeriodograms.” I EEE Tr ans. Audio Electroacoust. Vol. AU -15 (J une 1967).Pgs. 70-73.

cohere Estimate magnitude squared coherence functionbetween two signals.

pburg Estimate the power spectrum using the Burgmethod.

pmt m Estimate the power spectrum using the multitapermethod (MTM).

pmusi c Estimate the pseudospectrum using the MUSI Calgorithm.

pwel ch Estimate the power spectrum using Welch’s method.

pyul ear Estimate the power spectrum using the Yule-Walkerautoregressive method.

t f e Transfer function estimate from input and output.

Page 396: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 396/870

csd

7-115

[3] Oppenheim, A.V., and R.W. Schafer.Discrete-TimeSi gnal Processing

.Englewood Cliffs, NJ : Prentice-Hall, 1989. Pg. 737.

Page 397: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 397/870

czt

7-116

7czt

Purpose Chirp z-transform.

Syntax y = czt ( x, m, w, a)

y = czt ( x)

Description y =czt ( x, m, w, a) returns the chirp z-transform of signal x. The chirpz-transform is the z-transform of x along a spiral contour defined by wand a.mis a scalar that specifies the length of the transform, wis the ratio between

points along the z-planespiral contour of interest, and scalar a is the complexstarting point on that contour. Thecontour, a spiral or “chirp” in thez-plane, isgiven by

z = a*(w. - ( 0: m- 1) )

y =czt(x) uses the following default values:

• m=l engt h( x)

• w=exp( j *2*pi / m)• a =1

With thesedefaults, czt returns thez-transform of x at mequally spaced pointsaround theunit circle. This is equivalent tothediscreteFourier transform of x,or f f t ( x ) . The empty matrix [ ] specifies the default value for a parameter.

I f x is a matrix, czt ( x, m, w, a) transforms the columns of x.

Examples Create a random vector x of length 1013 and compute its DFT usingczt . This

is faster than the f f t function on the same sequence.

randn( ' stat e' , 0) ;

x = r andn( 1013, 1) ;

y = czt ( x) ;

Useczt to zoom in on a narrow-band section (100 to 150 Hz) of a filter’s

frequency response. First design the filter.h = f i r1(30, 125/ 500, boxcar ( 31) ) ; % f i l ter

Page 398: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 398/870

czt

7-117

Establish frequency and CZT parameters.

f s = 1000; f 1 = 100; f 2 = 150; % i n her t z

m = 1024;

w = exp(- j *2*pi * ( f 2- f 1) / ( m* fs ) ) ;

a = exp( j * 2* pi * f 1/ f s ) ;

Compute both the DF T and CZT of the filter.

y = f f t ( h, 1000) ;

z = cz t (h, m, w, a) ;

Create frequency vectors and compare the results.

f y = ( 0: l engt h( y) - 1) ' *1000/ l engt h( y) ;

f z = ( ( 0: l ength(z ) - 1) ' * ( f 2- f 1) / l ength(z ) ) + f 1;

pl ot ( f y( 1: 500) , abs( y( 1: 500) ) ) ; axi s( [ 1 500 0 1. 2] )

t i t l e( ' FFT' )

f i gure

pl ot ( f z , abs(z) ) ; axi s([ f 1 f 2 0 1. 2] )t i t l e( ' CZT' )

Algorithm czt uses the next power-of-2 length F FT to perform a fast convolution when

computing the z-transform on a specifi ed chirp contour [1]. czt can besignificantly faster than f f t for l arge, prime-length sequences.

Diagnostics I f m, w, or a is not a scalar, czt gives the following error message.

I nputs M, W, and A must be scal ars.

100 200 300 400 5000

0.2

0.4

0.6

0.8

1

FFT

100 110 120 130 1400

0.2

0.4

0.6

0.8

1

CZT

Page 399: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 399/870

czt

7-118

See Also

References [1] Rabiner, L .R., and B. Gold. Theory and Application of Digital Signal

Processing. Englewood Cliffs, NJ : Prentice-Hall, 1975. Pgs. 393-399.

f f t Compute the one-dimensional fast Fourier Transform.

f r eqz Compute the frequency response for digital filters.

Page 400: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 400/870

dct

7-119

7dctPurpose Discrete cosine transform (DCT).

Syntax y = dct ( x)

y = dct ( x, n)

Description y =dct(x) returns the unitary discrete cosine transform of x

where

N is the length of x, and x and y are the same size. I f x is a matrix, dct

transforms its columns. The series is indexed from n =1 and k =1 instead of

the usual n =0 and k =0 because MATL AB vectors run from 1 toN instead of from 0 toN- 1.

y =dct( x, n) pads or truncates x to length n before transforming.

The DCT is closely related to the discrete Fourier transform. Y ou can oftenreconstruct a sequence very accurately from only a few DCT coefficients, a

useful property for applications requiring data reduction.

y k( ) w k( ) x n( )π 2n 1–( ) k 1–( )

2N

-------------------------------------------cos

n 1=åk 1 … N, ,=,=

w k( )

1

N--------- k 1=,

2

N

---- 2 k N≤ ≤,

î

=

Page 401: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 401/870

dct

7-120

Example Find how many DCT coefficients represent 99% of the energy in a sequence.

x = ( 1: 100) + 50*cos( ( 1: 100) *2*pi / 40) ;

X = dct ( x) ;

[ XX, i nd] = sor t ( abs( X) ) ; i nd = f l i pl r ( i nd) ;

i = 1;

whi l e ( nor m( [ X( i nd( 1: i ) ) zer os( 1, 100- i ) ] ) / nor m( X) <. 99)

i = i + 1;

end

i =

3

See Also

References [1] J ain, A.K. Fundamentals of Digital I mageP rocessing. Englewood Cliffs,NJ :Prentice-Hall, 1989.

[2] Pennebaker, W.B., and J .L. Mitchell. J PE G Stil l I mage Data Compression

Standard. New York, NY : Van Nostrand Reinhold, 1993. Chapter 4.

f f t Compute the one-dimensional fast Fouriertransform.

i dct Compute the inverse discrete cosine transform.

dct 2 Two-dimensional DCT (see I mageProcessing Toolbox

User’s Guide).

i dct2 Two-dimensional inverse DCT (see I mageProcessing

Toolbox User’s Guide).

Page 402: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 402/870

decimate

7-121

7decimatePurpose Decrease the sampling rate for a sequence (decimation).

Syntax y = deci mat e( x, r )

y = deci mat e( x, r , n)

y = deci mate( x, r , ' f i r ' )

y = deci mate( x, r , n, ' f i r ' )

Description Decimation reduces the original sampling rate for a sequence to a lower rate,

theopposite of interpolation. Thedecimation processfilters theinput data witha lowpass filter and then resamples the resulting smoothed signal at a lower

rate.

y =deci mat e( x, r ) reduces the sample rate of x by a factor r . The decimatedvector y is r times shorter in length than the input vector x. By default,deci mat e employs an eighth-order lowpass Chebyshev type I filter. I t filtersthe input sequence in both the forward and reverse directions to remove all

phase distortion, effectively doubling the fil ter order.

y =deci mat e( x, r , n) uses an order n Chebyshev filter. Orders above13 arenotrecommended because of numerical instability. MAT L AB displays a warningin this case.

y =deci mat e( x, r , ' f i r ' ) uses a 30-point FI R filter, instead of the Chebyshev

I I R filter. Here deci mat e filters thei nput sequence in only one direction. This

technique conserves memory and is useful for working with long sequences.

y =deci mat e( x, r , n, ' f i r ' ) uses a length n FIR filter.

Example Decimate a signal by a factor of four.

t = 0: . 00025: 1; % Ti me vect or

x = si n( 2*pi *30*t ) + s i n( 2*pi *60*t ) ;

y = deci mate(x, 4) ;

Page 403: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 403/870

decimate

7-122

View the original and decimated signals.

s tem( x( 1: 120) ) , axi s ( [ 0 120 - 2 2] ) % Or i gi nal s i gnal

t i t l e( ' Or i gi nal Si gnal ' )

f i gure

st em( y( 1: 30) ) % Deci mat ed si gnal

t i t l e( ' Deci mat ed Si gnal ' )

Algorithm deci mat e uses decimation algorithms 8.2 and 8.3 from [1]:

1 I t designs a lowpass filter. By default, deci mat e uses a Chebyshev type Ifilter with normalized cutoff frequency 0. 8/ r and 0.05 dB of passbandripple. For thef i r option, deci mate designs a lowpass FI R filter with cutoff

frequency 1/ r using f i r 1.

2 For the F I R filter, deci mat e applies the filter to the input vector in onedirection. I n theI I R case, deci mat e applies thefilter in forward and reversedirections with f i l t f i l t .

3 deci mat e resamples the filtered data by selecting every r th point.

Diagnostics I f r is not an integer, deci mat e gives the foll owing error message.

Resampl i ng r at e R must be an i nteger .

I f n specifies an I I R fil ter with order greater than 13, deci mat e gives thefollowing warning.

War ni ng: I I R f i l t er s above or der 13 may be unr el i abl e.

0 50 100-2

-1

0

1

2 Original Signal

0 10 20 30-2

-1

0

1

2 Decimated Signal

Page 404: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 404/870

decimate

7-123

See Also

References [1]IEEE.Programs for Digital Signal Pr ocessing

. IE EE Press. New York: J ohnWiley & Sons, 1979. Chapter 8.

i nterp Resample data at a higher rate using lowpassinterpolation.

r esampl e Change sampling rate by any rational factor.

spl i ne Cubic spline interpolation (see the MATL AB

documentation).

upf i r dn Upsample, apply an F I R filter, and downsample.

Page 405: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 405/870

deconv

7-124

7deconvPurpose Deconvolution and 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 (quotient) is returned in vector q and the remainder in vector r suchthat b =conv( q, a) +r .

I f a and b are vectors of polynomial coefficients, convolving them is equivalent

to polynomial multiplication, and deconvolution is equivalent to polynomialdivision. The result of dividing b by a is quotient q and remainder r .

The deconv function is part of the standard MAT LAB language.

Example The convolution of a =[ 1 2 3] and b =[ 4 5 6] is

c = conv(a, b)

c =4 13 28 27 18

Usedeconv to divide b back out.

[q, r ] = deconv(c , a)

q =

4 5 6

r =

0 0 0 0 0

Algorithm This function calls f i l t er to compute the deconvolution as the impulseresponse of an I I R filter.

See Also conv Convolution and polynomial multiplication.

f i l t er Apply a filter to data.r esi duez z-transform partial fraction expansion.

Page 406: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 406/870

demod

7-125

7demodPurpose Demodulation for communications simulation.

Syntax x = demod( y, f c, f s , ' met hod' )

x = demod( y, f c, f s , ' met hod' , opt )

x = demod( y, f c, f s , ' pwm' , ' centered' )

[ x1, x2] = demod( y, f c, f s , ' qam' )

Description demod performs demodulation, that is, it obtains the original signal from a

modulated version of the signal. demod undoes the operation performed bymodul at e.

x =demod( y, f c, f s, ' met hod' ) and

x =demod( y, f c, f s, ' met hod' , opt ) demodulatethe real carrier signal y withacarrier frequency f c and sampling frequency f s, using oneof theoptions listedbelow for met hod. (Note that some methods accept an option, opt .)

amdsb- scoram

Amplitude demodulation, double sideband, suppressedcarrier. Multiplies y by a sinusoid of frequency f c and applies afifth-order Butterworth lowpass filter using f i l t f i l t .

x =y. *cos( 2*pi *f c*t ) ;[ b, a] =but t er( 5, f c*2/ f s) ;x =f i l t f i l t ( b, a, x) ;

amdsb- t c Amplitude demodulation, double sideband, transmitted

carrier. Multiplies y by a sinusoid of frequency f c, and applies afifth-order Butterworth lowpass filter using f i l t f i l t .

x =y. *cos( 2*pi *f c*t ) ;[ b, a] =but t er( 5, f c*2/ f s) ;x =f i l t f i l t ( b, a, x) ;

I f you specify opt , demod subtracts scalar opt from x. The defaultvalue for opt is 0.

amssb Amplitude demodulation, single sideband. Multiplies y by asinusoid of frequency f c and applies a fifth-order Butterworthlowpass filter using f i l t f i l t .

x =y. *cos( 2*pi *f c*t ) ;[ b, a] =but t er( 5, f c*2/ f s) ;x =f i l t f i l t ( b, a, x) ;

Page 407: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 407/870

demod

7-126

The default method is ' am' . Except for the ' ptm' and ' pwm' cases, x is thesame size as y.

I f y is a matrix, demod demodulates its columns.

x =demod( y, f c, f s, ' pwm' , ' centered' ) finds thepulsewidths assuming theyare centered at the beginning of each peri od. x is length l ength( y) * f c/ f s.

See Also

f m Frequency demodulation. Demodulates the FM waveform bymodulating the Hilbert transform of y by a complex exponential

of frequency - f c Hz and obtains the instantaneous frequency of the result.

pm Phase demodulation. Demodulates the PM waveform bymodulating the Hilbert transform of y by a complex exponentialof frequency –f c Hz and obtains the instantaneous phase of theresult.

pt m Pulse-time demodulation. Finds the pulse times of a pulse-timemodulated signal y. For correct demodulation, the pulses cannot

overlap. x is length l ength( t ) * fc / f s.

pwm Pulse-width demodulation. Finds the pulse widths of apulse-width modulated signal y. demod returns in x a vector whoseelements specify the width of each pulse in fractions of a period. The pulses in y should start at the beginning of each carrier

period, that is, they should be left justified.

qam Quadrature amplitude demodulation.

[ x1, x2] =demod( y, f c, f s, ' qam' ) multiplies y by a cosineand a

sine of frequency f c and applies a fifth-order Butterworthlowpass filter using f i l t f i l t .

x1 =y. *cos(2*pi *f c*t ) ;x2 =y. *si n(2*pi * fc*t ) ;

[ b, a] =but ter( 5, f c*2/ f s) ;x1 =f i l t f i l t ( b, a, x1) ;x2 =f i l t f i l t ( b, a, x2) ;

modul at e Apply modulation methods to signals.

vco Voltage controlled oscil lator.

Page 408: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 408/870

dftmtx

7-127

7dftmtxPurpose Discrete Fourier transform matrix.

Syntax A = df tmtx(n)

Description A discreteF ourier transform matrix is a complex matrix of values around theunit circle, whose matrix product with a vector computes the discrete Fouriertransform of the vector.

A =df t mt x( n) returns then-by-n complex matrix A that, when multiplied intoa length n column vector x.

y = A*x

computes the discrete Fourier transform of x.

The inverse discrete Fourier transform matrix is

Ai = conj (df tmtx(n) ) / n

Example I n practice, the discrete Fourier transform is computed more efficiently anduses less memory with an FFT algorithm

x = 1: 256;

y1 = f f t ( x) ;

than by using the Fourier transform matrix.

n = l engt h(x) ;

y2 = x*df t mt x( n) ;

norm( y1- y2)

ans =

1. 8297e- 009

Algorithm df t mt x uses an outer product to generate the transform matrix.

See Also convmt x Convolution matrix.

f f t Compute the one-dimensional fast Fouri er

transform.

Page 409: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 409/870

diric

7-128

7diricPurpose Compute the Dirichlet or periodic sinc function.

Syntax y = di r i c( x, n)

Description y =di r i c(x, n) returns a vector or array y the same sizeas x. The elements of y are the Dirichlet function of the elements of x. n must be a positive integer.

The Dirichlet function, or periodic sinc function, is

for any nonzero integer n. This function has period 2π for n odd and period 4π

for n even. I ts peak value is 1, and its minimum value is -1 for n even. Themagnitude of this function is (1/ n) times the magnitude of the discrete-time

Fourier transform of the n-point rectangular window.

Diagnostics I f n is not a positive integer, di r i c gives the foll owing error message.

Requi r es n to be a posi t i ve i nt eger .

See Also

diric x n,( )1–

x2π------- n 1–( )

x 0 2π± 4π± …, , ,=

nx 2 ⁄ ( )sinn x 2 ⁄ ( )sin---------------------------- else

î

=

cos Compute the cosine of vector/matrix elements (seethe MATL AB documentation).

gauspul s Generate a Gaussian-modulated signal pulse.pul st r an Generate a pulse train.

r ectpul s Generate a sampled aperiodic rectangle.

sawt oot h Generate a sawtooth or triangle wave.

si n Compute the sine of vector/matrix elements (see theMATL AB documentation).

s i nc Compute the sinc or sin(πt)/πt function.

square Generate a square wave.

t r i pul s Generate a sampled aperiodic triangle.

Page 410: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 410/870

dpss

7-129

7dpssPurpose Discrete prolate spheroidal sequences (Slepian sequences).

Syntax [e, v] = dpss( n, nw)

[e, v] = dpss( n, nw, k)

[ e, v] = dpss( n, nw, [ k1 k2] )

[e, v] = dpss( n, nw, ' i nt ' )

[e, v] = dpss( n, nw, ' i nt ' , Ni )

[ e, v] = dpss( . . . , ' trace' )

Description [ e, v] =dpss( n, nw) generates the first 2*nwdiscreteprolate spheroidal

sequences (DPSS) of length n in the columns of e, and their correspondingconcentrations in vector v. They are also generated in the DPSS M AT-filedatabase dpss. mat . nwmust beless than n/ 2.

[ e, v] =dpss( n, nw, k) returns thek most band-limited discrete prolate

spheroidal sequences. k must be an integer such that 1 ≤ k ≤ n.

[ e, v] =dpss( n, nw, [ k1 k2] ) returns the k1st through the k2nd discreteprolate spheroidal sequences, where 1 ≤ k1 ≤ k2 ≤ n.

For all of the above forms:

• The Slepian sequences are calculated directly.

• The sequences are generated in the frequency band | ω| ≤ ( 2πW) , where

W = nw/ n is the half-bandwidth and ω is in rad/sample.

• e( : , 1) is the length n signal most concentrated in the frequency band| ω| ≤ ( 2πW) radians, e( : , 2) is the signal orthogonal to e( : , 1) that is mostconcentrated in this band, e( : , 3) is the signal orthogonal to both e( : , 1)

and e( : , 2) that is most concentrated in this band, etc.

• For multitaper spectral analysis, typical choices for nware 2, 5/2, 3, 7/2, or 4.

[ e, v] =dpss( n, nw, ' i nt ' ) uses the interpolation method specified by the

string ' i nt ' to compute e and v from the sequences in dpss. mat with lengthclosest to n. Thestring ' i nt ' can be either:

• ' spl i ne' : Use spline interpolation.

• ' l i near ' : Use linear interpolation. This is much faster but less accuratethan spline interpolation.

Page 411: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 411/870

dpss

7-130

[ e, v] =dpss( n, nw, ' i nt ' , Ni ) interpolates fromexistinglength Ni sequences.

The interpolation method ' l i near ' requires Ni >n.

[ e, v] =d p s s ( . . . , ' trace' ) uses thetraili ng string ' trace' to display whichinterpolation method DPSS uses. I f you don’t specify the interpolation method,the display indicates that you are using the direct method.

Examples Example 1: Using dpss, dpssave, and dpssdir

Create a catalogue of 16 DPSS functions with nw=4, and use splineinterpolation on 10 of these functions while displaying the interpolation

method you use. You can do this using dpss, dpsssave, and dpssdi r .

% Cr eat e t he cat al ogue of f unct i ons.

[e, v] = dpss(16, 4) ;

% Save e and v i n a MAT- f i l e.

dpsssave( 4, e, v) ;

% Fi nd nw = 4. Fi r st cr eat e a st r uct ur e cal l ed i ndex.i ndex = dpssdi r ;

i ndex. wl i sts

ans =

NW: 4

key: 1

% Use spl i ne i nt er pol at i on on 10 of t he DPSS f unct i ons.

[e1, v1] = dpss(10, 4, ' spl i ne' , s i ze(e, 1) , ' t r ace' ) ;

Example 2: Using dpss and dpssload

Create a set of DP SS functions using dpss, and use the spline method on asubset of these functions. Use dpssl oad to load the MAT -file created by dpss.

% Cr eat e t he cat al ogue of f unct i ons.

[e, v] = dpss(16, 4) ;

% Load dpss. mat , wher e e and v are saved.[ e1, v1] = dpssl oad( 16, 4) ;

% Use spl i ne i nt er pol at i on on 10 of t he DPSS f unct i ons.

[e1, v1] = dpss(10, 4, ' spl i ne' ) ;

Page 412: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 412/870

dpss

7-131

See Also

References [1] Percival, D.B., and A.T. Walden. Spectral Analysis for Physical

Applications: Multitaper and Conventional UnivariateTechniques. Cambridge:Cambridge University Press, 1993.

dpsscl ear Remove discrete prolate spheroidal sequences from

database.

dpssdi r Discrete prolate spheroidal sequences databasedirectory.

dpssl oad L oad discrete prolate spheroidal sequences fromdatabase.

dpsssave Save discrete prolate spheroidal sequences indatabase.

pmt m Estimate the power spectral density using themultitaper method (MTM).

Page 413: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 413/870

dpssclear

7-132

7dpssclearPurpose Remove discrete prolate spheroidal sequences from database.

Syntax dpsscl ear( n, nw)

Description dpsscl ear( n, nw) removes sequences with length n and time-bandwidthproduct nwfrom the DPSS M AT-file databasedpss. mat .

See Also dpss Discrete prolate spheroidal sequences (Slepiansequences).

dpssdi r Discrete prolate spheroidal sequences databasedirectory.

dpssl oad L oad discrete prolate spheroidal sequences fromdatabase.

dpsssave Save discrete prolate spheroidal sequences indatabase.

Page 414: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 414/870

dpssdir

7-133

7dpssdirPurpose Discrete prolate spheroidal sequences database directory.

Syntax dpssdi r

dpssdi r ( n)

dpssdi r ( nw, ' nw' )

dpssdi r ( n, nw)

i ndex = dpssdi r

Description dpssdi r manages the database directory that contains the generated DPSSsamples in the DPSS MAT-fil e database dpss. mat .

dpssdi r lists the directory of saved sequences in dpss. mat .

dpssdi r ( n) lists the sequences saved with length n.

dpssdi r ( nw, ' nw' ) lists the sequences saved with time-bandwidth product nw.

dpssdi r ( n, nw) li sts the sequences saved with length n and time-bandwidthproduct nw.

i ndex =dpssdi r is a structure array describing the DPSS database. Pass n

and nwoptions as for the no output case to get a filtered i ndex.

Examples See “Example 1: Using dpss, dpssave, and dpssdir” on page 7-130.

See Also dpss Discrete prolate spheroidal sequences (Slepiansequences).

dpsscl ear Remove discrete prolate spheroidal sequences fromdatabase.

dpssl oad L oad discrete prolate spheroidal sequences fromdatabase.

dpsssave Save discrete prolate spheroidal sequences in

database.

Page 415: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 415/870

dpssload

7-134

7dpssloadPurpose L oad discrete prolate spheroidal sequences from database.

Syntax [ e, v] = dpssl oad( n, nw)

Description [ e, v] =dpssl oad( n, nw) loads all sequences with length n andtime-bandwidth product nwin the columns of e and their correspondingconcentrations in vector v from the DPSS M AT-file database dpss. mat .

Examples See “Example 2: Using dpss and dpssload” on page 7-130.

See Also dpss Discrete prolate spheroidal sequences (Slepian

sequences).

dpsscl ear Remove discrete prolate spheroidal sequences fromdatabase.

dpssdi r Discrete prolate spheroidal sequences database

directory.

dpsssave Save discrete prolate spheroidal sequences indatabase.

d

Page 416: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 416/870

dpsssave

7-135

7dpsssavePurpose Save discrete prolate spheroidal sequences in database.

Syntax dpsssave( nw, e, v)

st at us = dpsssave( nw, e, v)

Description dpsssave( nw, e, v) saves the sequences in the columns of e and their

corresponding concentrations in vector v in the DPSS MAT-file databasedpss. mat .

• I t is not necessary to specify sequence length, because the length of thesequence is determined by the number of rows of e.

• nwis the time-bandwidth product that was specified when the sequence wascreated using dpss.

status =dpsssave(nw, e, v) returns 0 if the savewas successful and 1 if therewas an error.

Examples See “Example 1: Using dpss, dpssave, and dpssdir” on page 7-130.

See Also dpss Discrete prolate spheroidal sequences (Slepiansequences).

dpsscl ear Remove discrete prolate spheroidal sequences fromdatabase.

dpssdi r Discrete prolate spheroidal sequences database

directory.dpssl oad L oad discrete prolate spheroidal sequences from

database.

lli

Page 417: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 417/870

ellip

7-136

7ellipPurpose Elliptic (Cauer) filter design.

Syntax [ b, a] = el l i p( n, Rp, Rs , Wn)

[ b, a] = el l i p( n, Rp, Rs , Wn, ' f t ype' )

[ b, a] = el l i p( n, Rp, Rs , Wn, ' s' )

[ b, a] = el l i p( n, Rp, Rs , Wn, ' f t ype' , ' s' )

[ z, p, k] = el l i p( . . . )

[ A, B, C, D] = el l i p( . . . )

Description el l i p designs lowpass, bandpass, highpass, and bandstop digital and analogelliptic filters. Elliptic filters offer steeper rolloff characteristics thanButterworth or Chebyshev filters, but are equiripple in both the pass- andstopbands. I n general, ell iptic filters meet given performance specificationswith the lowest order of any filter type.

Digital Domain

[ b, a] =el l i p( n, Rp, Rs, Wn) designs an order n lowpass digital elliptic filterwith cutoff frequency Wn, Rp dB of ripple in thepassband, and a stopband Rs dBdown from thepeak valuein thepassband. It returnsthefilter coefficientsin the

length n+1 row vectors b and a, with coefficients in descending powers of z.

The cutoff frequency is the edge of the passband, at which the magnituderesponse of the filter is - Rp dB. For el l i p, the cutoff frequency Wn is a number

between 0 and 1, where 1 corresponds to half the sampling frequency (Nyquistfrequency). Smaller values of passband ripple Rp and larger valuesof stopbandattenuation Rs both lead to wider transition widths (shallower rolloff characteristics).

I f Wn is a two-element vector, Wn =[ w1 w2] , el l i p returns an order 2*n

bandpass filter with passband w1 <ω <w2.

H z( )B z( )

A z( )-----------

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

1 a 2( )z 1–L a n 1+( )z n–+ + +

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

ellip

Page 418: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 418/870

ellip

7-137

[ b, a] =el l i p( n, Rp, Rs, Wn, ' f t ype' ) designs a highpass or bandstop filter,

where the string ' f t ype' is either:

• ' hi gh' for a highpass digital filter with cutoff frequency Wn

• ' stop' for an order 2*n bandstop digital fi lter if Wn is a two-element vector,

Wn =[ w1 w2] . The stopband is w1 <ω <w2.

With different numbers of output arguments, el l i p directly obtains other

realizations of the fil ter. To obtain zero-pole-gain form, use threeoutput

arguments as shown below.

[z , p, k] =el l i p( n, Rp, Rs, Wn) or

[ z , p, k] = el l i p( n, Rp, Rs, Wn, ' f t ype' ) returns thezeros and poles in length

n column vectors z and p and the gain in the scalar k.

To obtain state-space form, use four output arguments as shown below.

[ A, B, C, D] =el l i p( n, Rp, Rs, Wn) or

[ A, B, C, D] =el l i p( n, Rp, Rs, Wn, ' f t ype' ) where A, B, C, and Dare

and u is the input, x is the state vector, and y is the output.

Analog Domain

[ b, a] =el l i p( n, Rp, Rs, Wn, ' s' ) designs an order n lowpass analog ellipticfilter with cutoff frequency Wn and returns the filter coefficients in the lengthn+1 row vectors b and a, in descending powers of s, derived from the transferfunction

The cutoff frequency is the edge of the passband, at which the magnituderesponse of the filter is - Rp dB. For el l i p, the cutoff frequency Wn must begreater than 0.

x n 1+[ ] Ax n[ ] B u n[ ]+=

y n[ ] Cx n[ ] Du n[ ]+=

H s( )

B s( )

A s( )-----------

b 1( )sn b 2( )sn 1–L b n 1+( )+ + +

sn a 2( )sn 1–L

a n 1+( )+ + +-------------------------------------------------------------------------------------= =

ellip

Page 419: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 419/870

ellip

7-138

I f Wn is a two-element vector with w1 <w2, then el l i p( n, Rp, Rs, Wn, ' s' )

returns an order 2*n bandpass analog filter with passband w1 <ω <w2.

[ b, a] =el l i p( n, Rp, Rs, Wn, ' f t ype' , ' s' ) designs a highpass or bandstopfilter.

With different numbers of output arguments, el l i p directly obtains otherreali zationsof theanalogfilter. Toobtain zero-pole-gain form, usethree outputarguments as shown below.

[ z , p, k] =el l i p( n, Rp, Rs, Wn, ' s' ) or

[ z , p, k] =el l i p( n, Rp, Rs, Wn, ' f t ype' , ' s' ) returns the zeros and poles inlength n or 2*n column vectors z and p and the gain in the scalar k.

To obtain state-space form, use four output arguments as shown below.

[ A, B, C, D] =el l i p( n, Rp, Rs, Wn, ' s' ) or

[ A, B, C, D] =el l i p( n, Rp, Rs, Wn, ' f t ype' , ' s' ) where A, B, C, and Dare

and u is the input, x is the state vector, and y is the output.

Examples Example 1

For data sampled at 1000 Hz, design a sixth-order lowpass elliptic filter with acutoff frequency of 300 Hz, 3 dB of ripple in the passband, and 50 dB of attenuation in the stopband.

[ b, a] = el l i p( 6, 3, 50, 300/ 500) ;

The filter’s frequency response is

f r eqz( b, a, 512, 1000)

t i t l e( ' n=6 Lowpass El l i pt i c Fi l t er ' )

x· Ax B u+=

y Cx Du+=

ellip

Page 420: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 420/870

ellip

7-139

Example 2

Design a 20th-order bandpasselliptic filter with a passband from 100 to200 Hzand plot its impulse response.

n = 10; Rp = 0. 5; Rs = 20;

Wn = [ 100 200] / 500;

[ b, a] = el l i p( n, Rp, Rs , Wn) ;

[ y, t ] = i mpz(b, a, 101) ; stem( t , y)t i t l e( ' I mpul se Response of n=10 El l i pt i c Fi l t er ' )

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

−400

−300

−200

−100

0

100

Frequency (Hz)

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

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

−80

−60

−40

−20

0

Frequency (Hz)

M a g n i t u d e ( d B )

n=6 Lowpass Elliptic Filter

ellip

Page 421: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 421/870

ellip

7-140

Limitations For high order filters, the state-space form is the most numerically accurate,followed by the zero-pole-gain form. The transfer function form is the leastaccurate; numerical problems can arise for filter orders as low as 15.

Algorithm The design of elliptic filters is themost difficult and computationally intensiveof theButterworth, Chebyshev type I and I I , and elliptic designs. el l i p uses afive-step algorithm:

1 I t finds the lowpass analog prototype poles, zeros, and gain using theel l i pap function.

2 I t converts the poles, zeros, and gain into state-space form.

3 I t transforms the lowpass filter to a bandpass, highpass, or bandstop filterwith the desired cutoff frequencies using a state-space transformation.

4 For digital filter design, el l i p uses bi l i near to convert the analog filter

into a digital fil ter through a bilinear transformation with frequencyprewarping. Careful frequency adjustment guarantees that the analogfilters and the digital filters will have the same frequency response

magnitude at Wn or w1 and w2.

5 I t converts the state-space filter back to transfer function or zero-pole-gainform, 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.2Impulse Response of n = 10 Elliptic Filter

ellip

Page 422: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 422/870

e p

7-141

See Also bessel f Design a Bessel analog filter.

but t er Design a Butterworth analog or digital filter.

cheby1 Design a Chebyshev type I filter (passband ripple).

cheby2 Design a Chebyshev type I I filter (stopband ripple).

el l i pap Design an ell iptic analog lowpass filter prototype.

el l i por d Calculate the order for an ell iptic filter.

ellipap

Page 423: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 423/870

ellipap

7-142

7ellipapPurpose Elliptic analog lowpass filter prototype.

Syntax [ z , p, k] = el l i pap(n, Rp, Rs )

Description [ z , p, k] =el l i pap( n, Rp, Rs) returns the zeros, poles, and gain of an order n

elliptic analog lowpass filter prototype, with Rp dB of ripple in the passband,anda stopbandRs dB down from thepeak valuein thepassband. The zeros andpoles are returned in length n column vectors z and p and the gain in scalar k.I f n is odd, z is length n - 1. The transfer function is

Ell iptic filters offer steeper rolloff characteristics than Butterworth andChebyshev filters, but they are equiripple in both the passband and thestopband. Of the four classical filter types, elliptic filters usually meet a given

set of filter performance specifications with the lowest fil ter order.

el l i p sets the cutoff frequency of the elliptic filter to 1 for a normalizedresult. The cutoff frequency is the frequency at which the passband ends andthe filter has a magnitude response of 10-Rp/20.

Algorithm el l i pap uses the algorithm outlined in [1]. I t employs the M-file el l i pk tocalculate the complete elliptic integral of the first kind and the M-file el l i pj

to calculate J acobi elliptic functions.

See Also

References [1] Parks, T.W., and C.S. Burrus. Digital Filter Design. New York: J ohn Wiley& Sons, 1987. Chapter 7.

H s( )z s( )

p s( )---------- k

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

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

ω0

bessel ap Bessel analog lowpass filter prototype.

but t ap Butterworth analog lowpass filter prototype.

cheb1ap Chebyshev type I analog lowpass filter prototype.

cheb2ap Chebyshev type I I analog lowpass filter prototype.

el l i p Elliptic (Cauer) filter design.

ellipord

Page 424: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 424/870

7-143

7ellipordPurpose Calculate the minimum order for elliptic filters.

Syntax [ n, Wn] = el l i por d( Wp, Ws, Rp, Rs)

[ n, Wn] = el l i por d( Wp, Ws, Rp, Rs, ' s' )

Description el l i pord calculates the minimum order of a digital or analog elliptic filter

required to meet a set of filter design specifications.

Digital Domain

[ n, Wn] =el l i por d( Wp, Ws, Rp, Rs) returns the lowest order n of the ellipticfilter that loses no more than Rp dB in the passband and has at least Rs dB of attenuation in the stopband. The scalar (or vector) of corresponding cutoff

frequencies Wn, is also returned. Use the output arguments n and Wn in el l i p.

Choosethe input arguments tospecify thestopbandandpassband according tothe following table.

Table 7-7: Description of Stopband and Passband Filter Parameters

Wp Passband corner frequency Wp, the cutoff frequency, is a scalaror a two-element vector with values between 0 and 1, with 1corresponding to the normalized Nyquist frequency, π radiansper sample.

Ws Stopband corner frequency Ws, is a scalar or a two-element

vector with values between 0 and 1, with 1 corresponding tothe normalized Nyquist frequency.

Rp Passband ripple, in decibels. Twice this value specifies themaximum permissible passband width in decibels.

Rs Stopband attenuation, in decibels. This value is the number of decibels the stopband is attenuated with respect to thepassband response.

Page 425: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 425/870

ellipord

Page 426: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 426/870

7-145

Examples Example 1

For 1000 Hz data, design a lowpass filter with less than 3 dB of ripple in thepassband defined from 0 to 40 Hz and at l east 60 dB of ripple in the stopbanddefined from 150 Hz to the Nyquist frequency (500 Hz).

Wp = 40/ 500; Ws = 150/ 500;

Rp = 3; Rs = 60;

[ n, Wn] = el l i por d( Wp, Ws, Rp, Rs)

n =

4

Wn =

0. 0800

[ b, a] = el l i p( n, Rp, Rs , Wn) ;

f r eqz( b, a, 512, 1000) ;

t i t l e( ' n=4 El l i pt i c Lowpass Fi l t er ' )

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

−300

−200

−100

0

100

Frequency (Hz)

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

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

−100

−80

−60

−40

−20

0

Frequency (Hz)

M a g n i t u d e ( d B )

n=4 Elliptic Lowpass Filter

ellipord

Page 427: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 427/870

7-146

Example 2

Now design a bandpass filter with a passband from 60 Hz to 200 Hz, with lessthan 3 dB of ripple in the passband, and 40 dB attenuation in the stopbandsthat are 50 Hz wide on both sides of the passband.

Wp = [ 60 200] / 500; Ws = [ 50 250] / 500;

Rp = 3; Rs = 40;

[ n, Wn] = el l i por d( Wp, Ws, Rp, Rs)

n =

5

Wn =

0. 1200 0. 4000

[ b, a] = el l i p( n, Rp, Rs , Wn) ;

f r eqz( b, a, 512, 1000) ;

t i t l e( ' n=5 El l i pt i c Bandpass Fi l t er ' )

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

0

500

Frequency (Hz)

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

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

−250

−200

−150

−100

−50

0

Frequency (Hz)

M a g n i t u d e ( d B )

n=5 Elliptic Bandpass Filter

ellipord

Page 428: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 428/870

7-147

Algorithm el l i pord uses the elliptic lowpass filter order prediction formula described

in [1]. Thefunction performs its calculations in the analog domain for both theanalog and digital cases. For the digital case, it converts the frequencyparameters to the s-domain before estimating the order and naturalfrequencies, and then converts them back to the z-domain.

el l i pord initially develops a lowpass filter prototype by transforming thepassband frequencies of the desired filter to 1 rad/s (for low- and highpassfilters) and to -1 and 1 rad/s (for bandpass and bandstop filters). I t then

computes theminimum order required for a lowpassfilter tomeet thestopbandspecification.

See Also

References [1] Rabiner, L.R., and B. Gold. Theory and Appli cation of Digital Si gnal

Processing. Englewood Cliffs, NJ : Prentice-Hall, 1975. Pg. 241.

buttord Calculate the order for a Butterworth filter.

cheb1ord Calculate the order for a Chebyshev type I filter.

cheb2ord Calculate the order for a Chebyshev type I I filter.

el l i p Design an ell iptic (Cauer) filter.

eqtflength

Page 429: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 429/870

7-148

7eqtflengthPurpose Make the lengths of a transfer function’s numerator and denominator equal.

Syntax [ b, a] = eqt f l engt h( num, den)

Description [ b, a] = eqt f l engt h( num, den) modifies the vector numand/or the vector den,so that the resulting output vectors b and a have the same length. The inputvectors numand den may have different lengths. The vector numrepresents thenumerator polynomial of a given discrete-timetransfer function, andthevectorden represents its numerator. The resulting numerator b and denominator a

represent the same discrete-timetransfer function, but thesevectors have thesame length.

Useeqt f l engt h to obtain a numerator and denominator of equal length beforeapplying transfer function conversion functions such as t f2ss and t f 2zp todiscrete-time models.

Examples num = [ 1 0. 5] ;

den = [ 1 0. 75 0. 6 0] ;[ b, a] = eqt f l engt h( num, den)

b =

1. 0000 0. 5000 0

a =

1. 0000 0. 7500 0. 6000

Algorithm eqt f l ength( num, den) appends zeros to either numor den as necessary. I f bothnumand den have trail ing zeros in common, these are removed.

See Also t f2ss Convert a transfer function to state-space form.

t f2zp Convert a transfer function to zero-pole-gain form.

fdatool

Page 430: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 430/870

7-149

7fdatoolPurpose Open the Filter Design and Analysis Tool.

Syntax f dat ool

Description f dat ool opens the Filter Design and Analysis Tool (FDAT ool). Usethis tool to:

• Design filters

• Analyze filters

• Modify existing filter designs

See Chapter 5, “Filter Design and Analysis Tool,” for more information.

fdatool

Page 431: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 431/870

7-150

Remarks The Filter Design and Analysis Tool provides more design methods than the

SPTool Filter Designer.

See Also spt ool Open the signal processing GUI .

fft

Page 432: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 432/870

7-151

7fftPurpose Compute the one-dimensional fast F ouri er transform.

Syntax y = f f t ( x)

y = f f t ( x, n)

Description f f t computes the discrete F ourier transform of a vector or matrix. This

function implements the transform given by

where W N =e- j(2π/N) and N = l engt h( x) . Note that the series is indexed asn +1and k +1 instead of theusual n and k becauseM ATL AB vectors run from1 to N instead of from 0 to N-1.

y = f f t ( x) is the discrete Fourier transform of vector x, computed with a fast

Fourier transform (FFT ) algorithm. I f x is a matrix, y is theF FT of each columnof the matrix.

y = f f t ( x, n) is the n-point F FT . I f the length of x is less than n, f f t pads x

with traili ngzeros tolength n. If thel ength of x is greater than n, f f t truncatesthe sequencex. I f x is an array, f f t adjusts the length of the columns in the

same manner.

The f f t function is part of the standard MATL AB language.

Examples A common use of the Fourier transform is to find the frequency components of a time-domain signal buried in noise. Consider data sampled at 1000 Hz. F orma signal consisting of 50 Hz and 120 Hz sinusoids and corrupt the signal withzero-mean random noise.

r andn( ' state' , 0)

t = 0: 0. 001: 0. 6;

x = si n( 2*pi *50*t) + si n( 2*pi *120*t ) ;y = x + 2*randn( 1, l engt h( t ) ) ;

pl ot ( y( 1: 50) )

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

n 0=

N 1–

å=

fft

Page 433: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 433/870

7-152

I t is difficult to identify the frequency components by studying the original

signal. Convert to the frequency domain by taking the discrete Fouriertransform of the noisy signal y using a 512-point fast F ourier transform (FF T).

Y = f f t ( y, 512) ;

The power spectral density, a measurement of the energy at variousfrequencies, is

Pyy = Y. *conj ( Y) / 512;

Graph the first 256 points (the other 256 points are symmetric) on ameaningful frequency axis.

f = 1000*( 0: 255) / 512;

pl ot ( f , Pyy( 1: 256) )

0 5 10 15 20 25 30 35 40 45 50−5

−4

−3

−2

−1

0

1

2

3

4

5

fft

Page 434: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 434/870

7-153

See the pwel ch function for details on estimating the spectral density.

Sometimes it is useful tonormalizetheoutput of f f t so that a unit sinusoid in

the time domain corresponds to unit amplitude in the frequency domain. Toproduce a normalized discrete-time Fourier transform in this manner, use

Pn = abs( f f t ( x) )*2/ l ength( x)

Algorithm f f t is a built-in MATL AB function. See thef f t reference page in theM ATL ABdocumentation for details about the algorithm.

See Also

0 100 200 300 400 5000

10

20

30

40

50

60

70

dct I mplement the discrete cosine transform (DCT).df t mt x Compute the discrete Fourier transform matrix.

f f t 2 Compute the two-dimensional fast Fouriertransform.

f f t shi f t Rearrange the outputs of f f t and f f t 2.

f i l t er Filter data.

f r eqz Compute the frequency response of digital filters.

i f f t Compute the one-dimensional inverse fast Fouri er

transform.

pwel ch Estimate the power spectral density (PSD) of a signalusing Welch’s method.

fft2

Page 435: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 435/870

7-154

7fft2Purpose Compute the two-dimensional fast Fouri er transform.

Syntax Y = f f t 2( X)

Y = f f t 2( X, m, n)

Description Y = f f t 2( X) performs a two-dimensional F FT, producing a result Y with the

same size as X. I f X is a vector, Y has the same orientation as X.

Y = f f t 2( X, m, n) truncates or zero pads X, if necessary, to create an m-by-n

array before performing the FF T. The result Y is also m-by-n.

The f f t 2 function is part of the standard MATL AB language.

Algorithm f f t 2 (x ) is simply

f f t ( f f t ( x) . ' ) . '

This computes the one-dimensional f f t of each column of x, then of each row

of the result. The timerequired to compute f f t 2 (x ) depends on the number of prime factors in [ m, n] =s i ze( x) . f f t 2 is fastest when mand n are powers of 2.

See Also f f t One-dimensional fast Fourier transform.

f f t shi f t Rearrange the outputs of f f t and f f t 2.

i f f t One-dimensional inverse fast Fourier transform.

i f f t 2 Two-dimensional inverse fast Fouri er transform.

fftfilt

Page 436: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 436/870

7-155

7fftfiltPurpose FFT-based FI R filtering using the overlap-add method.

Syntax y = f f t f i l t ( b, x)

y = f f t f i l t ( b, x, n)

Description f f t f i l t filters data using the efficient F FT-based method of overlap-add, a

frequency domain filtering technique that works only for FI R filters.

y = f f t f i l t ( b, x) filters the data in vector x with the filter described by

coefficient vector b. I t returns the data vector y. The operation performed byf f t f i l t is described in the timedomain by the difference equation

An equivalent representation is thez-transform or frequencydomain description

By default, f f t f i l t chooses an FFT length and data block length thatguarantee efficient execution time.

y = f f t f i l t ( b, x, n) uses an FFT length of nf f t =2 next pow2( n) and a datablock length of nf f t - l engt h( b) +1.

f f t f i l t works for both real and complex inputs.

Examples Show that the results from f f t f i l t and f i l t er are identical.

b = [1 2 3 4] ;

x = [1 zeros (1, 99) ] ' ;

nor m( f f t f i l t ( b, x) - f i l t er ( b, 1, x) )

ans =

9. 5914e- 15

Algorithm f f t f i l t uses f f t to implement the overlap-add method [1], a technique thatcombines successive frequency domain filtered blocks of an input sequence.

f f t f i l t breaks an input sequence x into length L data blocks

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

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

x

L 2L 3L ceil(nx/L)*L

. . .

fftfilt

Page 437: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 437/870

7-156

and convolves each block with the filter b by

y = i f f t ( f f t ( x( i : i +L- 1) , nf f t ) . *f f t ( b, nf f t ) ) ;

where nf f t is the F FT length. f f t f i l t overl aps successive output sections bynb- 1 points, where nb is the length of the filter, and sums them.

f f t f i l t chooses the key parameters L and nf f t in different ways, dependingon whether you supply an FFT length n and on the lengths of the filter andsignal. I f you do not specify a value for n (which determines FFT length),

f f t f i l t chooses these key parameters automatically:

• I f l engt h( x) is greater than l engt h( b) , f f t f i l t chooses values that

minimize the number of blocks times the number of flops per FFT.

• I f l engt h( b) is greater than or equal to l engt h( x) , f f t f i l t uses a singleFFT of length

2 next pow2( l engt h( b) + l ength(x) - 1)

This essentially computes

y = i f f t ( f f t ( B, nf f t ) . *f f t ( X, nf f t ) )

I f you supply a value for n, f f t f i l t chooses an F FT length, nf f t , of 2 next pow2( n) and a data block length of nf f t - l engt h( b) +1. I f n is less thanl engt h( b) , f f t f i l t sets n to l engt h( b) .

See Also

References [1] Oppenheim, A.V., and R.W. Schafer, Discrete-TimeSi gnal Processing,Prentice-Hall, 1989.

nb–1L

nb–12L

nb–13L

. . .

conv Convolution and polynomial multiplication.

f i l t er Filter data with a recursive (II R) or nonrecursive(FI R) filter.

f i l t f i l tZero-phase digital filteri ng.

fftshift

Page 438: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 438/870

7-157

7fftshiftPurpose Rearrange the outputs of the FFT functions.

Syntax y = f f t shi f t ( x)

Description y = f f t shi f t ( x) rearranges the outputs of f f t and f f t 2 by moving the zerofrequency component to the center of the spectral density, which is sometimesa more convenient form.

F or vectors, f f t shi f t ( x) returns a vector with the left and right halves

swapped.For arrays, f f t s hi f t ( x) swaps quadrants one and three with quadrants twoand four.

The f f t shi f t function is part of the standard MATLAB language.

Examples For any array X

Y = f f t 2( x)

has Y( 1, 1) = sum( sum( X) ) ; theDC component of thesignal is in theupper-leftcorner of the two-dimensional F FT. For

Z = f f t shi f t ( Y)

the DC component is near the center of the matrix.

See Also f f t One-dimensional fast Fouri er transform.

f f t 2 Two-dimensional fast Fourier transform.

filter

Page 439: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 439/870

7-158

7filterPurpose Filter data with a recursive (I I R) or nonrecursive (FI R) filter.

Syntax y = f i l t er ( b, a, x)

[ y, zf ] = f i l t er ( b, a, x)

[ . . . ] = f i l t er ( b, a, x, z i )

[ . . . ] = f i l t er ( b, a, x, z i , di m)

Description y = f i l t er ( b, a, x) filters the data in vector x with the fil ter described bycoefficient vectors a and b to create the filtered data vector y. When x is a

matrix, filter operates on the columns of x. When x is an N-dimensional array,filter operates on the first nonsingleton dimension. a(1) cannot be 0, and if a(1) ≠ 1, f i l t er normalizes the filter coefficients by a( 1) .

[ y, zf ] = f i l t er ( b, a, x) returnsthefinal values zf of the state vector. Whenx is a vector, the size of the final condition vector zf ismax( l engt h( b) , l engt h( a) ) - 1, the number of delays in the filter. When x is a

multidimensional array, zf is an s-by-c matrix, where:

• s is the number of delays in the filter.

• c is pr od( si ze( x) ) / s i ze( x, di m) , wheredi mis thedimension into which youare filtering (the first nonsingleton dimension by default).

[ . . . ] = f i l t er ( b, a, x, z i ) specifies initial state conditions in the vector zi . The size of the initial condition vector zi must be the same asmax( l engt h( b) , l engt h( a) ) - 1, the number of delays in the filter.

[ . . . ] = f i l t er ( b, a, x, z i , di m) filters the input data located along thedimension di mof x. Set zi to the empty vector [ ] to use zero initial conditions.

The f i l t er function is part of the standard MAT LAB language.

filter

Page 440: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 440/870

7-159

Examples Find and graph the 101-point unit impulse response of a digital filter.

x = [1 zeros(1, 100)] ;[ b, a] = but t er ( 12, 400/ 1000) ;

y = f i l t er ( b, a, x) ;

st em( y)

Algorithm f i l t er is implemented as a transposed direct form I I structure [1], as shown

below

where n-1 is the filter order. The state vector z is a vector whose componentsare derived from the values of the inputs to each delay in the 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

Page 441: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 441/870

7-160

The operation of f i l t er at sample m is implemented using the transposed

direct form I I structure. This is calculated by the time domain differenceequations for y and the states zi.

Note thedivision by a(1). For efficient computation, select this coefficient to bea power of 2.

You can use f i l t i c to generate the state vector zi(0) from past inputs andoutputs.

The input-output description of this filtering operation in the z-transformdomain is a rational transfer function.

See Also

References [1] Oppenheim, A.V., and R.W. Schafer, Discrete-TimeSi gnal Processing,Prentice-Hall, 1989, pp. 311-312.

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

a 1( )----------------------------------------------------------=

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

=

zn 2–

m( ) b n 1–( )x m( ) zn 1–

m 1–( ) a n 1–( )y m( )–+=

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

Y z( )b 1( ) b 2( )z 1–

L b nb 1+( )z nb–+ + +

a 1( ) a 2( )z 1–L a na 1+( )z na–+ + +

------------------------------------------------------------------------------------------- -X z( )=

f f t f i l t F FT-based F I R filtering using the overlap-addmethod.

f i l t er 2 Two-dimensional digital filtering.

f i l t f i l t Zero-phase digital filteri ng.

f i l t i c Make initial conditions for f i l t er function.

filter2

Page 442: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 442/870

7-161

7filter2Purpose Two-dimensional digital filtering.

Syntax Y = f i l t er 2( B, X)

Y = f i l t er 2( B, X, ' shape' )

Description Y = f i l t er 2( B, X) filters the two-dimensional data in X with the

two-dimensional FI R filter in the matrix B. The result, Y, is computed usingtwo-dimensional convolution and is the same size as X.

Y = f i l t er 2( B, X, ' shape' ) returns Y computed with size specified by' shape' :

• ' same' returns the central part of the convolution that is the same sizeas X

(default).

• ' f ul l ' returns the full two-dimensional convolution, when si ze( Y) exceedssi ze( X) .

• ' val i d' returns only those parts of the convolution that are computed

without the zero-padded edges, when si ze( Y) is less than si ze( X) .

The f i l t er 2 function is part of the standard MATL AB language.

Algorithm The f i l t er 2 function uses conv2 to compute the full two-dimensional

convolution of the FI R filter with the input matrix. By default, f i l t er 2

extracts and returns thecentral part of theconvolution that is thesame sizeastheinput matrix. Use the' shape' parameter to specify an alternatepart of the

convolution for return.

See Also conv2 Two-dimensional convolution.

f i l t er Filter data with a recursive (II R) or nonrecursive

(FI R) filter.

filtfilt

Page 443: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 443/870

7-162

7filtfiltPurpose Zero-phase digital filtering.

Syntax y = f i l t f i l t ( b, a, x)

Description y = f i l t f i l t ( b, a, x) performs zero-phase digital filtering by processing theinput data in both the forward and reverse directions (see problem 5.39 in [1]).After filtering in the forward direction, it reverses the filtered sequence andruns it back through thefilter. The resultingsequencehas precisely zero-phasedistortion and double the filter order. f i l t f i l t minimizes start-up and ending

transients by matching initial conditions, and works for both real and complexinputs.

Note that f i l t f i l t should not beused with differentiator and Hilbert F I Rfilters, since the operation of these fil ters depends heavily on their phaseresponse.

Algorithm f i l t f i l t is an M -file that uses the f i l t er function. I n addition to the

forward-reverse filtering, it attempts to minimize startup transients byadjusting initial conditions to match the DC component of the signal and byprepending several filter lengths of a flipped, reflected copy of the input signal.

See Also

References [1] Oppenheim, A.V., and R.W. Schafer, Discrete-TimeSi gnal Processing,Prentice-Hall, 1989, pp. 311-312.

f f t f i l t F FT-based F I R filtering using the overlap-add

method.

f i l t er Filter data with a recursive (II R) or nonrecursive(FI R) filter.

f i l t er 2 Two-dimensional digital filtering.

filtic

Page 444: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 444/870

7-163

7filticPurpose Find initial conditions for a transposed direct form I I filter implementation.

Syntax z = f i l t i c( b, a, y, x)

z = f i l t i c( b, a, y)

Description z = f i l t i c( b, a, y, x) finds the initial conditions, z, for the delays in thetransposed direct form I I filter implementation given past outputs y andinputs x. The vectors b and a represent the numerator and denominatorcoefficients, respectively, of the filter’s transfer function.

The vectors x and y contain the most recent input or output first, and oldestinput or output last.

where nb is l engt h( b) - 1 (the numerator order) and na is l engt h( a) - 1 (thedenominator order). I f l engt h( x) is less than nb, f i l t i c pads it with zeros to

length nb; if l engt h( y) is less than na, f i l t i c pads it with zeros to length na.Elements of x beyond x(nb- 1) and elements of y beyond y(na- 1) are

unnecessary so f i l t i c ignores them.

Output z is a column vector of length equal to the larger of nb and na.z describes the state of the delays given past inputs x and past outputs y.

z = f i l t i c( b, a, y) assumes that theinput x is 0 in thepast.

The transposed direct form I I structure is

where n-1 is the filter order.

f i l t i c works for both real and complex inputs.

x x 1–( ) x 2–( ) x 3–( ) … x nb–( ) …, , , , , =

y y 1–( ) y 2–( ) y 3–( ) … y n– a( ) …, , , , , =

Σ Σ Σ z -1 z -1

x(m)

y(m)

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

– a(3) –a(2)

z1(m) z2(m)

Σ z -1

b(n)

– a(n)

zn -1(m)

...

...

...

filtic

Page 445: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 445/870

7-164

Algorithm f i l t i c performs a reverse difference equation to obtain the delay states z.

Diagnostics I f any of the input arguments y, x, b, or a is not a vector (that is, if anyargument is a scalar or array), f i l t i c gives the following error message.

Requi r es vect or i nput s.

See Also

References [1] Oppenheim, A.V., and R.W. Schafer, Discrete-TimeSi gnal Processing,Prentice-Hall, 1989, pp. 296, 301-302.

f i l t er Filter data with a recursive (II R) or nonrecursive(FI R) filter.

f i l t f i l tZero-phase digital filteri ng.

fir1

Page 446: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 446/870

7-165

7fir1Purpose Design a window-based finite impulse response filter.

Syntax b = f i r1(n, Wn)

b = f i r 1(n, Wn, ' f type' )

b = f i r 1( n, Wn, wi ndow)

b = f i r 1(n, Wn, ' f type' , wi ndow)

b = f i r 1( . . . , ' normal i zat i on' )

Description f i r 1 implements the classical method of windowed linear-phase FI R digital

filter design [1]. I t designs filters in standardlowpass, bandpass, highpass, andbandpass configurations. By default the filter is normalized so that themagnitude response of the filter at the center frequency of the passband is0 dB.

Note Use f i r 2 for windowed filters with arbitrary frequency response.

b = f i r1(n, Wn) returns row vector b containing the n+1 coefficients of anorder n lowpass FI R filter. This is a Hamming-window based, linear-phasefilter with normalized cutoff frequency Wn. The output filter coefficients, b, are

ordered in descending powers of z.

Wn is a number between 0 and 1, where 1 corresponds to theNyquist frequency.I f Wn is a two-element vector, Wn =[ w1 w2] , f i r 1 returnsa bandpass filter withpassband w1 <ω <w2.

I f Wn is a multi-element vector, Wn =[w1 w2 w3 w4 w5 . . . wn] , f i r 1 returns

an order n multiband filter with bands 0 <ω <w1, w1 <ω <w2, ..., wn <ω <1.

By default, the filter is scaled so that the center of the first passband has amagnitude of exactly 1 after windowing.

B z( ) b 1( ) b 2( )z 1–L b n 1+( )z n–+ + +=

fir1

Page 447: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 447/870

7-166

b = f i r 1(n, Wn, ' f t ype' ) specifies a filter type, where ' f t ype' is:

• ' hi gh' for a highpass filter with cutoff frequency Wn.

• ' stop' for a bandstop filter, if Wn =[ w1 w2] . The stopband frequency rangeis specified by this interval.

• ' DC- 1' to make the first band of a multiband filter a passband.

• ' DC- 0' to make the first band of a multiband filter a stopband.

f i r 1 always uses an even fi lter order for the highpass and bandstop

configurations. This is because for odd orders, the frequency response at theNyquist frequency is 0, which is inappropriate for highpass and bandstopfilters. I f you specify an odd-valued n, f i r 1 increments it by 1.

b = f i r 1( n, Wn, wi ndow) uses the window specified in column vector wi ndow

for the design. The vector wi ndowmust be n+1 elements long. I f no window isspecified, f i r 1 uses a Hamming window (see hammi ng) of length n+1.

b = f i r 1(n, Wn, ' f t ype' , wi ndow) accepts both ' f t ype' and wi ndow

parameters.

b = f i r 1( . . . , ' normal i zat i on' ) specifies whether or not the filtermagnitude is normalized. The string ' normal i zat i on' can be:

• ' scal e' (default): Normalizethe filter sothat themagnituderesponse of thefilter at the center frequency of the passband is 0 dB.

• ' noscal e' : Do not normalize the filter.

The group delay of the F I R filter designed by f i r 1 is n/ 2.

Algorithm f i r 1 uses thewindow method of FI R filter design [1]. I f w(n) denotes a window,

where 1 ≤ n ≤ N, and the impulse response of the ideal filter is h(n), whereh(n) is the inverse Fourier transform of the ideal frequency response, then thewindowed digital filter coefficients are given by

b n( ) w n( )h n( ) 1 n N≤ ≤,=

fir1

Page 448: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 448/870

7-167

Examples Example 1

Design a 48th-order FI R bandpass filter with passband 0.35≤ w ≤ 0.65.b = f i r1(48, [0. 35 0. 65] ) ;

f r eqz( b, 1, 512)

Example 2

The chi r p. mat file contains a signal, y, that has most of its power abovef s / 4,or half the Nyquist frequency. Design a 34th-order F I R highpass filter toattenuate the components of the signal below f s / 4. Usea cutoff frequencyof 0.48 and a Chebyshev window with 30 dB of ripple.

l oad chi r p % Load y and f s.

b = f i r1( 34, 0. 48, ' hi gh' , chebwi n( 35, 30) ) ;

f r eqz( b, 1, 512)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−2500

−2000

−1500

−1000

−500

0

Normalized Frequency (×π rad/sample)

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

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−100

−80

−60

−40

−20

0

20

Normalized Frequency (×π rad/sample)

M

a g n i t u d e ( d B )

fir1

Page 449: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 449/870

7-168

See Also

References [1] Programs for Digital Signal Processing, I EE E Press, New York, 1979.Algorithm 5.2.

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−2000

−1500

−1000

−500

0

500

Normalized Frequency (×π rad/sample)

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

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−120

−100

−80

−60

−40

−20

0

20

Normalized Frequency (×π rad/sample)

M a g n i t u d e ( d B )

f i l t er Filter data with a recursive (II R) or nonrecursive(FI R) filter.

f i r 2 Window-based finite impulse response filter

design – arbitrary response.

f i r c l s Constrained least square FI R fi lter design formultiband filters.

f i r c l s 1 Constrained least square filter design for lowpass

and highpass linear phase FI R filters.

f i r l s L east square linear-phase F I R filter design.

f r eqz Frequency response of digital filters.kai ser or d Estimate parameters for f i r 1 with a K aiser window.

r emez Parks-McClellan optimal FIR filter design.

fir2

Page 450: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 450/870

7-169

7fir2Purpose Design a frequency sampling-based finite impulse response filter.

Syntax b = f i r 2( n, f , m)

b = f i r2( n, f , m, wi ndow)

b = f i r 2(n, f , m, npt )

b = f i r2( n, f , m, npt , wi ndow)

b = f i r 2(n, f , m, npt , l ap)

b = f i r2( n, f , m, npt , l ap, wi ndow)

Description f i r 2 designs frequency sampling-based digital FI R filters with arbitrarilyshaped frequency response.

Note Use f i r 1 for windows-based standard lowpass, bandpass, highpass,and bandstop configurations.

b = f i r 2( n, f , m) returns row vector b containing the n+1 coefficients of anorder n FI R filter. Thefrequency-magnitudecharacteristics of this filter matchthose given by vectors f and m:

• f is a vector of frequency points in therange from 0 to1, where 1 correspondsto the Nyquist frequency. The first point of f must be 0 and the last point 1.

The frequency points must be in increasing order.

• mis a vector containing the desired magnitude response at the points

specified in f .

• f and mmust be the same length.

• Duplicate frequency points are allowed, corresponding to steps in thefrequency response.

Usepl ot ( f , m) to view the filter shape.

The output filter coefficients, b, are ordered in descending powers of z.

f i r 2 always uses an even filter order for configurations with a passband at theNyquist frequency. This is because for odd orders, the frequency response at

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

fir2

th N i t f i il 0 I f if dd l d

Page 451: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 451/870

7-170

the Nyquist frequency is necessarily 0. I f you specify an odd-valued n, f i r 2

increments it by 1.

b = f i r2( n, f , m, wi ndow) uses the window specified in the column vectorwi ndow. Thevector wi ndowmust ben+1 elements long. I f nowindow is specifi ed,

f i r 2 uses a Hamming window (see hammi ng) of length n+1.

b = f i r 2(n, f , m, npt ) or

b = f i r2( n, f , m, npt , wi ndow) specifies the number of points, npt , for the grid

onto which f i r 2 interpolates the frequency response, without or with a wi ndowspecification.

b = f i r 2(n, f , m, npt , l ap) and

b = f i r2( n, f , m, npt , l ap, wi ndow) specify the size of the region, l ap, thatf i r 2 inserts around duplicate frequency points, with or without a wi ndow

specification.

See the “Algorithm” section for more on npt and l ap.

Algorithm Thedesired frequency responsei s interpolated onto a dense, evenly spaced gridof length npt . npt is 512 by default. I f twosuccessive values of f are the same,a region of l ap points is set up around this frequency to provide a smooth butsteep transition in therequested frequency response. By default, l ap is 25. Thefilter coefficients areobtained by applying an inversefast Fourier transform to

the grid and multiplying by a window; by default, this is a Hamming window.

Examples Design a 30th-order lowpass filter and overplot the desired frequency responsewith the actual frequency response.

f = [0 0. 6 0. 6 1] ; m= [1 1 0 0] ;

b = f i r 2( 30, f , m) ;

[ h, w] = f reqz(b, 1, 128) ;

pl ot ( f , m, w/ pi , abs(h))

l egend( ' I deal ' , ' f i r2 Desi gned' )t i t l e( ' Compari son of Fr equency Response Magni t udes' )

fir2

Page 452: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 452/870

7-171

See Also

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

0.2

0.4

0.6

0.8

1

1.2

1.4Comparison of Frequency Response Magnitudes

Idealfir2 Designed

but t er Butterworth analog and digital filter design.

cheby1 Chebyshev type I filter design (passband ripple).

cheby2 Chebyshev type I I filter design (stopband ripple).

el l i p Elliptic (Cauer) filter design.

f i r 1 Window-based finite impulse response filter design –standard response.

maxf l at Generalized digital Butterworth filter design.

r emez Parks-McClellan optimal FIR filter design.

yul ewal k Recursive digital fil ter design.

fircls

7firclsPurpose Constrained least square FI R fil ter design for multiband filters

Page 453: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 453/870

7-172

Purpose Constrained least square FI R fil ter design for multiband filters.

Syntax b = f i r cl s( n, f , amp, up, l o)

f i rc l s (n, f , amp, up, l o, ' desi gn_f l ag' )

Description b = f i r cl s( n, f , amp, up, l o) generates a length n+1 linear phaseFIR filter b.

The frequency-magnitude characteristics of this filter match those given byvectors f and amp:

• f is a vector of transition frequencies in the range from 0 to 1, where 1corresponds to the Nyquist frequency. The first point of f must be 0 and thelast point 1. The frequency points must be in increasing order.

• amp is a vector describing the piecewise constant desired amplitude of thefrequency response. The length of amp is equal tothenumber of bands in theresponse and should be equal to l ength( f ) - 1.

• up and l o arevectors with thesame length as amp. They define theupper andlower bounds for the frequency response in each band.

f i r c l s always uses an even filter order for configurations with a passband atthe Nyquist frequency. This is because for odd orders, the frequency responseat the Nyquist frequency is necessarily 0. I f you specify an odd-valued n,f i r c l s increments it by 1.

f i rc l s (n, f , amp, up, l o, ' desi gn_f l ag' ) enables you to monitor the filter

design, where ' desi gn_f l ag' can be:

• ' t race' , for a textual display of the design error at each iteration step.

• ' pl ot s ' , for a collection of plots showing the filter’s full-band magnituderesponseand a zoomed view of the magnituderesponsein each sub-band. Allplots are updated at each iteration step.

• ' bot h' , for both the textual display and plots.

fircls

Examples Design an order 50 bandpass filter

Page 454: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 454/870

7-173

Examples Design an order 50 bandpass filter.

n = 50;f = [0 0. 4 0. 8 1] ;

amp = [ 0 1 0] ;

up = [ 0. 02 1. 02 0. 01] ;

l o = [ - 0. 02 0. 98 - 0. 01] ;

b = f i rc l s (n, f , amp, up, l o, ' pl ots ' ) ; % Pl ot magni tude response

Note Normally, the lower value in the stopband will be specified as negative.By setting l o equal to 0 in the stopbands, a nonnegative frequency responseamplitude can be obtained. Such filters can be spectrally factored to obtainminimum phase filters.

Algorithm The algorithm is a multiple exchange algorithm that uses L agrangemultipliers and K uhn-Tucker conditions on each iteration.

0 0.2 0.4 0.6 0.8 1 1.2 1.4-2

0

2

0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4

-0.02

0

0.02

B a n

d # 1

0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8

0.98

11.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

Fre uenc

fircls

See Also f i r c l s 1 Constrained least square filter design for lowpass

Page 455: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 455/870

7-174

See Also

References [1] Selesnick, I .W., M. L ang, and C.S. Burrus, “Constrained Least SquareDesign of FI R Filters without Specified Transition Bands,” Proceedings of the

I EE E I nt. Conf. Acoust., Speech, Si gnal Processing, Vol. 2 (May 1995),pp. 1260-1263.

[2] Selesnick, I .W., M. L ang, and C.S. Burrus. “Constrained Least SquareDesign of F I R Filters without Specified Transition Bands.” I E EE Transactions

on Signal Processing, Vol. 44, No. 8 (August 1996).

f i r c l s 1 Constrained least square filter design for lowpassand highpass linear phase FI R filters.

f i r l s L east square linear-phase F I R filter design.

r emez Parks-McClellan optimal FIR filter design.

fircls1

7fircls1Purpose Constrained least square filter design for lowpass and highpass linear phase

Page 456: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 456/870

7-175

p q g p g p p

FI R filters.

Syntax b = f i r c l s1(n, wo, dp, ds )

b = f i r c l s1(n, wo, dp, ds , ' hi gh' )

b = f i rc l s1(n, wo, dp, ds , wt )

b = f i rc l s1(n, wo, dp, ds , wt , ' hi gh' )

b = f i rc l s1( n, wo, dp, ds, wp, ws, k)

b = f i rc l s1( n, wo, dp, ds, wp, ws, k, ' hi gh' )

b = f i r cl s1( n, wo, dp, ds, . . . , ' desi gn_f l ag' )

Description b = f i r c l s1(n, wo, dp, ds ) generates a lowpass FI R filter b, where n+1 is thefilter length, wo is thenormalized cutoff frequency in therangebetween 0 and 1(where 1 corresponds to the Nyquist frequency), dp is the maximum passbanddeviation from1 (passbandripple), andds is the maximumstopband deviationfrom 0 (stopband ripple).

b = f i r c l s1(n, wo, dp, ds , ' hi gh' ) generates a highpass FI R filter b. f i r cl s1always uses an even filter order for thehighpass configuration. This is becausefor odd orders, the frequency response at the Nyquist frequency isnecessarily 0. I f you specify an odd-valued n, f i r c l s 1 increments it by 1.

b = f i rc l s1(n, wo, dp, ds , wt ) and

b = f i rc l s1(n, wo, dp, ds , wt , ' hi gh' ) specifies a frequency wt above which

(for wt >wo) or below which (for wt <wo) the filter is guaranteed to meet thegiven band criterion. This will help you design a filter that meets a passbandor stopband edge requirement. There are four cases:

• Lowpass:

- 0 <wt <wo <1: the amplitude of the filter is within dp of 1 over thefrequency range 0 <ω <wt .

- 0 <wo <wt <1: the amplitude of the filter is within ds of 0 over the

frequency range wt <ω <1.

fircls1

• Highpass:

Page 457: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 457/870

7-176

-

0 <wt <wo <1: the amplitude of the filter is within ds of 0 over thefrequency range0 <ω <wt .

- 0 <wo <wt <1: the amplitude of the filter is within dp of 1 over the

frequency rangewt <ω <1.

b = f i rc l s1( n, wo, dp, ds, wp, ws, k) generates a lowpass FI R filter b with aweighted function, where n+1 is the filter length, wo is the normalized cutoff frequency, dp is themaximumpassband deviation from 1 (passband ripple), and

ds is the maximum stopband deviation from 0 (stopband ripple). wp is thepassband edge of the L2 weight function and ws is the stopband edge of the L2

weight function, where wp <wo <ws. k is theratio(passbandL2 error)/(stopbandL2 error)

b = f i rc l s1( n, wo, dp, ds, wp, ws, k, ' hi gh' ) generates a highpass F I R filter b

with a weighted function, where ws <wo <wp.

b = f i r cl s1( n, wo, dp, ds, . . . , ' desi gn_f l ag' ) enables you to monitor thefilter design, where ' desi gn_f l ag' can be:

• ' t race' , for a textual display of the design table used in the design• ' pl ot s ' , for plots of the filter’s magnitude, group delay, and zeros and poles

• ' bot h' , for both the textual display and plots

Note I n the design of very narrow band filters with small dp and ds, theremay not exist a filter of the given l ength that meets the specifications.

k

A ω( ) D ω( )– 2 ωd0

wp

ò

A ω( ) D ω( )–2

ωdws

π

ò

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

fircls1

Examples Design an order 55 lowpass filter with a cutoff frequency at 0.3.

Page 458: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 458/870

7-177

n = 55; wo = 0. 3;dp = 0. 02; ds = 0. 008;

b = f i rc l s1( n, wo, dp, ds, ' pl ot s ' ) ; % Pl ot magni t ude response

Algorithm The algorithm is a multiple exchange algorithm that uses L agrangemultipliers and K uhn-Tucker conditions on each iteration.

See Also

References [1] Selesnick, I .W., M. L ang, and C.S. Burrus, “Constrained L east Square

Design of FI R F ilters without Specified Transition Bands,” Proceedings of the

I EEE I nt. Conf. Acoust., Speech, Signal Pr ocessing, Vol. 2 (May 1995),pp. 1260-1263.

[2] Selesnick, I .W., M. L ang, and C.S. Burrus, “Constrained L east SquareDesign of FI R Filters without Specified Transition Bands,”I EE E Transactions

on Signal Processing, Vol. 44, No. 8 (August 1996).

0 0.2 0.4 0.6 0.8 10

0.5

1

0 0.05 0.1 0.15 0.2 0.25-0.04

-0.02

0

0.02

0.04

0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-0.01

0

0.01

f i r c l s Constrained least square F I R filter design formultiband filters.

f i r l s L east square linear-phase F I R filter design.

r emez Parks-McClellan optimal FIR filter design.

firls

7firlsPurpose L east square linear-phase F I R filter design.

Page 459: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 459/870

7-178

Syntax b = f i r l s ( n, f , a)

b = f i r l s( n, f , a, w)

b = f i r l s( n, f , a, ' f t ype' )

b = f i r l s (n, f , a, w, ' f type' )

Description f i r l s designs a linear-phaseFI R filter that minimizes the weighted,integrated squared error between an ideal piecewise linear function and the

magnitude response of the filter over a set of desired frequency bands.

b = f i r l s ( n, f , a) returns row vector b containing the n+1 coefficients of theorder n FI R filter whose frequency-amplitude characteristics approximatelymatch those given by vectors f and a. The output filter coefficients, or “taps,”in b obey the symmetry relation.

ThesearetypeI (n odd) andtype I I (n even) linear-phasefilters. Vectors f and aspecify the frequency-amplitude characteristics of the filter:

• f is a vector of pairs of frequency points, specified in the range between 0and 1, where 1 corresponds to the Nyquist frequency. The frequencies mustbe in increasing order. Duplicate frequency points are allowed and, in fact,can beused to design a filter exactly the same as thosereturned by the f i r 1

and f i r 2 functions with a rectangular or boxcar window.

• a is a vector containing the desired amplitude at the points specified in f .

The desired amplitude function at frequencies between pairs of points

(f (k), f (k+1)) for k odd is the line segment connecting the points (f (k), a(k))and (f (k+1), a(k+1)).

The desired amplitude function at frequencies between pairs of points(f (k), f (k+1)) for k even is unspecified. These are transition or “don’t care”regions.

• f and a are the same length. This length must be an even number.

f i r l s always uses an even filter order for configurations with a passband atthe Nyquist frequency. This is because for odd orders, the frequency response

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

firls

at theNyquist frequency is necessarily 0. I f you specify an odd-valued n, f i r l s

increments it by 1

Page 460: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 460/870

7-179

increments it by 1.

The figure below illustrates the relationship between the f and a vectors indefining a desired amplitude response.

b = f i r l s( n, f , a, w) uses the weights in vector wto weight the fit in each

frequency band. The length of wis half the length of f and a, sothere is exactlyone weight per band.

b = f i r l s( n, f , a, ' f t ype' ) and

b = f i r l s( n, f , a, w, ' f t ype' ) specify a filter type, where ' f t ype' is:

• ' hi l ber t ' for linear-phase filters with odd symmetry (type I I I and type I V). The output coefficients in b obey the relation b(k) = -b(n+2-k),k =1, ... , n +1. This class of filters includes the Hilbert transformer, which

has a desired amplitude of 1 across the entire band.

• ' di f f erent i ator ' for type I I I and type I V filters, using a special weightingtechnique. F or nonzero amplitudebands, the integrated squared error has a

weight of (1/f )

2

so that the error at low frequencies is much smaller than athigh frequencies. For FI R differentiators, which have an amplitudecharacteristic proportional to frequency, the filters minimize the relative

integrated squared error (the integral of the square of the ratio of the errorto the desired amplitude).

1.0

0.0

Desired amplitude

response (a)

Normalized

frequency (f )

0.5

"Don't care"/transition regions

f = [0 . 3 . 4 . 6 . 7 . 9]

a = [ 0 1 0 0 . 5 . 5]

0.1 0.2 0.3 0.4 0.5 0.6 0.70.0 0.8 0.9 1.0 (Nyquist)

firls

Examples Example 1

Design an order 255 lo pass filter ith transition band

Page 461: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 461/870

7-180

Design an order 255 lowpass filter with transition band.

b = f i r l s (255, [0 0. 25 0. 3 1] , [ 1 1 0 0] ) ;

Example 2

Design a 31 coefficient differentiator.

b = f i r l s( 30, [ 0 0. 9] , [ 0 0. 9] , ' di f f er ent i at or ' ) ;

Example 3Design a 24th-order anti-symmetric filter with piecewiselinear passbands andplot the desired and actual frequency response.

F = [ 0 0. 3 0. 4 0. 6 0. 7 0. 9] ;

A = [ 0 1 0 0 0. 5 0. 5] ;

b = f i r l s( 24, F, A, ' hi l ber t ' ) ;

f or i =1: 2: 6,

pl ot ( [F ( i ) F ( i +1) ] , [A( i ) A( i +1) ] , ' - - ' ) , hol d on

end

[H, f ] = f reqz (b, 1, 512, 2) ;

pl ot ( f , abs( H) ) , gr i d on, hol d of f

l egend( ' I deal ' , ' f i r l s Des i gn' )

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] descri bes the theoretical approach behind f i r l s. The function

solves a system of linear equations involving an inner product matrix of size

Page 462: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 462/870

7-181

solves a system of linear equations involving an inner product matrix of size

roughly n/ 2 using MAT L AB’s \ operator.

This function designs type I , I I , I I I , and I V linear-phase filters. Type I and I Iare the defaults for n even and odd respectively, while the ' hi l ber t ' and' di f f erent i ator ' flags produce type I I I (n even) and I V (n odd) filters. Thevarious filter types have different symmetri es and constraints on theirfrequency responses (see [2] for details).

Diagnostics An appropriate diagnostic message is displayed when incorrect arguments areused.

F must be even l engt h.

F and A must be equal l engt hs.

Requi r es symmet r y to be ' hi l ber t ' or ' di f f er ent i at or ' .

Requi r es one wei ght per band.Fr equenci es i n F must be nondecr easi ng.

Fr equenci es i n F must be i n r ange [0, 1] .

A more serious warning message is

War ni ng: Mat r i x i s cl ose to si ngul ar or badl y scal ed.

This tends tohappen when theproduct of thefilter length and transition width

grows large. I n this case, the filter coefficients b might not represent thedesired fil ter. You can check the fil ter by looking at its frequency response.

Linear Phase

Filter Type

Filter

Order

Symmetry of Coefficients Response H(f),

f = 0

Response H(f),

f = 1 (Nyquist)

TypeI Even even: No restriction No restriction

TypeI I Odd No restriction H(1) = 0

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

Type I V Odd H(0) = 0 No restriction

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

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

firls

See Also f i r 1 Window-based finite impulse responsefilter design –standard response.

Page 463: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 463/870

7-182

References [1] Parks, T.W., and C.S. Burrus, Digital Filter Design, J ohn Wiley & Sons,1987, pp. 54-83.

[2] Oppenheim, A.V., and R.W. Schafer, Discrete-TimeSi gnal Processing,Prentice-Hall, 1989, pp. 256-266.

standard response.

f i r 2 Window-based finite impulse responsefilter design –arbitrary response.

f i r r c os Raised cosine F I R filter design.

r emez Parks-McClellan optimal FIR filter design.

firrcos

7firrcosPurpose Raised cosine F I R filter design.

Page 464: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 464/870

7-183

b = f i r r cos( n, F0, df , f s )b = f i r r cos( n, F0, df , f s , ' bandwi dth')

b = f i r r cos( n, F0, df )

b = f i r r cos( n, F0, r , f s , ' rol l off ' )

b = f i r rcos( . . . , ' t ype' )

b = f i r rcos( . . . , ' t ype' , del ay)

b = f i r rcos( . . . , ' t ype' , del ay, wi ndow)

[ b, a] = f i r r cos( . . . )

Description b = f i r r cos(n, F0, df , f s) or, equivalently,

b = f i r r cos( n, F0, df , f s , ' bandwi dth' ) returns an order n lowpasslinear-phase FI R filter with a raised cosine transition band. The filter hascutoff frequencyF0, transition bandwidth df , andsampling frequency f s, all inhertz. df must be small enough so that F0 ± df /2 is between 0 and f s / 2. The

coefficients in b are normalized so that the nominal passband gain is always

equal to 1. Specify f s as the empty vector [ ] to use the default value f s =2.

b = f i r r cos(n, F0, df ) uses a default sampling frequency of f s =2.

b = f i r r cos( n, F0, r , f s , ' rol l off ' ) interprets the third argument, r , as the

rolloff factor instead of the transition bandwidth, df . r must be in the range[ 0, 1] .

b = f i r rcos( . . . , ' t ype' ) designs either a normal raised cosine filter or asquare root raised cosine filter according to how you specify of the string' t ype' . Specify ' t ype' as:

• ' normal ' , for a regular raised cosine filter. This is the default, and is alsoineffect when the ' t ype' argument i s left empty, [ ] .

• ' sqr t ' , for a square root raised cosine filter.

b = f i r rcos( . . . , ' t ype' , del ay) specifies an integer delay in the range[ 0, n+1] . The default is n/ 2 for even n and ( n+1) / 2 for odd n.

b = f i r rcos( . . . , ' t ype' , del ay, wi ndow) applies a length n+1 window to thedesigned filter to reduce the ripple in the frequency response. wi ndowmust be

a length n+1 column vector. I f no window is specified, a boxcar (rectangular)

firrcos

window is used. Care must be exercised when using a window with a delayother than the default.

Page 465: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 465/870

7-184

[ b, a] = f i r r cos( . . . ) always returns a = 1.

Examples Design an order 20 raised cosine FI R filter with cutoff frequency 0.25 of theNyquist frequency and a transition bandwidth of 0.25.

h = f i r r cos(20, 0. 25, 0. 25) ;

f r eqz( h, 1)

See Also

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−700

−600

−500

−400

−300

−200

−100

0

Normalized Frequency (×π rad/sample)

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

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−120

−100

−80

−60

−40

−20

0

20

Normalized Frequency (×π rad/sample)

M a g n i t u d e ( d B )

f i r 1 Window-based finite impulse responsefilter design –standard response.

f i r 2 Window-based finite impulse responsefilter design –arbitrary response.

f i r l s L east square linear-phase F I R filter design.

r emez Parks-McClellan optimal FIR filter design.

freqs

7freqsPurpose Frequency response of analog filters.

Page 466: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 466/870

7-185

Syntax h = f reqs(b, a, w)

[h, w] = f reqs (b, a)

[h, w] = f reqs (b, a, n)

f r eqs( b, a)

Description f r eqs returns the complex frequency responseH( jω) (Laplace transform) of ananalog filter

given the numerator and denominator coefficients in vectors b and a.

h = f reqs(b, a, w) returns the complex frequency responseof the analogfilterspecified bycoefficient vectors b and a. f r eqs evaluates the frequency responsealong the imaginary axis in the complex plane at the frequencies specified in

real vector w.

[h, w] = f reqs (b, a) automatically picks a set of 200 frequency points wonwhich to compute the frequency response h.

[h, w] = f reqs (b, a, n) picks n frequencies on which to compute the frequency

response h.

f r eqs with no output arguments plots the magnitude and phase responseversus frequency in the current figure window.

f r eqs works only for real input systems and positive frequencies.

Examples Find and graph the frequency response of the transfer function given by

a = [ 1 0. 4 1] ;

b = [0. 2 0. 3 1] ;

w = l ogspace( - 1, 1) ;

f r eqs( b, a, w)

H s( )B s( )

A s( )-----------

b 1( )snb b 2( )snb 1–L

b n b 1+( )+ + +

a 1( )sna a 2( )sna 1–L a na 1+( )+ + +

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

H s( )0.2s2 0.3s 1+ +

s2 0.4s 1+ +-----------------------------------------=

freqs

101

Page 467: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 467/870

7-186

You can also create the plot with

h = f reqs(b, a, w) ;

mag = abs( h) ;

phase = angl e( h) ;

subpl ot ( 2, 1, 1) , l ogl og( w, mag)

subpl ot ( 2, 1, 2) , semi l ogx(w, phase)

To convert to hertz, degrees, and decibels, use

f = w/ ( 2*pi ) ;

mag = 20*l og10( mag) ;

phase = phase*180/ pi ;

Algorithm f r eqs evaluates the polynomials at each frequency point, then divides thenumerator response by the denominator response.

s = i *w;h = pol yval (b, s) . / pol yval (a, s) ;

10-1

100

101

10-1

100

Frequency

M a g n i t u d e

10-1

100

101

-150

-100

-50

0

Frequency

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

freqs

See Also abs Absolute value (magnitude).

angl e Phase angle.

Page 468: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 468/870

7-187

f r eqz Frequency response of digital filters.

i nvf r eqs Continuous-time (analog) fil ter identification fromfrequency data.

l ogspace Generate logarithmically spaced vectors (see theMAT L AB documentation).

pol yval Polynomial evaluation (see the MATLAB

documentation).

freqspace

7freqspacePurpose Frequency spacing for frequency response.

S nta f f reqspace( n)

Page 469: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 469/870

7-188

Syntax f = f reqspace( n)

f = f reqspace( n, ' whole' )

[ f 1, f 2] = f reqspace( n)

[ f 1, f 2] = f reqspace( [ m n] )

[ x1, y1] = f reqspace( n, ' meshgri d' )

[ x1, y1] = f reqspace( [m n] , ' meshgri d' )

Description f r eqspace returns the implied frequency range for equally spaced frequencyresponses. This is useful when creating frequency vectors for use with f r eqz.

f = f reqspace( n) returns the frequency vector f assuming n evenly spacedpoints around the unit circle. For n even or odd, f is ( 0: 2/ n: 1) . For n even,

f r eqspace returns ( n +2) /2 points. F or N odd, it returns ( n +1) /2 points.

f = f reqspace( n, ' whole' ) returns n evenly spaced points around the wholeunit circle. I n this case, f is 0: 2/ n: 2*( n- 1) / n.

[ f 1, f 2] = f reqspace( n) returns the two-dimensional frequency vectors f 1

and f 2 for an n-by-n matrix. For n odd, both f 1 and f 2 are

[ - 1 +1/ n: 2/ n: 1- 1/ n] . For n even, both f 1 and f 2 are [ - 1: 2/ n: 1- 2/ n] .

[ f 1, f 2] = f reqspace( [ m n] ) returns the two-dimensional frequency vectorsf 1 and f 2 for an m-by-n matrix.

[ x1, y1] = f reqspace( n, ' meshgri d' ) and

[ x1, y1] = f reqspace( [m n] , ' meshgri d' ) are equivalent to

[ f 1, f 2] = f r eqspace( . . . ) ;

[ x1, y1] = meshgr i d( f 1, f 2) ;

See the MATL AB documentation for details on the meshgr i d function.

See Also f r eqz Compute the frequency response of digital filters.i nvf r eqz Discrete-time filter identification from frequency

data.

freqz

7freqzPurpose Compute the frequency response of digital filters.

Syntax [ h w] = f r eqz( b a n)

Page 470: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 470/870

7-189

Syntax [ h, w] = f r eqz( b, a, n)

h = f r eqz( b, a, w)

[ h, w] = f r eqz( b, a, n, ' whol e' )

[ h, w, uni ts] = f r eqz(b, a, . . . )

[ h, f ] = f reqz(b, a, n, f s)

h = f reqz(b, a, f , f s)

[ h, f ] = f reqz(b, a, n, ' whol e' , f s )

[ h, f , uni ts] = f r eqz(b, a, n, ' whole' , f s )f reqz (b, a, . . . )

Description [h, w] = f reqz (b, a, n) returns the frequency response vector h and thecorresponding frequency vector wfor the digital filter whose transfer functionis determined by the (real or complex) numerator and denominatorpolynomials represented in the vectors b and a, respectively. The vectors h

and ware both of length n. The frequency vector whas values ranging from 0 to

π radians per sample. When you don’t specify the integer n, or you specify it asthe empty vector [ ] , the frequency response is calculated using the defaultvalue of 512 samples.

h = f reqz(b, a, w) returns the frequency response vector h calculated at thefrequencies (in radians per sample) supplied by the vector w. The vector wcan

have any length.

[ h, w] = f r eqz(b, a, n, ' whol e' ) uses n sample points around the entire unitcircle to calculate the frequency response. The frequency vector whas length n

and has values ranging from 0 to 2π radians per sample.

[ h, w, uni t s] = f r eqz( b, a, . . . ) returns the optional string argument uni t s,

specifying the units for the frequency vector w. The string returned in uni t s is' r ad/ sampl e' , denoting radians per sample.

[ h, f ] = f r eqz( b, a, n, f s ) returns the frequency response vector h and thecorresponding frequency vector f for the digital filter whose transfer functionis determined by the (real or complex) numerator and denominator

polynomials represented in the vectors b and a, respectively. The vectors h

and f are both of length n. For this syntax, thefrequency response is calculated

freqz

using the sampling frequency specified by the scalar f s (in hertz). Thefrequency vector f is calculated in units of hertz (Hz). The frequency vector f

has values ranging from 0 to f s / 2 Hz

Page 471: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 471/870

7-190

has values ranging from 0 to f s / 2 Hz.

h = f r eqz( b, a, f , f s ) returns the frequency response vector h calculated at

the frequencies (in Hz) supplied in thevector f . The vector f can beany length.

[ h, f ] = f r eqz( b, a, n, ' whol e' , f s ) uses n points aroundtheentire unit circleto calculate the frequency response. The frequency vector f has length n andhas values ranging from 0 to f s Hz.

[ h, f , uni t s] = f r eqz( b, a, n, ' whol e' , f s ) returns the optional stringargument uni ts , specifying the units for the frequency vector f . Thestringreturned in uni t s is ' Hz' , denoting hertz.

f r eqz(b, a, . . . ) plots the magnitude and unwrapped phase of the frequencyresponse of the filter. The plot is displayed in the current figure window.

Examples Pl ot themagnitude and phase response of an FI R filter.b = f i r1(80, 0. 5, kai ser ( 81, 8) ) ;

f r eqz(b, 1) ;

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−5000

−4000

−3000

−2000

−1000

0

Normalized Frequency (×π rad/sample)

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

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

−100

−50

0

50

Normalized Frequency (×π rad/sample)

M a g

n i t u d e ( d B )

freqz

Remarks I t is best tochoosea power of twofor thethird input argument n, becausef r eqz

uses an FFT algorithm to calculate the frequency response. See the reference

description of f f t for more information

Page 472: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 472/870

7-191

description of f f t for more information.

Algorithm The frequency response [1] of a digital filter can be interpreted as the transfer

function evaluated at z =e jω. You can always write a rational transfer functionin the following form.

f r eqz determines the transfer function from the (real or complex) numerator

and denominator polynomials you specify, and returns the complex frequencyresponse H(e jω) of a digital filter. The frequency response is evaluated atsample points determined by the syntax that you use.

f r eqz generally uses an F FT algorithm to compute the frequency responsewhenever you don’t supply a vector of frequencies as an input argument. I t

computes the frequency response as the ratio of the transformed numeratorand denominator coefficients, padded with zeros to the desired length.

When you dosupply a vector of frequencies as an input argument, then f r eqz

evaluates the polynomials at each frequency point using Horner’s method of nested polynomial evaluation [1], dividing the numerator response by the

denominator response.

H z( )B z( )

A z( )-----------

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

a 1( ) a 2( )z 1–L a na 1+( )z na–+ + +

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

freqz

See Also abs Compute the absolute value (magnitude).

angl e Compute the phase angle.

f f t Compute the one dimensional fast Fourier

Page 473: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 473/870

7-192

References [1] Oppenheim, A.V., and R.W. Schafer, Discrete-TimeSi gnal Processing,Prentice-Hall, 1989, pp. 203-205.

f f t Compute the one-dimensional fast Fouriertransform.

f i l t er Filter data.

f r eqs Compute the frequency response of analog fil ters.

f r eqzpl ot Plot the frequency response of a digital fi lter.

i mpz Compute the impulse response of digital filters.

i nvf r eqz I dentify discrete-time fil ter parameters fromfrequency data.

l ogspace Generate logarithmically spaced vectors (see theMATL AB documentation).

freqzplot

7freqzplotPurpose Plot frequency response data.

Syntax f r eqzpl ot ( h, w)

Page 474: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 474/870

7-193

yf r eqzpl ot ( h, w, s)

Description f r eqzpl ot ( h, w) plots the frequency response data contained in h at the

frequencies specified in the vector w, where h can be either a vector or a matrix.wmust be a vector whose length is the number of rows in h. The data in h isplotted versus frequency won two plots:

• The magnitude of h is plotted in dB.• The phase of h is plotted in degrees.

The units for frequency on the plots arein radians per sample. I f h is a matrix,the frequency responses of each column of h is plotted.

f r eqzpl ot ( h, w, s) specifies a structure of plotting options, s, with thefoll owing fields:

• s. xuni t s – a string specifying the frequency axis units. The contents of s. xuni t s can be one of the following:

- ' r ad/ sampl e' (default)

- ' Hz'

- ' kHz'

- ' MHz'

-' GHz'

- A user-specified string

• s. yuni t s – a string specifying the vertical axis units. The contents of s. yuni t s can be one of the following:

- ' dB' (default)

- ' l i near '

-

' squared'

freqzplot

• s. pl ot – a string specifying the type of plot to produce. The contents of s. pl ot can be one of the foll owing:

- ' bot h' (default)

Page 475: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 475/870

7-194

- ' mag'

- ' phase'

Note that the s structure can be obtained as an output of f r eqz.

Examples nf f t = 512; Fs = 44. 1; % Fs i s i n kHz.

[ b1, a1] = cheby1( 5, 0. 4, 0. 5) ;

[ b2, a2] = cheby1( 5, 0. 5, 0. 5) ;[ h1, f , s] = f reqz(b1, a1, nf f t , Fs) ;

h2 = f r eqz( b2, a2, nf f t , Fs) ; % Use t he same nf f t and Fs.

h = [ h1 h2] ;

s. pl ot = ' mag' ; % Pl ot t he magni t ude onl y.

s. xuni t s = ' khz' ; % Label t he f r equency uni t s cor r ect l y.

s. yuni t s = ' squar ed' ; % Pl ot t he magni t ude squar ed.

f reqzpl ot ( h, f , s) ; % Compare the two Chebyshev f i l t er s .

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

freqzplot

See Also f r eqz Compute and plot the frequency response of a fil ter.

gr pdel ay Compute the average filter delay.

psdpl ot Plot power spectral density (PSD) data

Page 476: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 476/870

7-195

psdpl ot Plot power spectral density (PSD) data.

gauspuls

7gauspulsPurpose Generate a Gaussian-modulated sinusoidal pulse.

Syntax yi = gauspul s ( t , f c, bw)yi = gauspul s(t f c bw bwr)

Page 477: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 477/870

7-196

yi = gauspul s(t , f c, bw, bwr)

[ yi , yq] = gaus pul s( . . . )

[ yi , yq, ye] = gauspul s( . . . )

t c = gauspul s( ' cutof f ' , f c, bw, bwr , t pe)

Description gauspul s generates Gaussian-modulated sinusoidal pulses.

yi = gauspul s ( t , f c, bw) returns a unity-amplitudeGaussian RF pulseat thetimes indicated in array t , with a center frequency f c in hertz and a fractionalbandwidth bw, which must begreater than 0. The default value for f c is1000 Hz and for bwis 0.5.

yi = gauspul s(t , f c, bw, bwr) returns a unity-amplitude Gaussian RF pulse

with a fractional bandwidth of bwasmeasured at a level of bwr dB with respectto the normalized signal peak. The fractional bandwidth reference level bwr

must be less than 0, because it indicates a reference level less than the peak(unity) envelope amplitude. The default value for bwr is -6 dB.

[ yi , yq] = gaus pul s( . . . ) returns both the in-phase and quadrature pulses.

[ yi , yq, ye] = gauspul s( . . . ) returns the RF signal envelope.

t c = gauspul s( ' cutof f ' , f c, bw, bwr , t pe) returns thecutoff timet c (greater

than or equal to 0) at which thetrailing pulseenvelopefalls below t pe dB withrespect to the peak envelope amplitude. The trail ing pulse envelope level t pe

must be less than 0, because it indicates a reference level less than the peak(unity) envelope amplitude. The default value for t pe is -60 dB.

Remarks Default values are substituted for empty or omitted trail ing input arguments.

gauspuls

Examples Plot a 50 kHz Gaussian RF pulse with 60% bandwidth, sampled at a rate of

1 MH z. Truncate the pulse where the envelope falls 40 dB below the peak.

t c = gauspul s ( ' cutof f ' , 50e3, 0. 6, [ ] , - 40) ;

t t 1 6 t

Page 478: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 478/870

7-197

t = - t c : 1e- 6 : t c;

yi = gauspul s(t , 50e3, 0. 6) ;

pl ot ( t , yi )

See Also

-4 -2 0 2 4

x 10-5

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

chi rp Generate a swept-frequency cosine.

cos Compute the cosine of vector/matrix elements (seethe MATL AB documentation).

di r i c Compute the Dirichlet or periodic sinc function.

pul str an Generate a pulse train.

r ectpul s Generate a sampled aperiodic rectangle.

sawt oot h Generate a sawtooth or triangle wave.

si n Compute the sine of vector/matrix elements (see theMAT L AB documentation).

s i nc Compute the sinc or sin(πt)/πt function.

square Generate a square wave.

t r i pul s Generate a sampled aperiodic triangle.

gmonopuls

7gmonopulsPurpose Generate a Gaussian monopulse.

Syntax y = gmonopul s( t , f c)t c = gmonopul s( ' cutof f ' , f c )

Page 479: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 479/870

7-198

t c gmonopul s( cutof f , f c )

Description y = gmonopul s( t , f c) returns samples of the unity-amplitude Gaussian

monopulsewith center frequency f c (in hertz)at thetimes indicated in array t .By default, f c =1000 Hz.

t c = gmonopul s( ' cutof f ' , f c ) returns the time duration between the

maximum and minimum amplitudes of the pulse.

Remarks Default values are substituted for empty or omitted trail ing input arguments.

Examples Example 1

Plot a 2 GHz Gaussian monopulse sampled at a rate of 100 GHz.

f c = 2E9; f s=100E9;

t c = gmonopul s( ' cut of f ' , f c);t = - 2*tc : 1/ f s : 2*t c;

y = gmonopul s( t , f c) ; pl ot ( t , y)

−4 −3 −2 −1 0 1 2 3 4

x 10−10

−1

−0.8

−0.6

−0.4

−0.2

0

0.2

0.4

0.6

0.8

1

gmonopuls

Example 2

Construct a pulse train from the monopulse of Example 1 using a spacing of

7.5 ns.

f 2E9 f 100E9 % t f l f

Page 480: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 480/870

7-199

f c = 2E9; f s=100E9; % cent er f r eq, sampl e f r eq

D = [2. 5 10 17. 5] ' * 1e- 9; % pul se del ay t i mes

t c = gmonopul s( ' cutof f ' , f c) ; % wi dt h of each pul se

t = 0 : 1/ f s : 150*t c; % si gnal eval uat i on t i me

yp = pul st r an( t , D, @gmonopul s, f c) ;

pl ot ( t , yp)

See Also

0 0.5 1 1.5 2 2.5

x 10−8

−1

−0.8

−0.6

−0.4

−0.2

0

0.2

0.4

0.6

0.8

1

chi rp Generate a swept-frequency cosine.

gauspul s Generate a Gaussian-modulated sinusoidal pulse.

pul str an Generate a pulse train.

r ectpul s Generate a sampled aperiodic rectangle.

t r i pul s Generate a sampled aperiodic triangle.

grpdelay

7grpdelayPurpose Compute the average filter delay (group delay).

Syntax [ gd, w] = grpdel ay( b, a, n)[gd, f ] = grpdel ay(b, a, n, f s )

Page 481: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 481/870

7-200

[ gd, w] = grpdel ay( b, a, n, ' whol e' )

[gd, f ] = grpdel ay(b, a, n, ' whol e' , f s )

gd = grpdel ay( b, a, w)

gd = grpdel ay( b, a, f , f s )

gr pdel ay(b, a)

Description The group delay of a filter is a measure of the average delay of the filter as afunction of frequency. I t is the negative first derivative of the phase responseof the filter. I f the complex frequency response of a filter is , then the

group delay is

where ω is frequency and θ i s the phase angle of .

[ gd, w] = grpdel ay( b, a, n) returns then-point group delay, , of the

digital filter

given the numerator and denominator coefficients in vectors b and a. gr pdel ay

returns both gd, the group delay, and w, a vector containing the n frequencypoints in radians. gr pdel ay evaluates the group delay at n points equallyspaced around the upper half of the unit circle, so wcontains n points between0 and π.

[gd, f ] = grpdel ay(b, a, n, f s ) specifies a positive sampling frequency f s inhertz. I t returns a length n vector f containing the actual frequency points atwhich the group delay is calculated, also in hertz. f contains n points between

0 and f s / 2.

H e j ω

( )

τg ω( )dθ ω( )

dω---------------–=

H e

j ω

( )

τg ω( )

H z( )B z( )

A z( )-----------

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

a 1( ) a 2( )z 1–L a na 1+( )z na–+ + +

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

grpdelay

[ gd, w] = grpdel ay( b, a, n, ' whol e' ) and

[gd, f ] = grpdel ay(b, a, n, ' whol e' , f s ) usen points around the whole unitcircle (from 0 to 2π, or from 0 to f s).

Page 482: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 482/870

7-201

gd = gr pdel ay( b, a, w) and

gd = grpdel ay(b, a, f , f s ) return thegroup delay evaluated at thepoints in w

(in radians) or f (in hertz), respectively, where f s is the sampling frequency in

hertz.

gr pdel ay with no output arguments plots the group delay versus frequency inthe current figure window.

gr pdel ay works for both real and complex input systems.

Examples Plot the group delay of Butterworth filter b(z)/a(z).

[ b, a] = but t er ( 6, 0. 2) ;

gr pdel ay(b, a, 128)

0 0.2 0.4 0.6 0.8 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

Plot both the group and phase delays of a system on the same graph.

gd = gr pdel ay( b, a, 512) ;

gd( 1) = [ ] ; % Avoi d NaNs

[ h, w] = f r eqz( b, a, 512) ; h( 1) = [ ] ; w( 1) = [ ] ;

Page 483: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 483/870

7-202

pd = - unwr ap( angl e( h) ) . / w;

pl ot ( w, gd, w, pd, ' : ' )

xl abel ( ' Fr equency ( rad/ sec)' ) ; gr i d;

l egend( ' Gr oup Del ay' , ' Phase Del ay' ) ;

Algorithm gr pdel ay multiplies the filter coefficients by a unit ramp. After Fouriertransformation, this process corresponds to differentiation.

See Also

0 0.5 1 1.5 2 2.5 3 3.5−6

−4

−2

0

2

4

6

8

10

12

Frequency (rad/sec)

Group DelayPhase Delay

cceps I mplement complex cepstral analysis.

f f t Compute the frequency one-dimensional fast Fouriertransform.

f r eqz Compute the frequency response of digital filters.hi l bert Compute the Hilbert transform.

i cceps Compute the inverse complex cepstrum.

r ceps Real cepstrum and minimum phase reconstruction.

hamming

7hammingPurpose Compute a Hamming window.

Syntax w = hammi ng( n)w = hammi ng( n, ' sf l ag' )

Page 484: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 484/870

7-203

Description w = hammi ng( n) returns an n-point symmetric Hamming window in the

column vector w. n should be a positive integer. The coefficients of a Hammingwindow are computed from the following equation.

w = hammi ng( n, ' sf l ag' ) returns an n-point Hamming window using thewindow sampling specified by ' sf l ag' , which can be either ' per i odi c ' or' symmetr i c' (thedefault). When ' per i odi c ' is specified, hammi ng computes a

length n+1 window and returns the first n points.

Note I f you specify a one-point window (n=1), the value 1 is returned.

Examples w = hammi ng( 64) ;

pl ot ( w) ; t i t l e( ' Hammi ng Wi ndow' )

w k 1+[ ] 0.54 0.46 2πk

n 1–

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

è ø

cos– k 0= … n 1–, , ,=

0 10 20 30 40 50 60 700

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1Hamming Window

hamming

See Also bart l et t Compute a Bartlett window.

bl ackman Compute a Blackman window.

boxcar Compute a rectangular window.

chebwi n Compute a Chebyshev window.

Page 485: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 485/870

7-204

References [1] Oppenheim, A.V., and R.W. Schafer, Discrete-TimeSi gnal Processing,Prentice-Hall, 1989, pp. 447-448.

p y

hann Compute a Hann window.

kai ser Compute a K aiser window.

t r i ang Compute a triangular window.

hann

7hannPurpose Compute a Hann (Hanning) window.

Syntax w = hann( n)w = hann( n, ' sf l ag' )

Page 486: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 486/870

7-205

Description w = hann( n) returns an n-point symmetric Hann window in the column

vector w. n must be a positive integer. The coefficients of a Hann window arecomputed from the following equation.

w = hann( n, ' sf l ag' ) returns an n-point H ann window using the windowsampling specified by ' sf l ag' , which can be either ' per i odi c ' or' symmetr i c' (the default). When ' per i odi c' is specified, hann computes a

length n+1 window and returns the first n points.

Note I f you specify a one-point window (n=1), the value 1 is returned.

Examples w = hann(64) ;

pl ot ( w) ; t i t l e( ' Hann Wi ndow' )

w k 1+[ ] 0.5 1 2πk

n 1–

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

è ø

cos–

è ø

k 0= … n 1–, , ,=

0 10 20 30 40 50 60 700

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1Hann Window

hann

See Also bart l et t Compute a Bartlett window.

bl ackman Compute a Blackman window.

boxcar Compute a rectangular window.

chebwi n Compute a Chebyshev window.

Page 487: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 487/870

7-206

References [1] Oppenheim, A.V., and R.W. Schafer, Discrete-TimeSi gnal Processing,Prentice-Hall, 1989, pp. 447-448.

hammi ng Compute a Hamming window.

kai ser Compute a K aiser window.

t r i ang Compute a triangular window.

hilbert

7hilbertPurpose Compute the discrete-time analytic signal using the Hilbert transform.

Syntax x = hi l ber t ( xr )x = hi l ber t ( xr , n)

Page 488: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 488/870

7-207

Description x = hi l ber t ( xr ) returns a complex heli cal sequence, sometimes called theanalytic signal, from a real data sequence. The analytic signal x =xr +i *xi

has a real part, xr , which is theoriginal data, and an imaginary part, xi , whichcontains theH ilbert transform. The imaginary part is a version of theoriginalreal sequencewith a 90°phaseshift. Sines aretherefore transformed tocosines

and vice versa. The Hilbert transformed series has the same amplitude andfrequency content astheoriginal real data andincludes phaseinformation that

depends on the phase of the original data.

I f xr is a matrix, x = hi l ber t ( xr ) operates columnwiseon the matrix, findingthe Hilbert transform of each column.

x = hi l ber t ( xr , n) uses an n point F FT to compute the Hilbert transform.

The input dataxr

is zero-padded or truncated to lengthn

, as appropriate. The Hilbert transform is useful in calculating instantaneous attributes of atime series, especiall y the amplitude and frequency. The instantaneousamplitude is the amplitude of the complex Hilbert transform; theinstantaneous frequency is the timerate of change of the instantaneous phase

angle. For a pure sinusoid, the instantaneous amplitude and frequency areconstant. The instantaneous phase, however, is a sawtooth, reflecting the wayin which the local phaseangle varies linearly over a single cycle. For mixtures

of sinusoids, theattributes areshort term, or local, averages spanning nomorethan two or three points.

Reference [1] describes the K olmogorov method for minimum phasereconstruction, which involves takingtheH ilbert transform of thel ogarithm of the spectral density of a time series. The toolbox function r ceps performs thisreconstruction.

F or a discrete-time analytic signal x, the last half of f f t ( x ) is zero, and the

first (DC) and center (Nyquist) elements of f f t ( x ) are purely real.

hilbert

Algorithm The analytic signal for a sequencex has a one-sided Fourier transform, that is,

negative frequencies are 0. To approximate the analytic signal, hi l bert

calculates the FFT of the input sequence, replaces those FFT coefficients thatcorrespond to negative frequencies with zeros, and calculates the inverse FFTof the result.

Page 489: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 489/870

7-208

In detail, hi l bert uses a four-step algorithm:

1 I t calculates the FFT of the input sequence, storing the result in a vector x.

2 I t creates a vector h whose elements h( i ) have the values:

-

1 for i = 1, ( n/ 2) +1- 2 for i = 2, 3, ... , ( n/ 2)

- 0 for i = ( n/ 2) +2, ... , n

3 I t calculates the element-wise product of x and h.

4 I t calculates theinverseF FT of thesequence obtained in step 3 and returnsthe first n elements of the result.

I f the input data xr is a matrix, hi l bert operates in a similar manner,

extending each step above to handle the matrix case.

Example xr = [ 1 2 3 4] ;

x = hi l ber t ( xr )

x =

1. 0000+1. 0000i 2. 0000- 1. 0000i 3. 0000- 1. 0000i 4. 0000+1. 0000i

You can see that the imaginary part, i mag( x) =[ 1 - 1 - 1 1] , is the Hilbert

transform of xr , and the real part, real ( x) =[ 1 2 3 4] , is simply xr itself.Note that the last half of f f t ( x ) =[ 10 - 4+4i - 2 0] is zero (in this example,thelast half is just thelast element), and that theDC and Nyquist elements of f f t ( x ) , 10 and -2 respectively, are purely real.

See Also f f t One-dimensional fast Fourier transform.

i f f t One-dimensional inverse fast Fourier transform.

r ceps Real cepstrum and minimum phase reconstruction.

hilbert

References [1] Claerbout, J .F., Fundamentals of Geophysical Data Processing,

McGraw-Hill, 1976, pp. 59-62.

[2] Marple, S.L., “Computing the discrete-time analytic signal via FFT,” I E E E Transactions on S ignal Processing, Vol. 47, No. 9 (September 1999),pp. 2600-2603.

Page 490: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 490/870

7-209

pp. 2600 2603.

[3] Oppenheim, A.V., and R.W. Schafer, Discrete-TimeSi gnal Processing,2nd ed., Prentice-Hall, 1998.

icceps

7iccepsPurpose I nverse complex cepstrum.

Syntax x = i cceps(xhat , nd)

Description x = i cceps(xhat , nd) returns the inverse complex cepstrum of the (assumedl) h t i d l f d l I f h t bt i d ith

Page 491: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 491/870

7-210

real) sequencexhat , removing nd samples of delay. I f xhat was obtained withcceps( x) , then the amount of delay that was added to x was the element of r ound( unwr ap( angl e( f f t ( x) ) ) / pi ) corresponding to π radians.

See Also

References [1] Oppenheim, A.V., and R.W. Schafer, Discrete-TimeSi gnal Processing,Prentice-Hall, 1989.

cceps Complex cepstral analysis.

hi l bert Hilbert transform.

r ceps Real cepstrum and minimum phase reconstruction.

unwr ap Unwrap phase angles.

idct

7idctPurpose I nverse discrete cosine transform.

Syntax x = i dct ( y)x = i dct ( y, n)

Description Theinverse discretecosine transform reconstructs a sequencefromits discrete

Page 492: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 492/870

7-211

Description Theinverse discretecosine transform reconstructs a sequencefromits discrete

cosine transform (DCT) coefficients. The i dct function is theinverseof thedct

function.

x = i dct ( y) returns the inverse discrete cosine transform of y

where

and N = l engt h( x) , which is the same as l engt h( y) . The series is indexedfrom n = 1and k = 1 instead of theusual n = 0and k = 0 because MATLABvectors run from 1 to N instead of from 0 to N-1.

x = i dct ( y, n) appends zeros or truncates the vector y to length n beforetransforming.

I f y is a matrix, i dct transforms its columns.

See Also

x n( ) w k( )y k( )π 2n 1–( ) k 1–( )

2N-------------------------------------------cos

k 1=

N

å n 1 … N, ,=,=

w k( )

1

N

--------- k 1=,

2N---- 2 k N≤ ≤,

î

=

dct Discrete cosine transform (DCT).

dct2 Two-dimensional DCT (see the I mage Processing Toolbox

documentation).

i dct2 Two-dimensional inverse DCT (see the I mage Processing Toolboxdocumentation).

i f f t One-dimensional inverse fast Fourier transform.

idct

References [1] J ain, A.K., Fundamentals of Digital I mageProcessing, Prentice-Hall, 1989.

[2] Pennebaker, W.B., and J .L. Mitchell, J PE G Stil l I mage Data Compression

Standard, Van Nostrand Reinhold, 1993, Chapter 4.

Page 493: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 493/870

7-212

ifft

7ifftPurpose One-dimensional inverse fast Fouri er transform.

Syntax y = i f f t (x)y = i f f t (x, n)

Description i f f t computes theinverseF ourier transform of a vector or array. This function

Page 494: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 494/870

7-213

Description i f f t computes theinverseF ourier transform of a vector or array. This function

implements the inverse transform given by

where W N =e- j(2π/N) and N = l engt h( x) . Note that the series is indexed asn +1and k +1 instead of theusual n and k becauseM ATL AB vectors run from1 to N instead of from 0 to N-1.

y = i f f t (x) is the inverse Fourier transform of vector x. I f x is an array, y is

the inverse FFT of each column of the matrix.

y = i f f t (x, n) is then-point inverseFF T. I f the length of x is lessthan n, i f f t

pads x with trailing zeros to length n. If the length of x is greater than n, i f f t

truncates the sequence x. When x is an array, i f f t adjusts the length of thecolumns in the same manner.

The i f f t function is part of the standard MATL AB language.

Algorithm The i f f t function is an M -file. The algorithm for i f f t is thesame as that for

f f t , except for a sign change and a scalefactor of n =l engt h( x) . The executiontime is fastest when n is a power of two and slowest when n is a large prime.

See Also

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

kn–

k 0=

N 1–

å=

f f t One-dimensional fast Fouri er transform.

f f t 2 Two-dimensional fast Fourier transform.

f f t shi f t Rearrange the outputs of f f t and f f t 2.

i f f t 2 Two-dimensional inverse fast Fourier transform.

ifft2

7ifft2Purpose Two-dimensional inverse fast F ouri er transform.

Syntax Y = i f f t 2( X) Y = i f f t 2( X, m, n)

Description Y = i f f t 2( X) returns the two-dimensional inverse fast Fourier transform

Page 495: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 495/870

7-214

p ( )

(FF T) of the array X. I f X is a vector, Y has the same orientation as X.

Y = i f f t 2( X, m, n) truncates or zero pads X, if necessary, to create an m-by-narray before performing the inverse FF T. The result Y is also m-by-n.

For any X, i f f t 2( f f t 2(X) ) equals X to within roundoff error. I f X is real,i f f t 2( f f t 2(X) ) may have small imaginary parts.

The i f f t 2 function is part of the standard MATL AB language.

Algorithm The algorithm for i f f t 2 is the same as that for f f t 2, except for a sign changeand scale factors of [mn] =si ze( X) . The execution time is fastest when m

and n are powers of two and slowest when they are large primes.

See Also f f t One-dimensional fast Fourier transform.

f f t 2 Two-dimensional fast Fourier transform.

f f t n N-dimensional fast Fourier transform (see theMATL AB documentation).

f f t shi f t Rearrange the outputs of f f t and f f t 2.

i f f t One-dimensional inverse fast Fourier transform.

i f f t n N-dimensional inverse fast Fourier transform (seethe MATL AB documentation).

impinvar

7impinvarPurpose I mpulse invariance method for analog-to-digital filter conversion.

Syntax [bz , az] = i mpi nvar ( b, a, f s )[bz , az] = i mpi nvar ( b, a)

[bz ,az] = i mpi nvar ( b, a, f s , t ol )

Page 496: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 496/870

7-215

Description [bz , az] = i mpi nvar ( b, a, f s ) creates a digital filter with numerator anddenominator coefficients bz and az, respectively, whose impulse response isequal to the impulse response of the analog fil ter with coefficients b and a,scaled by 1/ f s . I f you leave out the argument f s, or specify f s as the empty

vector [ ] , it takes the default value of 1 Hz.

[bz ,az] = i mpi nvar ( b, a, f s , t ol ) uses the tolerance specified by t ol todetermine whether poles are repeated. A larger tolerance increases thelikelihood that i mpi nvar interprets closely located poles as multiplicities(repeated ones). The default is 0.001, or 0.1% of a pole’s magnitude. Note thattheaccuracy of the pole values is stil l limited to theaccuracy obtainable by theroots function.

Examples Convert an analog lowpass filter to a digital filter using i mpi nvar with asampling frequency of 10 Hz.

[ b, a] = but t er ( 4, 0. 3, ' s' ) ;

[ bz, az] = i mpi nvar( b, a, 10)

bz =

1. 0e- 006 *

- 0. 0000 0. 1324 0. 5192 0. 1273 0

az =

1. 0000 - 3. 9216 5. 7679 - 3. 7709 0. 9246

impinvar

Algorithm i mpi nvar performs the impulse-invariant method of analog-to-digital transfer

function conversion discussed in reference [1]:

1 I t finds the partial fraction expansion of the system represented by b and a.

2 I t replaces the poles p by the poles exp( p/ f s) .

3 I t finds the transfer function coefficients of the system from the residues

Page 497: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 497/870

7-216

from step 1 and the poles from step 2.

See Also

References [1] Parks, T.W., and C.S. Burrus, Digital Filter Design, J ohn Wiley & Sons,

1987, pp. 206-209.

bi l i near Bi linear transformation method for analog-to-digitalfilter conversion.

l p2bp Tr ansform lowpass analog filters to bandpass.

l p2bs Tr ansform lowpass analog filters to bandstop.

l p2hp Transform lowpass analog filters to highpass.

l p2l p Change the cut-off frequency for a lowpass analog

filter.

impz

7impzPurpose Compute the impulse response of digital fil ters.

Syntax [ h, t ] = i mpz(b, a)[h, t ] = i mpz(b, a, n)

[h, t ] = i mpz(b, a, n, f s )

i mpz( b, a)

Page 498: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 498/870

7-217

i mpz( . . . )

Description [ h, t ] = i mpz(b, a) computes the impulse response of the filter with

numerator coefficients b and denominator coefficients a. i mpz chooses the

number of samples andreturns theresponsein thecolumn vector h andsampletimes in the column vector t (where t = [ 0: n- 1] ' , and n =l engt h( t ) iscomputed automatically).

[ h, t ] = i mpz(b, a, n) computes n samples of the impulse response when n isan integer (t =[ 0: n- 1] ' ). I f n is a vector of integers, i mpz computes the

impulseresponseat thoseinteger locations, starting the responsecomputationfrom 0 (and t =n or t =[ 0 n] ). I f, instead of n, you includethe empty vector [ ]

for the second argument, the number of samples is computed automatically bydefault.

[ h, t ] = i mpz(b, a, n, f s ) computes n samples and produces a vector t of

length n so that the samples are spaced 1/ f s units apart.

i mpz with no output arguments plots the impulse response in the currentfigure window using st em( t , h) .

i mpz works for both real and complex input systems.

Examples Plot the first 50 samples of the impulse response of a fourth-order lowpasselliptic filter with cutoff frequency of 0.4 times the Nyquist frequency.

[ b, a] = el l i p(4, 0. 5, 20, 0. 4) ;

i mpz( b, a, 50)

impz

0.3

0.4

0.5

Page 499: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 499/870

7-218

Algorithm i mpz filters a length n impulse sequence using

f i l ter ( b, a, [ 1 zeros(1, n- 1) ] )

and plots the results using stem.

To compute n in the auto-length case, i mpz either uses n = l ength(b) for the

FI R case or first finds the poles using p = r oot s ( a) , if l engt h( a) is greaterthan 1.

I f the filter is unstable, n is chosen to be the point at which the term from the

largest pole reaches 10 6 times its original value.I f the filter is stable, n is chosen to be the point at which the term due to thelargest amplitude pole is 5*10 - 5 of its original amplitude.

I f the filter is oscillatory (poles on the unit circle only), i mpz computes fiveperiods of the slowest oscil lation.

I f the filter has both oscillatory and damped terms, n is chosen to equal fiveperiods of the slowest oscillation or the point at which the term due to thelargest (nonunity) amplitude pole is 5*10 - 5 of its original amplitude,whichever is greater.

0 5 10 15 20 25 30 35 40 45-0.2

-0.1

0

0.1

0.2

impz

i mpz alsoallows for delays in the numerator polynomial. The number of delaysis incorporated into the computation for the number of samples.

See Also i mpul se Unit impulse response (see the Control System Toolboxdocumentation).

stem Plot discrete sequence data (see the MATL ABdocumentation)

Page 500: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 500/870

7-219

documentation).

interp

7interpPurpose I ncrease sampling rate by an integer factor (interpolation).

Syntaxy = i nt er p( x, r )

y = i nt er p( x, r , l , al pha)

[ y, b] = i nt er p( x, r , l , al pha)

Description I nterpolation increases the original sampling rate for a sequence to a higher

Page 501: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 501/870

7-220

Description I nterpolation increases the original sampling rate for a sequence to a higherrate. i nterp performs lowpass interpolation byinsertingzerosinto theoriginalsequence and then applying a special lowpass filter.

y = i nt er p( x, r ) increases the sampling rate of x by a factor of r . Theinterpolated vector y is r times longer than the original input x.

y = i nt er p( x, r , l , al pha) specifies l (filter length) and al pha (cut-off frequency). The default value for l is 4 and the default value for al pha is 0.5.

[ y, b] = i nt er p( x, r , l , al pha) returns vector b containing the filtercoefficients used for the interpolation.

Examples I nterpolate a signal by a factor of four.

t = 0: 0. 001: 1; % Ti me vector

x = si n( 2*pi *30*t ) + s i n( 2*pi *60*t ) ;

y = i nt er p( x, 4) ;

st em( x(1: 30) ) ;

t i t l e( ' Or i gi nal Si gnal ' ) ;

f i gure

st em( y(1: 120) ) ;t i t l e( ' I nterpol ated Si gnal ' ) ;

interp

0

0.5

1

1.5

2Interpolated Signal

0

0.5

1

1.5

2Original Signal

Page 502: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 502/870

7-221

Algorithm i nterp uses the lowpass interpolation Algorithm 8.1 described in [1]:

1 I t expands the input vector to the correct length by inserting zeros betweenthe original data values.

2 I t designs a special symmetric FI R filter that allowstheoriginal data topass

through unchanged and interpolates between so that the mean-squareerrors between theinterpolated points and their ideal values areminimized.

3 I t applies the filter to the input vector to produce the interpolated output

vector.

The length of the FI R lowpass interpolating filter is 2*l *r +1. The number of original sample values used for interpolation is 2*l . Ordinarily, l should beless than or equal to 10. Theoriginal signal is assumed to be band limited with

normalized cutoff frequency 0 ≤ al pha ≤ 1, where 1 is half theoriginal samplingfrequency (theNyquist frequency). The default value for l is 4 and the defaultvalue for al pha is 0.5.

Diagnostics I f r is not an integer, i nterp gives the following error message.

Resampl i ng r at e R must be an i nteger .

0 20 40 60 80 100 120-2

-1.5

-1

-0.5

0 5 10 15 20 25 30-2

-1.5

-1

-0.5

interp

See Also deci mat e Decrease the sampling rate for a sequence(decimation).

i nt er p1 One-dimensional data interpolation (table lookup)(see the MATL AB documentation).

r esampl e Change sampling rate by any rational factor.

spl i ne Cubic spline interpolation (see theMATL ABd i )

Page 503: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 503/870

7-222

References [1] Programs for Digital Signal P rocessing, I EE E P ress, New York, 1979,Algorithm 8.1.

documentation).

upf i r dn Upsample, apply an FI R filter, and downsample.

intfilt

7intfiltPurpose Interpolation FIR filter design.

Syntax b = i nt f i l t ( r , l , al pha)

b = i nt f i l t ( r , n, ' Lagrange' )

Description b = i nt f i l t ( r , l , al pha) designs a linear phaseF I R filter that performs ideal

bandlimited interpolation using the nearest 2*l nonzero samples, when used

Page 504: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 504/870

7-223

on a sequence interleaved with r - 1 consecutive zeros every r samples. I tassumes an original bandlimitedness of al pha times the Nyquist frequency. The returned filter is identical to that used by i nterp.

b = i nt f i l t ( r , n, ' Lagrange' ) or

b = i nt f i l t ( r , n, ' l ' ) designs an FI R fi lter that performs nth-orderL agrange polynomial interpolation on a sequence interleaved with r - 1

consecutivezerosevery r samples. b haslength ( n +1)*r for n even, andlength( n +1)* r -1 for n odd.

Both types of filters are basically lowpass and are intended for interpolation

and decimation.

Examples Design a digital interpolation filter to upsample a signal by four, using the

bandlimited method.

al pha = 0. 5; % "Bandl i mi tedness" f act or

h1 = i nt f i l t ( 4, 2, al pha) ; % Bandl i mi t ed i nt er pol at i on

The filter h1 works best when theoriginal signal i s bandlimited toal pha times

the Nyquist frequency. Create a bandlimited noise signal.

r andn( ' state' , 0)

x = f i l ter ( f i r1(40, 0. 5) , 1, randn( 200, 1) ) ; % Bandl i mi t

Now zero pad the signal with three zeros between every sample. The resultingsequence is four times the length of x.

xr = reshape( [ x zeros( l ength( x) , 3) ] ' , 4* l ength( x) , 1) ;

I nterpolate using the f i l t er command.

y = f i l t er ( h1, 1, xr ) ;

intfilt

y is an interpolated version of x, delayed by seven samples (thegroup-delay of the filter). Zoom in on a section to see this.

pl ot ( 100: 200, y(100: 200) , 7+( 101: 4: 196) , x(26: 49) , ' o' )

0.6

0.8

Page 505: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 505/870

7-224

i nt f i l t also performs L agrange polynomial interpolation of the originalsignal. For example, first-order polynomial interpolation is just l inearinterpolation, which is accomplished with a triangular filter.

h2 = i nt f i l t ( 4, 1, ' l ' ) % Lagrange i nterpol at i on

h2 =

0. 2500 0. 5000 0. 7500 1. 0000 0. 7500 0. 5000 0. 2500

Algorithm The bandlimited method uses f i r l s to design an interpolation FI R equivalentto that presented in [1]. The polynomial method uses L agrange’s polynomialinterpolation formula on equally spaced samples to construct the appropriatefilter.

See Also

100 110 120 130 140 150 160 170 180 190 200−1.2

−1

−0.8

−0.6

−0.4

−0.2

0

0.2

0.4

deci mat e Decrease the sampling rate for a sequence(decimation).

i nterpI ncrease sampling rate by an integer factor(interpolation).

r esampl e Change sampling rate by any rational factor.

intfilt

References [1] Oetken, Parks, and Schüßler, “New Results in the Design of Digital

I nterpolators,”I EEE Trans. Acoust., Speech, Si gnal Pr ocessing, Vol. ASSP-23(J une 1975), pp. 301-309.

Page 506: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 506/870

7-225

invfreqs

7invfreqsPurpose I dentify continuous-time filter parameters from frequency response data.

Syntax [ b, a] = i nvf reqs(h, w, nb, na)

[ b, a] = i nvf reqs(h, w, nb, na, wt )

[ b, a] = i nvf reqs(h, w, nb, na, wt , i ter )

[ b, a] = i nvf reqs(h, w, nb, na, wt , i ter , to l )

[b, a] = i nvf reqs(h, w, nb, na, wt , i t er , t ol , ' trace' )

[b ] i f (h ' l ' b )

Page 507: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 507/870

7-226

[b, a] = i nvf reqs(h, w, ' compl ex' , nb, na, . . . )

Description i nvf r eqs is the inverse operation of f r eqs; it finds a continuous-timetransfer

function that corresponds to a given complex frequency response. F rom alaboratory analysis standpoint, i nvf r eqs is useful in converting magnitudeand phase data into transfer functions.

[ b, a] = i nvf reqs(h, w, nb, na) returns the real numerator and denominatorcoefficient vectors b and a of the transfer function

whose complex frequency responseis given in vector h at the frequency pointsspecified in vector w. Scalars nb and na specify the desired orders of thenumerator and denominator polynomials.

Frequency is specified in radians between 0 and π, and the length of h must bethesame as the length of w. i nvf r eqs uses conj ( h) at - wto ensure the properfrequency domain symmetry for a real filter.

[ b, a] = i nvf reqs(h, w, nb, na, wt ) weights the fit-errors versus frequency,

where wt is a vector of weighting factors the same length as w.

[ b, a] = i nvf reqs(h, w, nb, na, wt , i ter ) and

[ b, a] = i nvf reqs(h, w, nb, na, wt , i ter , to l ) provide a superior algorithmthat guarantees stability of the resulting linear system and searches for thebest fit using a numerical, iterative scheme. The i t er parameter tells

i nvf r eqs to end the iteration when the solution has converged, or after i t er

iterations, whichever comes first. i nvf r eqs defines convergence as occurringwhen the norm of the(modified) gradient vector is less than t ol , where t ol is

H s( )B s( )

A s( )-----------

b 1( )snb b 2( )snb 1–L b n b 1+( )+ + +

a 1( )sna

a 2( )sna 1–

L

a na 1+( )+ + +

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

invfreqs

an optional parameter that defaults to 0.01. To obtain a weight vector of allones, use

i nvf reqs(h, w, nb, na, [ ] , i ter , tol )

[b, a] = i nvf reqs (h, w, nb, na, wt , i t er , t ol , ' trace' ) displays a textualprogress report of the iteration.

[b a] = i nvf reqs (h w ' compl ex' nb na ) creates a complex filter I n

Page 508: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 508/870

7-227

[b, a] = i nvf reqs (h, w, compl ex , nb, na, . . . ) creates a complex filter. I nthis case no symmetry is enforced, and the frequency is specified in radiansbetween -π and π.

Remarks When building higher order models using high frequencies, it is important toscale the frequencies, dividing by a factor such as half the highest frequencypresent in w, soas toobtain well conditioned values of a and b. This correspondsto a rescaling of time.

Examples Example 1

Convert a simple transfer function to frequency response data and then back

to the original filter coefficients.

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

[h, w] = f reqs (b, a, 64) ;

[ bb, aa] = i nvf reqs(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 that bb and aa are equivalent to b and a, respectively. However, aa haspoles in the left half-plane and thus the system is unstable. Use i nvf r eqs’siterative algorithm to find a stable approximation to the system.

[ bbb, aaa] = i nvf reqs(h, w, 4, 5, [ ] , 30)

bbb =

0. 6816 2. 1015 2. 6694 0. 9113 - 0. 1218

Page 509: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 509/870

7-228

aaa =

1. 0000 3. 4676 7. 4060 6. 2102 2. 5413 0. 0001

Example 2

Suppose you have two vectors, mag and phase, that contain magnitude andphase data gathered in a laboratory, and a third vector wof frequencies. You

can convert the data into a continuous-time transfer function using i nvf r eqs.

[ b, a] = i nvf r eqs( mag. *exp( j *phase) , w, 2, 3) ;

Algorithm By default, i nvf r eqs uses an equation error method to identify the best modelfrom the data. This finds b and a in

by creating a system of linear equations and solving them with MATL AB’s \

operator. Here A(w(k)) and B(w(k)) are the Fourier transforms of thepolynomials a and b, respectively, at the frequency w(k), and n is the numberof frequency points (the length of h and w). This algorithm is based on Levi [1].

Several variants have been suggested in the literature, where the weightingfunction wt gives less attention to high frequencies.

minb a,

wt k( ) h k( )A w k( )( ) B w k( )( )– 2

k 1=

n

å

invfreqs

The superior (“output-error”) algorithm uses thedamped Gauss-Newton methodfor iterative search [2], with theoutput of thefirst algorithm as the initialestimate. This solves the direct problem of minimizing theweighted sum of the

squared error between the actual and the desired frequency responsepoints.

minb a,

wt k( ) h k( )B w k( )( )

A w k( )( )--------------------–

2

k 1=

n

å

Page 510: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 510/870

7-229

See Also

References [1] L evi, E.C., “Complex-Curve Fitting,” I RE Trans. on Automatic Control,Vol. AC-4 (1959), pp. 37-44.

[2] Dennis, J .E., J r., and R.B. Schnabel. Numeri cal Methods for UnconstrainedOptimization and Nonlinear Equations. Englewood Cliffs, NJ : Prentice-Hall,1983.

k 1

f r eqs Compute the frequency response of analog filters.

f r eqz Compute the frequency response of digital filters.i nvf r eqz I dentify a discrete-time filter from frequency data.

prony I mplement Prony’s method for time domain I I R filterdesign.

invfreqz

7invfreqzPurpose I dentify discrete-time filter parameters from frequency response data.

Syntax [ b, a] = i nvf reqz(h, w, nb, na)

[ b, a] = i nvf reqz(h, w, nb, na, wt )

[ b, a] = i nvf reqz(h, w, nb, na, wt , i ter )

[ b, a] = i nvf reqz(h, w, nb, na, wt , i ter , to l )

[b, a] = i nvf reqz(h, w, nb, na, wt , i t er , t ol , ' trace' )

[b, a] = i nvf reqz(h, w, ' compl ex' , nb, na, . . . )

Page 511: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 511/870

7-230

[ , ] q ( , , p , , , )

Description i nvf r eqz is the inverse operation of f r eqz; it finds a discrete-time transfer

function that corresponds to a given complex frequency response. From alaboratory analysis standpoint, i nvf r eqz can be used to convert magnitudeand phase data into transfer functions.

[ b, a] = i nvf reqz(h, w, nb, na) returns the real numerator and denominatorcoefficients in vectors b and a of the transfer function

whose complex frequency responseis given in vector h at the frequency pointsspecified in vector w. Scalars nb and na specify the desired orders of thenumerator and denominator polynomials.

Frequency is specified in radians between 0 and π, and the length of h must bethesame as the length of w. i nvf r eqz uses conj ( h) at - wto ensure the properfrequency domain symmetry for a real filter.

[ b, a] = i nvf reqz(h, w, nb, na, wt ) weights the fit-errors versus frequency,where wt is a vector of weighting factors the same length as w.

[ b, a] = i nvf reqz(h, w, nb, na, wt , i ter ) and

[ b, a] = i nvf reqz(h, w, nb, na, wt , i ter , to l ) provide a superior algorithm

that guarantees stability of the resulting linear system and searches for the

best fit using a numerical, iterative scheme. Thei t er

parameter tellsi nvf r eqz to end the iteration when the solution has converged, or after i t er

iterations, whichever comes first. i nvf r eqz defines convergence as occurringwhen the norm of the(modified) gradient vector is less than t ol , where t ol is

H z( )B z( )

A z( )-----------

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

a 1( ) a 2( )z1–

L

a na 1+( )zna–

+ + +

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

invfreqz

an optional parameter that defaults to 0.01. To obtain a weight vector of allones, use

i nvf reqz(h, w, nb, na, [ ] , i ter , tol )

[b, a] = i nvf reqz (h, w, nb, na, wt , i t er , t ol , ' trace' ) displays a textualprogress report of the iteration.

[b, a] = i nvf reqz (h, w, ' compl ex' , nb, na, . . . ) creates a complex filter. I n

Page 512: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 512/870

7-231

this case no symmetry is enforced, and the frequency is specified in radiansbetween -π and π.

Examples Convert a simple transfer function to frequency response data and then backto the original filter coefficients.

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

[h, w] = f reqz (b, a, 64) ;

[ bb, aa] = i nvf reqz(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 that bb and aa are equivalent to b and a, respectively. However, aa haspoles outside the unit circle and thus the system is unstable. Use i nvf r eqz’siterative algorithm to find a stable approximation to the system.

[ bbb, aaa] = i nvf reqz(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 By default, i nvf r eqz uses an equation error method to identify the best model

from the data. This finds b and a in

by creating a system of linear equations and solving them with MATL AB’s \

operator Here A(ω(k)) and B(ω(k)) are the Fourier transforms of the

minb a,

wt k( ) h k( )A ω k( )( ) B ω k( )( )– 2

k 1=

n

å

Page 513: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 513/870

7-232

operator. Here A(ω(k)) and B(ω(k)) are the Fourier transforms of thepolynomials a and b, respectively, at the frequency ω(k), and n is the numberof frequency points (thelength of h and w). This algorithm is a based on L evi [1].

The superior (“output-error”) algorithm uses the damped Gauss-Newtonmethod for iterative search [2], with the output of the first algorithm as theinitial estimate. This solves thedirect problem of minimizing theweighted sumof the squared error between the actual and the desired frequency responsepoints.

See Also

References [1] L evi, E.C., “Complex-Curve F itting,” I RE Trans. on Automatic Control,Vol. AC-4 (1959), pp. 37-44.

[2] Dennis, J .E., J r., and R.B. Schnabel, Numeri cal Methods for Unconstrained

Optimization and Nonlinear Equations, Prentice-Hall, 1983.

minb a, wt k( ) h k( )

B ω k( )( )

A ω k( )( )-------------------

2

k 1=

n

å

f r eqs Compute the frequency response of analog fil ters.

f r eqz Compute the frequency response of digital filters.

i nvf r eqs Continuous-time (analog) filter identification fromfrequency data.

prony Prony’s method for time domain I I R fi lter design.

is2rc

7is2rcPurpose Convert i nverse sine parameters to reflection coefficients.

Syntax k = i s2r c( i si n)

Description k = i s2r c( i si n) returns a vector of reflection coefficients k from a vector of inverse sine parameters i s i n.

Examples i si n = [ 0. 2000 0. 8727 0. 0020 0. 0052 - 0. 0052] ;

k i 2 ( i i )

Page 514: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 514/870

7-233

k = i s2rc( i s i n)

k =

0. 3090 0. 9801 0. 0031 0. 0082 - 0. 0082

See Also

References [1] Deller, J .R., J .G. Proakis, and J .H.L. Hansen, “Discrete-TimeP rocessing of

Speech Signals,” Prentice-Hall, 1993.

ac2r c Convert autocorrelation parameters to reflectioncoefficients.

l ar2rc Convert log area ratio parameters to reflectioncoefficients.

pol y2r cConvert prediction filter coefficients to reflectioncoefficients.

rc2i s Convert reflection coefficients to inverse sine

parameters.

kaiser

7kaiserPurpose Compute a K aiser window.

Syntax w = kai ser( n, beta)

Description w = kai ser( n, beta) returns an n-point Kaiser (I 0 – sinh) window in thecolumn vector w. beta is the K aiser window β parameter that affects thesidelobe attenuation of the Fourier transform of the window.

To obtain a K aiser window that designs an FI R filter with sidelobe height

Page 515: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 515/870

7-234

g g-α dB, use the following β.

I ncreasing bet a widens the main lobe and decreases the amplitude of the

sidelobes (increases the attenuation).

Examples w = kai ser ( 200, 0. 5) ;pl ot ( w)

t i t l e( ' Kai ser Wi ndow, bet a = . 5' )

β

0.1102 α 8.7–( ), α 50>

0.5842 α 21–( )0.4 0.07886 α 21–( )+ , 50 α 21≥ ≥

0, α 21<î

=

0 20 40 60 80 100 120 140 160 180 2000.94

0.95

0.96

0.97

0.98

0.99

1Kaiser Window, beta = .5

kaiser

See Also bart l et t Compute a Bartlett window.

bl ackman Compute a Bl ackman window.

boxcar Compute a rectangular window.chebwi n Compute a Chebyshev window.

hammi ng Compute a Hamming window.

hann Compute a Hann window.

kai ser or d Estimate parameters for f i r 1 with a K aiser window.

Page 516: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 516/870

7-235

References [1] K aiser, J .F ., “Nonrecursive Digital F ilter Design Using the - sinhWindow Function,”Pr oc. 1974 I EEE Symp. Circuits and Systems, (April 1974),

pp. 20-23.

[2] Selected Papers in Digital Signal Processing I I , IE EE P ress, New York,1975.

[3] Oppenheim, A.V., and R.W. Schafer, Discrete-TimeSi gnal Processing,

Prentice-Hall, 1989, p. 453.

t r i ang Compute a triangular window.

I 0

kaiserord

7kaiserordPurpose Estimate parameters for an FI R filter design with a K aiser window.

Syntax [ n, Wn, bet a, f t ype] = kai ser or d( f , a, dev)

[ n, Wn, bet a, f type] = kai ser ord( f , a, dev, f s)

c = kai serord( f , a, dev, f s, ' cel l ' )

Description kai ser or d returns a filter order n and bet a parameter to specify a K aiserwindow for use with the f i r 1 function. Given a set of specifications in thefrequencydomain, kai ser or d estimates theminimum FI R filter order that will

Page 517: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 517/870

7-236

frequencydomain, kai ser or d estimates theminimum FI R filter order that willapproximately meet the specifications. kai ser or d converts the given filterspecifications into passband and stopband ripples and converts cutoff

frequencies into the form needed for windowed FI R filter design.

[ n, Wn, bet a, f t ype] = kai ser or d( f , a, dev) finds the approximate order n,normalized frequency band edges Wn, and weights that meet inputspecifications f , a, and dev. f is a vector of band edges and a is a vectorspecifying the desired amplitude on the bands defined by f . The length of f is

twicethe length of a, minus 2. Together, f and a define a desired piecewiseconstant responsefunction. dev is a vector the same sizeas a that specifies themaximum allowable error or deviation between the frequency response of theoutput filter and its desired amplitude, for each band. The entries in dev

specify the passband ripple and the stopband attenuation. Y ou specify eachentry in dev as a positive number, representing absolute filter gain (not in

decibels).

NoteI f, in the vector

dev, you specify unequal deviations across bands, theminimum specified deviation is used, since the K aiser window method is

constrained to produce filters with minimum deviation in all of the bands.

f i r 1 can use the resulting order n, frequency vector Wn, multiband magnitude

type f t ype, and the K aiser window parameter beta. The f t ype string isintended for usewith f i r 1; it is equal to' hi gh' for a highpass filter and ' stop'

for a bandstop filter. F or multiband filters, it can be equal to ' dc-0' when thefirst band is a stopband (starting at f =0) or ' dc-1' when the first band is apassband.

kaiserord

To design an F I R filter b that approximately meets the specifications given bykai ser parameters f , a, and dev, use the following command.

b = f i r1( n, Wn, kai ser( n+1, bet a) , f type, ' noscal e' )

[ n, Wn, beta, f t ype] = kai serord( f , a, dev, f s) uses a sampling frequency f s

in H z. I f you don’t specify the argument f s, or if you specify it as the emptyvector [ ] , it defaults to 2 Hz, and the Nyquist frequency is 1 Hz. You can usethis syntax to specify band edges scaled to a particular application’s samplingfrequency.

Page 518: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 518/870

7-237

frequency.

c = kai serord( f , a, dev, f s , ' cel l ' ) is a cell-array whose elements are the

parameters to f i r 1.

Note I n somecases, kai ser or d underestimates or overestimates the order n.I f thefilter does not meet thespecifications, try a higher order such asn+1, n+2,and so on, or a try lower order.

Results are inaccurate if the cutoff frequencies are near 0 or the Nyquist

frequency, or if dev is large (greater than 10%).

Algorithm kai ser or d uses empirically derived formulas for estimating the orders of lowpass filters, as well as differentiators and Hilbert transformers. Estimatesfor multiband filters (such as bandpass filters) are derived from the lowpassdesign formulas.

The design formulas that underlie the K aiser window and its application toFIR filter design are

where α =-20log10δ is the stopband attenuation expressed in decibels (recallthat δp =δs is required).

β

0.1102 α 8.7–( ), α 50>

0.5842 α 21–( )0.4 0.07886 α 21–( )+ , 50 α 21≥ ≥

0, α 21<î

=

kaiserord

The design formula is

where n is thefilter order and ∆ω is thewidth of thesmallest transition region.

Examples Example 1

Design a lowpass filter with passband defined from 0 to 1 kHz and stopbanddefined from 1500 Hz to 4 kHz. Specify a passband ripple of 5%and a stopband

nα 7.95–

2.285 ω∆( )

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

Page 519: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 519/870

7-238

defined from 1500 Hz to 4 kHz. Specify a passband ripple of 5%and a stopbandattenuation of 40 dB.

f samp = 8000;f cut s = [ 1000 1500] ;

mags = [ 1 0] ;

devs = [ 0. 05 0. 01] ;

[ n, Wn, bet a, f t ype] = kai ser or d( f cut s, mags, devs, f samp) ;

hh = f i r 1( n, Wn, f t ype, kai ser ( n+1, bet a) , ' noscal e' ) ;

f r eqz( hh)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−1400

−1200

−1000

−800

−600

−400

−200

0

Normalized Frequency (×π rad/sample)

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

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−120

−100

−80

−60

−40

−20

0

20

Normalized Frequency (×π rad/sample)

M a g n i t u d e ( d B )

kaiserord

Example 2

Design an odd-length bandpass filter (note that odd length means even order,so the input to f i r 1 must be an even integer).

f samp = 8000;

f cut s = [ 1000 1300 2210 2410] ;

mags = [ 0 1 0] ;

devs = [ 0. 01 0. 05 0. 01] ;

[ n, Wn, bet a, f t ype] = kai ser or d( f cut s, mags, devs, f samp) ;

n = n + r em( n, 2) ;

Page 520: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 520/870

7-239

( , ) ;

hh = f i r1(n, Wn, f t ype, kai ser( n+1, bet a) , ' noscal e' ) ;

[ H, f ] = f r eqz( hh, 1, 1024, f samp) ;pl ot ( f , abs(H) ) , gr i d on

Example 3

Design a lowpass filter with a passband cutoff of 1500 Hz, a stopband cutoff of

2000 Hz, passband ripple of 0.01, stopband ripple of 0.1, and a samplingfrequency of 8000 Hz.

[ n, Wn, bet a, f t ype] = kai ser or d( [ 1500 2000] , [ 1 0] , . . .

[ 0. 01 0. 1] , 8000) ;

b = f i r1( n, Wn, f type, kai ser( n+1, bet a) , ' noscal e' ) ;

0 500 1000 1500 2000 2500 3000 3500 40000

0.2

0.4

0.6

0.8

1

1.2

1.4

kaiserord

This is equivalent to

c = kai seror d( [ 1500 2000] , [ 1 0] , [ 0. 01 0. 1] , 8000, ' cel l ' ) ;

b = f i r 1( c: ) ;

Remarks Be careful todistinguish between themeanings of filter length and filter order. The filter length is the number of impulse response samples in the FI R filter.Generally, theimpulseresponseis indexed fromn =0ton =L -1, where L isthefilter length. The filter order is the highest power in a z-transformrepresentation of thefilter. F or an FI R transfer function, this representation is

Page 521: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 521/870

7-240

a polynomial in z, where the highest power is zL -1 and the lowest power is z0.

The filter order is onelessthan thelength (L -1) and is alsoequal tothenumberof zeros of the z polynomial.

See Also

References [1] K aiser, J .F., “Nonrecursive Digital F ilter Design Using the - sinhWindow Function,”Proc. 1974I EE E Symp. Circuits and Systems, (April 1974),pp. 20-23.

[2] Selected Papers in Digital Signal P rocessing I I , IE EE Press, New York,1975, pp. 123-126.

[3] Oppenheim, A.V., and R.W. Schafer, Discrete-TimeSi gnal Processing,

Prentice-Hall, 1989, pp. 458-562.

f i r 1 Window-based finite impulse responsefilter design –standard response.

kai ser K aiser window.

r emezor d Parks-McClellan optimal F I R filter order estimation.

I 0

lar2rc

7lar2rcPurpose Convert log area ratio parameters to reflection coefficients.

Syntax k = l ar 2r c( g)

Description k = l ar 2r c( g) returns a vector of reflection coefficients k from a vector of logarea ratio parameters g.

Examples g = [ 0. 6389 4. 5989 0. 0063 0. 0163 - 0. 0163] ;

k = l ar 2r c( g)

Page 522: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 522/870

7-241

k =

0. 3090 0. 9801 0. 0031 0. 0081 - 0. 0081

See Also

References [1] Deller, J .R., J .G. Proakis, and J .H.L. Hansen, “Discrete-TimeP rocessing of

Speech Signals,” Prentice-Hall, 1993.

ac2r c Convert autocorrelation parameters to reflectioncoefficients.

i s2rc Convert inverse sine parameters to reflectioncoefficients.

pol y2r c Convert prediction filter coefficients to reflection

coefficients.

rc2l ar Convert reflection coefficients to log area ratioparameters.

latc2tf

7latc2tf Purpose Convert lattice filter parameters to transfer function form.

Syntax [ num, den] = l at c2t f ( k, v)

[ num, den] = l atc2t f ( k, ' i i ropt i on' )

num = l at c2t f ( k, ' f i r opt i on' )

num = l atc2t f ( k)

Description [ num, den] = l at c2t f ( k, v) finds the transfer function numerator numanddenominator den from the I I R latticecoefficients k and ladder coefficients v.

Page 523: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 523/870

7-242

[ num, den] = l atc2t f ( k, ' i i ropt i on' ) produces an II R filter transfer

function according to the value of the string ' i i ropt i on' :

• ' al l pol e' : Produces an all-pole filter transfer function from the associatedall-pole I I R lattice filter coefficients k.

• ' al l pass' : Produces an all pass filter transfer function from the associatedallpass I I R lattice filter coefficients k.

num = l at c2t f ( k, ' f i r opt i on' ) produces an FI R filter according to thevalue

of the string ' f i r opt i on' :

• ' mi n' : Produces a minimum-phase FI R filter numerator from the associatedminimum-phase FI R lattice filter coefficients k.

• ' max' : Produces a maximum-phaseFI R filter numerator fromtheassociatedmaximum-phase FI R lattice fil ter coefficients k.

• ' FI R' : Produces a general F I R filter numerator from the lattice filtercoefficients k (default, if you leave off the string altogether).

See Also l at cf i l t L attice and lattice-ladder filter implementation.

t f 2l at c Convert transfer function filter parameters to latticefilter form.

latcfilt

7latcfiltPurpose L attice and lattice-ladder filter implementation.

Syntax [ f , g] = l at cf i l t ( k, x)

[ f , g] = l at cf i l t ( k, v, x)

[ f , g] = l at cf i l t ( k, 1, x)

[ f , g, zf ] = l at cf i l t ( . . . , ' i c' , z i )

Description When filtering data, lattice coefficients can be used to represent:

• FIR filters

Page 524: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 524/870

7-243

• All-pole I I R filters

• Allpass I I R filters

• General IIR filters

[ f , g] = l at cf i l t ( k, x) filters x with the FI R lattice coefficients in thevector k. f is theforward lattice filter result and g is thebackward filter result.I f , f corresponds tothe minimum-phaseoutput, andg corresponds tothemaximum-phase output.

I f k and x are vectors, the result is a (signal) vector. Matrix arguments arepermitted under the foll owing rules:

• I f x is a matrix and k is a vector, each column of x is processed through thelattice filter specified by k.

• I f x is a vector and k is a matrix, each column of k is used to filter x, and asignal matrix is returned.

I f x

andk

are both matrices with the same number of columns, then theithcolumn of k is used to filter the ith column of x. A signal matrix is returned.

[ f , g] = l at cf i l t ( k, v, x) filters x with the I I R lattice coefficients k andladder coefficients v. k and v must be vectors, while x can be a signal matrix.

[ f , g] = l at cf i l t ( k, 1, x) filters x with theI I R lattice specified by k, where k

and x can bevectors or matrices. f is theall-pole lattice filter result andg istheallpass filter result.

[ f , g, zf ] = l at cf i l t ( . . . , ' i c' , z i ) accepts a length-k vector zi specifyingthe initial condition of the lattice states. Output zf is a length-k vectorspecifying the final condition of the lattice states.

k 1≤

latcfilt

See Also f i l t er Filter data with a recursive (I I R) or nonrecursive(FI R) filter.

l at c2t f Convert lattice filter parameters to transfer functionform.

t f 2l at c Convert transfer function filter parameters to latticefilter form.

Page 525: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 525/870

7-244

levinson

7levinsonPurpose Compute the Levinson-Durbin recursion.

Syntax a = l evi nson( r , p)

Description The L evinson-Durbin recursion is an algorithm for finding an all-pole I I R filterwith a prescribed deterministicautocorrelation sequence. I t hasapplicationsinfilter design, coding, andspectral estimation. The fil ter that l evi nson producesis minimum phase.

a = l evi nson( r , p) finds the coefficients of an pth-order autoregressive linear

Page 526: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 526/870

7-245

process which has r as its autocorrelation sequence. r is a real or complex

deterministic autocorrelation sequence (a vector), and p is the order of denominator polynomial A(z); that is, a = [ 1 a( 2) . . . a( p+1) ] . The filtercoefficients are ordered in descending powers of z.

Algorithm l evi nson solves the symmetric Toeplitz system of linear equations

where r = [ r(1) ... r(p+1)] is the input autocorrelation vector, and r(i)*

denotes the complexconjugateof r(i). The algorithm requiresO(p2) flops and isthus much more efficient than the MA TL AB \ command for large p. However,the l evi nson function uses \ for low orders to provide the fastest possible

execution.

H z( )1

A z( )-----------

1

1 a 2( )z 1–L a p 1+( )z p–+ + +

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

r 1( ) r 2( )∗

L r p( )∗

r 2( ) r 1( ) L r p 1–( )∗

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

a 2( )

a 3( )

a p 1+( )

r 2( )–

r 3( )–

r p 1+( )–

=

levinson

See Also l pc Compute li near prediction fi lter coefficients.

prony Prony’s method for time domain I I R filter design.

r l evi nson Compute the reverse L evinson-Durbin recursion.

schurrc Compute reflection coefficients using Schur’salgorithm.

st mcb Compute a linear model using Steiglitz-McBrideiteration.

Page 527: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 527/870

7-246

References [1] L jung, L ., System I dentification: Theory for the User, Prentice-Hall, 1987,

pp. 278-280.

lp2bp

7lp2bpPurpose Transform lowpass analog filters to bandpass.

Syntax [ bt , at ] = l p2bp( b, a, Wo, Bw)

[ At , Bt , Ct , Dt ] = l p2bp( A, B, C, D, Wo, Bw)

Description l p2bp transforms analog lowpass fil ter prototypes with a cutoff frequency of

1 rad/sinto bandpassfilters with desired bandwidth and center frequency. Thetransformation is one step in the digital filter design process for the but t er ,cheby1, cheby2, and el l i p functions.

l p2bp can perform the transformation on two different linear system

Page 528: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 528/870

7-247

l p2bp can perform the transformation on two different linear system

representations:transfer function form andstate-spaceform. I n both cases, theinput system must be an analog filter prototype.

Transfer Function Form (Polynomial)

[ bt , at ] = l p2bp( b, a, Wo, Bw) transforms an analog lowpass filter prototypegiven by polynomial coefficients into a bandpass filter with center frequency Wo

andbandwidth Bw. Rowvectors b and a specify the coefficients of the numerator

and denominator of the prototype in descending powers of s.

Scalars Wo and Bwspecify the center frequency and bandwidth in units of rad/s.

For a filter with lower band edge w1 and upper band edge w2, useWo =sqr t ( w1*w2) and Bw=w2- w1.

l p2bp returns the frequency transformed fil ter in row vectors bt and at .

State-Space Form

[ At , Bt , Ct , Dt ] = l p2bp( A, B, C, D, Wo, Bw) converts the continuous-timestate-space lowpass filter prototype in matrices A, B, C, Dshown below

b s( )

a s( )----------

b 1( )snbL b n b( )s b nb 1+( )+ + +

a 1( )snaL a na( )s a na 1+( )+ + +

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

x· Ax B u+=

y Cx Du+=

lp2bp

into a bandpass filter with center frequency Wo and bandwidth Bw. For a filterwith lower band edge w1 and upper band edge w2, use Wo =sqr t ( w1*w2) andBw=w2- w1.

The bandpass filter is returned in matrices At , Bt , Ct , Dt .

Algorithm l p2bp is a highly accurate state-space formulation of the classic analog filterfrequency transformation. Consider the state-space system

x· Ax B u+=

y Cx Du+=

Page 529: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 529/870

7-248

where u is the input, x is the state vector, and y is the output. The Laplacetransform of the first equation (assuming zero initial conditions) is

Now if a bandpass filter is to havecenter frequency ω0 and bandwidth Bw, thestandard s-domain transformation is

where Q =ω0/Bw and p =s/ω0. Substituting this for s in the L aplacetransformed state-space equation, and considering the operator p as d/dt

results in

or

Now define

which, when substituted, leads to

y

sX s( ) AX s( ) B U s( )+=

s Q p2 1+( ) p ⁄ =

Qx·· Qx+ A·

x B u·+=

Qx·· A·

– x B– u· Qx–=

Qω·

Qx–=

Qx· Ax Qω B u+ +=

lp2bp

The last two equations give equations of state. Write them in standard formand multiply the differential equations by ω0 to recover the time/frequencyscaling represented by p and find state matrices for the bandpass filter.

Q = Wo/ Bw; [ ma, na] = si ze( A) ;

At = Wo*[ A/ Q eye( ma, na) ; - eye( ma, na) zeros( ma, na) ] ;

Bt = Wo*[ B/ Q; zer os( ma, nb) ] ;

Ct = [ C zer os( mc, ma) ] ;

Dt = d;

If theinput tol p2bp is in transfer function form, thefunction transforms it intostate-space form before applying this algorithm

Page 530: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 530/870

7-249

state space form before applying this algorithm.

See Also bi l i near Bili near transformation method for analog-to-digitalfilter conversion.

i mpi nvar I mpulsei nvariancemethod for analog-to-digital filterconversion.

l p2bs Transform lowpass analog filters to bandstop.

l p2hp Transform lowpass analog filters to highpass.

l p2l p Change the cut-off frequency for a lowpass analogfilter.

lp2bs

7lp2bsPurpose Transform lowpass analog filters to bandstop.

Syntax [ bt , at ] = l p2bs(b, a, Wo, Bw)

[ At , Bt , Ct , Dt ] = l p2bs(A, B, C, D, Wo, Bw)

Description l p2bs transforms analog lowpass filter prototypes with a cutoff frequency of

1 rad/s into bandstop filters with desired bandwidth and center frequency. Thetransformation is one step in the digital filter design process for the but t er ,cheby1, cheby2, and el l i p functions.

l p2bs can perform the transformation on two different linear system

Page 531: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 531/870

7-250

representations:transfer function form andstate-spaceform. I n both cases, theinput system must be an analog filter prototype.

Transfer Function Form (Polynomial)

[ bt , at ] = l p2bs(b, a, Wo, Bw) transforms an analog lowpass fil ter prototypegiven by polynomial coefficients into a bandstop fil ter with center frequency Wo

and bandwidth Bw. Rowvectors b and a specify the coefficients of the numerator

and denominator of the prototype in descending powers of s.

Scalars Wo and Bwspecify the center frequency and bandwidth in units of

radians/second. F or a filter with lower band edge w1 and upper band edge w2,use Wo =sqr t ( w1*w2) and Bw=w2- w1.

l p2bs returns the frequency transformed filter in row vectors bt and at .

State-Space Form

[ At , Bt , Ct , Dt ] = l p2bs(A, B, C, D, Wo, Bw) converts the continuous-timestate-space lowpass filter prototype in matrices A, B, C, D shown below

b s( )

a s( )----------

b 1( )snbL b nb( )s b nb 1+( )+ + +

a 1( )snaL a na( )s a na 1+( )+ + +

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

x· Ax B u+=

y Cx Du+=

lp2bs

into a bandstop filter with center frequency Wo and bandwidth Bw. For a filterwith lower band edge w1 and upper band edge w2, use Wo =sqr t ( w1*w2) andBw=w2- w1.

The bandstop filter is returned in matrices At , Bt , Ct , Dt .

Algorithm l p2bs is a highly accurate state-space formulation of the classic analog filterfrequency transformation. I f a bandstop filter is to have center frequency ω0and bandwidth Bw, the standard s-domain transformation is

sp

Q p2 1+( )------------------------=

Page 532: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 532/870

7-251

where Q =ω0/Bw and p =s/ω0. The state-space version of this transformation is

Q = Wo/ Bw;

At = [ Wo/ Q*i nv( A) Wo*eye(ma) ; - Wo*eye(ma) zeros( ma) ] ;

Bt = - [ Wo/ Q*( A B) ; zer os( ma, nb) ] ;

Ct = [ C/ A zer os( mc, ma) ] ;

Dt = D - C/ A*B;

See l p2bp for a derivation of the bandpass version of this transformation.

See Also

Q p 1+( )

bi l i near Bili near transformation method of analog-to-digitalfilter conversion.

i mpi nvar I mpulse invariance method of analog-to-digital filterconversion.

l p2bp Transform lowpass analog filters to bandpass.

l p2hp Transform lowpass analog filters to highpass.l p2l p Change the cut-off frequency for a lowpass fil ter.

lp2hp

7lp2hpPurpose Transform lowpass analog filters to highpass.

Syntax [ bt , at ] = l p2hp( b, a, Wo)

[ At , Bt , Ct , Dt ] = l p2hp( A, B, C, D, Wo)

Description l p2hp transforms analog lowpass filter prototypes with a cutoff frequency of

1 rad/s into highpass filters with desired cutoff frequency. The transformationis one step in the digital filter design process for the but t er , cheby1, cheby2,and el l i p functions.

The l p2hp function can perform the transformation on two different linear

Page 533: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 533/870

7-252

system representations: transfer function form and state-space form. I n bothcases, the input system must be an analog filter prototype.

Transfer Function Form (Polynomial)

[ bt , at ] = l p2hp( b, a, Wo) transforms an analog lowpass filter prototypegiven by polynomial coefficients into a highpass filter with cutoff frequency Wo.

Row vectors b and a specify the coefficients of the numerator and denominator

of the prototype in descending powers of s.

Scalar Wo specifies the cutoff frequency in units of radians/second. The

frequency transformed filter is returned in row vectors bt and at .

State-Space Form

[ At , Bt , Ct , Dt ] = l p2hp( A, B, C, D, Wo) converts the continuous-timestate-space lowpass filter prototype in matrices A, B, C, D below

into a highpass filter with cutoff frequency Wo. The highpass filter is returned

in matrices At , Bt , Ct , Dt .

b s( )

a s( )----------

b 1( )snbL b nb( )s b nb 1+( )+ + +

a 1( )snaL a na( )s a na 1+( )+ + +

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

x· Ax B u+=

y Cx Du+=

lp2hp

Algorithm l p2hp is a highly accurate state-space formulation of the classic analog filter

frequency transformation. I f a highpass filter is tohavecutoff frequency ω0,thestandard s-domain transformation is

The state-space version of this transformation is

At = Wo*i nv( A) ;

Bt = - Wo*(A\ B) ;

Ct = C/ A;

sω0

p-------=

Page 534: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 534/870

7-253

Dt = D - C/ A*B;

See l p2bp for a derivation of the bandpass version of this transformation.

See Also bi l i near Bili near transformation method for analog-to-digitalfilter conversion.

i mpi nvar I mpulsei nvariancemethod for analog-to-digital filterconversion.

l p2bp Transform lowpass analog filters to bandpass.

l p2bs Transform lowpass analog filters to bandstop.

l p2l p Change the cut-off frequency for lowpass analogfilters.

lp2lp

7lp2lpPurpose Change the cut-off frequency for a lowpass analog filter.

Syntax [bt , at ] = l p2l p(b, a, Wo)

[ At , Bt , Ct , Dt ] = l p2l p( A, B, C, D, Wo)

Description l p2l p transforms an analoglowpass filter prototype with a cutoff frequency of

1 rad/s into a lowpass filter with any specified cutoff frequency. Thetransformation is one step in the digital filter design process for the but t er ,cheby1, cheby2, and el l i p functions.

The l p2l p function can perform the transformation on two different linear

Page 535: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 535/870

7-254

system representations: transfer function form and state-space form. I n bothcases, the input system must be an analog filter prototype.

Transfer Function Form (Polynomial)

[bt , at ] = l p2l p(b, a, Wo) transforms an analog lowpass filter prototypegiven by polynomial coefficients into a lowpass filter with cutoff frequency Wo.

Row vectors b and a specify the coefficients of the numerator and denominator

of the prototype in descending powers of s.

Scalar Wo specifies the cutoff frequency in units of radians/second. l p2l p

returns the frequency transformed filter in row vectors bt and at .

State-Space Form

[ At , Bt , Ct , Dt ] = l p2l p( A, B, C, D, Wo) converts the continuous-timestate-space lowpass filter prototype in matrices A, B, C, D below

into a lowpass filter with cutoff frequency Wo. l p2l p returns the lowpass filter

in matrices At , Bt , Ct , Dt .

b s( )

a s( )----------

b 1( )snbL b nb( )s b nb 1+( )+ + +

a 1( )snaL a na( )s a na 1+( )+ + +

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

x· Ax B u+=

y Cx Du+=

lp2lp

Algorithm l p2l p is a highly accurate state-space formulation of the classic analog filter

frequency transformation. I f a lowpass filter is to havecutoff frequency ω0, thestandard s-domain transformation is

The state-space version of this transformation is

At = Wo*A;

Bt = Wo*B;

Ct = C;

Dt = D;

s p ω0 ⁄ =

Page 536: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 536/870

7-255

See l p2bp for a derivation of the bandpass version of this transformation.

See Also bi l i near Bili near transformation method for analog-to-digital

filter conversion.

i mpi nvar I mpulsei nvariancemethod for analog-to-digital filterconversion.

l p2bp Transform lowpass analog filters to bandpass.

l p2bs Transform lowpass analog filters to bandstop.

l p2hp Transform lowpass analog filters to highpass.

lpc

7lpcPurpose Compute linear prediction filter coefficients.

Syntax a = l pc( x, p)

Description l pc determines the coefficients of a forward linear predictor by minimizing theprediction error i n the least squares sense. I t has applications in filter designand speech coding.

a = l pc( x, p) finds the coefficients of a pth-order linear predictor (FI R fil ter)that predicts the current value of the real-valued time series x based on past

samples.

Page 537: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 537/870

7-256

p is the order of the prediction filter polynomial, a =[ 1 a( 2) . . . a( p+1) ] . I f p is unspecified, l pc uses as a default p =l engt h( x) - 1. I f x is a matrixcontaining a separate signal in each column, l pc returns a model estimate foreach column in the rows of matrix a.

Examples Estimate a data series using a third-order forward predictor, and compare tothe original signal.

First, create the signal data as the output of an autoregressive process drivenby white noise. Use the last 4096 samples of the AR process output to avoid

start-up transients.

randn( ' stat e' , 0) ;

noi se = r andn( 50000, 1) ; % Nor mal i zed whi t e Gaussi an noi se

x = f i l t er ( 1, [1 1/ 2 1/ 3 1/ 4] , noi se) ;x = x(45904: 50000) ;

Compute the predictor coefficients, estimated signal, prediction error, andautocorrelation sequence of the prediction error.

a = l pc( x, 3) ;

est _ x = f i l t er ( [ 0 - a( 2: end) ] , 1, x) ; % Est i mat ed si gnal

e = x - est _x; % Pr edi ct i on er r or

[ acs, l ags] = xcor r ( e, ' coef f ' ) ; % ACS of pr edi ct i on er ror

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

lpc

The prediction error, e(n), can be viewed as the output of the prediction errorfilter A(z) shown below, where H(z) is the optimal linear predictor, x(n) is theinput signal, and is the predicted signal.x n( )

H z( ) a– 2( )z1–

a– 3( )z2–L– a– n 1+( )z

p–= Σ

x n( )x n( )

–+

e n( )

Prediction Error

A

Page 538: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 538/870

7-257

Compare the predicted signal to the original signal.

pl ot ( 1: 97, x( 4001: 4097) , 1: 97, est _x( 4001: 4097) , ' - - ' ) ;

t i t l e( ' Or i gi nal Si gnal vs. LPC Est i mat e' ) ;

xl abel ( ' Sampl e Number ' ) ; yl abel ( ' Ampl i t ude' ) ; gr i d;

l egend( ' Or i gi nal Si gnal ' , ' LPC Est i mat e' )

L ook at the autocorrelation of the prediction error.

pl ot ( l ags, acs) ;

t i t l e( ' Aut ocorr el at i on of the Predi ct i on Err or ' ) ;

xl abel ( ' Lags' ) ; yl abel ( ' Normal i zed Val ue' ) ; gr i d;

A z( )

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 approximately white Gaussian noise, as expected for athird-order AR input process.

0.4

0.6

0.8

1

1.2

Autocorrelation of the Prediction Error

N o r m a l i z e d V a l u e

Page 539: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 539/870

7-258

Algorithm l pc uses the autocorrelation method of autoregressive (AR) modeling to find

the filter coefficients. The generated fil ter might not model the process exactlyeven if the data sequence is truly an AR process of thecorrect order. This isbecause the autocorrelation method implicitly windows the data, that is, itassumes that signal samples beyond the length of x are 0.

l pc computes the least squares solution to

where

−5000 −4000 −3000 −2000 −1000 0 1000 2000 3000 4000 5000−0.2

0

0.2

Lags

Xa b≈

X

x 1( ) 0 L 0

x 2( ) x 1( )

x 2( ) 0

x m( ) x 1( )

0 x m( ) x 2( )

0 L 0 x m( )

= a

1

a 2( )

a p 1+( )

= b

1

0

0

=, ,

lpc

and mis the length of x. Solving the least squares problem via the normalequations

leads to the Yule-Walker equations

h [ (1) (2) ( +1)] i t l ti ti t f t d

XH Xa XH b=

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

r 2( ) r 1( )

r 2( )*

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

a 2( )

a 3( )

a p 1+( )

r 2( )–

r 3( )–

r p 1+( )–

=

Page 540: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 540/870

7-259

where r = [ r(1) r(2) ... r(p+1)] is an autocorrelation estimate for x computedusing xcor r . The Yule-Walker equations are solved in O(p2) flops by theL evinson-Durbin algorithm (see l evi nson).

See Also

References [1] J ackson, L .B., Digital Fil ters and Signal Pr ocessing, Second Edition,

K luwer Academic Publishers, 1989. pp. 255-257.

ar yul e Compute an estimate of AR model parameters using

the Yule-Walker method.

l evi nson Compute the L evinson-Durbin recursion.

prony Prony’s method for time domain I I R filter design.

pyul ear Estimate the power spectral density using the Yule-Walker AR method.

st mcb Compute a linear model using Steiglitz-McBrideiteration.

lsf2poly

7lsf2polyPurpose Convert line spectral frequencies to prediction filter coefficients.

Syntax a = l sf 2pol y( l sf )

Description a = l sf 2pol y( l sf ) returns a vector a containing the prediction filtercoefficients from a vector l sf of line spectral frequencies (also known as linespectrum pairs).

Examples l sf = [ 0. 7842 1. 5605 1. 8776 1. 8984 2. 3593] ;

a = l sf 2pol y( l sf )

a = 1 0000 0 6148 0 9899 0 0001 0 0031 0 0081

Page 541: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 541/870

7-260

a = 1. 0000 0. 6148 0. 9899 0. 0001 0. 0031 - 0. 0081

See Also

References [1] Deller, J .R., J .G. Proakis, and J .H.L. Hansen, “Discrete-TimeP rocessing of

Speech Signals,” Prentice-Hall, 1993.

[2] Rabiner, L .R., and R.W. Schafer, “Digital Processing of Speech Signals,”Prentice-Hall, 1978.

ac2pol y Convert autocorrelation parameters to predictionfilter coefficients.

pol y2l sf Convert prediction filter coefficients to li ne spectralfrequencies.

r c2pol y Convert reflection coefficients to prediction filtercoefficients.

maxflat

7maxflatPurpose Generalized digital Butterworth filter design.

Syntax [ b, a, ] = maxf l at ( nb, na, Wn)

b = maxf l at ( nb, ' sym' , Wn)[ b, a, b1, b2] = maxf l at ( nb, na, Wn)

[ . . . ] = maxf l at ( nb, na, Wn, ' desi gn_f l ag' )

Description [ b, a, ] = maxf l at ( nb, na, Wn) is a lowpass Butterworth filter with numeratorand denominator coefficients b and a of orders nb and na respectively. Wn is thenormalized cutoff frequency at which the magnitude response of the filter is

equal to (approx. -3 dB). Wn must be between 0 and1, where 1 corresponds

to the Nyquist frequency

1 2 ⁄

Page 542: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 542/870

7-261

to the Nyquist frequency.

b = maxf l at ( nb, ' sym' , Wn) is a symmetric FI R Butterworth filter. nb must beeven, and Wn is restricted to a subinterval of [0,1]. The function raises an errorif Wn is specified outside of this subinterval.

[ b, a, b1, b2] = maxf l at ( nb, na, Wn) returns twopolynomials b1 and b2 whoseproduct is equal to the numerator polynomial b (that is, b = conv( b1, b2) ).

b1 contains all the zeros at z =- 1, and b2 contains all the other zeros.

[ . . . ] = maxf l at ( nb, na, Wn, ' desi gn_f l ag' ) enablesyou tomonitor thefil terdesign, where ' desi gn_f l ag' is:

• ' t r ace' , for a textual display of the design table used in the design

• ' pl ot s ' , for plots of the filter’s magnitude, group delay, and zeros and poles

• ' bot h' , for both the textual display and plots

Examples nb = 10; na = 2; Wn = 0. 2;

[ b, a, b1, b2] = maxf l at ( nb, na, Wn, ' pl ots ' )

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

1

Pole−zero plot

7

8Group delay

Page 543: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 543/870

7-262

Algorithm The method consists of the use of formulae, polynomial root finding, and atransformation of polynomial roots.

See Also

References [1] Selesnick, I .W., and C.S. Burrus, “Generalized Digital Butterworth FilterDesign,”Pr oceedings of theI E EE I nt. Conf. Acoust., Speech, Signal Processing,

Vol. 3 (May 1996).

−1 0 1

−1

−0.5

0

0.5

Real

I m a g i n a r y

<− deg 10

0 0.5 14

5

6

7

ω / π

S a m p l e s

but t er Butterworth analog and digital filter design.

f i l t er Filter data with a recursive (II R) or nonrecursive

(FI R) filter.f r eqz Compute the frequency response of digital filters.

medfilt1

7medfilt1Purpose One-dimensional median filteri ng.

Syntax y = medf i l t 1(x ,n)

y = medf i l t1( x, n, bl ksz)

Description y = medf i l t 1(x ,n) applies an order n one-dimensional median filter to

vector x; the function considers the signal to be 0 beyond the end points.Output y has the same length as x.

For n odd, y(k) is the median of x( k- ( n- 1) / 2: k+( n- 1) / 2) .

F or n even, y(k) is the median of x( k-n/ 2) , x(k- ( n/ 2) +1) , ..., x(k+( n/ 2) - 1) .

I n this case, medf i l t 1 sorts the numbers, then takes the average of thed l

Page 544: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 544/870

7-263

, , g(n -1 ) / 2 and ( ( n- 1) / 2) +1 elements.

The default for n is 3.

y = medf i l t1( x, n, bl ksz) uses a f or -loop to compute bl ksz (block size)output samples at a time. Usebl ksz <<l engt h( x) if you are low on memory,

since medf i l t 1 uses a working matrix of size n-by-bl ksz. By default,bl ksz = l ength(x ) ; this provides the fastest execution if you have sufficientmemory.

I f x is a matrix, medf i l t 1 median filters its columns using

y( : , i ) = medf i l t 1( x( : , i ) , n, bl ksz)

in a loop over the columns of x.

See Also

References [1] Pratt, W.K ., Digital I mage Processing, J ohn Wiley & Sons, 1978,pp. 330-333.

f i l t er Filter data with a recursive (II R) or nonrecursive

(FI R) filter.

medf i l t 2 Two-dimensional median filtering (see the I mageProcessing Toolbox documentation).

medi an Median value (see the MAT LAB documentation).

modulate

7modulatePurpose Modulation for communications simulation.

Syntax y = modul ate(x , f c, f s , ' met hod' )

y = modul ate(x , f c, f s , ' met hod' , opt )[y, t ] = modul ate(x, f c, f s)

Description y = modul ate(x , f c, f s , ' met hod' ) and

y = modul ate(x , f c, f s , ' met hod' , opt ) modulate the real messagesignal x

with a carrier frequency f c and sampling frequency f s, using oneof theoptionslisted below for ' met hod' . Note that some methods accept an option, opt .

amdsb- sc Amplitude modulation, double sideband, suppressed carrier.

Page 545: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 545/870

7-264

oram

p pp

Multiplies x by a sinusoid of frequency f c.

y = x. * cos(2*pi * f c* t )

amdsb- t c Amplitude modulation, double sideband, transmitted carri er.

Subtracts scalar opt from x and multiplies theresult by a sinusoidof frequency f c.

y = (x -opt ) . * cos(2*pi * f c *t )

If the opt parameter is not present, modul at e uses a default of mi n( mi n( x) ) so that the message signal (x-opt) is entirelynonnegative and has a minimum value of 0.

amssb Amplitude modulation, single sideband. Multiplies x by asinusoid of frequency f c and addstheresult totheHilbert transformof x multiplied by a phase shifted sinusoid of frequency f c.

y =

x. *cos(2*pi *f c*t) +i mag( hi l bert ( x) ) . *si n( 2*pi *f c*t)

This effectively removes the upper sideband.

modulate

f m Frequency modulation. Creates a sinusoid with instantaneousfrequency that varies with the message signal x.

y = cos( 2*pi *f c*t + opt *cumsum( x) )

cumsumis a rectangular approximation to the integral of x.modul at e uses opt as the constant of frequency modulation. I f opt

is not present, modul at e uses a default of

opt = ( f c/ f s)*2*pi / ( max( max( x) ) )

so the maximum frequency excursion from f c is f c Hz.

pm Phase modulation. Creates a sinusoid of frequency f c whosephase varies with the message signal x.

y = cos(2*pi *f c*t + opt *x)

Page 546: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 546/870

7-265

y = cos(2 pi f c t + opt x)

modul at e uses opt as the constant of phase modulation. I f opt is

not present, modul at e uses a default of

opt = pi / ( max( max( x) ) )

so the maximum phase excursion is π radians.

pwm Pulse-width modulation. Creates a pulse-width modulated

signal from the pulse widths in x. The elements of x must bebetween 0 and 1, specifying the width of each pulse in fractions of

a period. The pulses start at the beginning of each period, that is,they are left justified.

modul at e( x, f c, f s, ' pwm' , ' cent er ed' )

yields pulses centered at the beginning of each period. y is length

l engt h( x) * f s / f c.

pt m Pulse time modulation. Creates a pulse time modulated signalfrom the pulse times in x. The elements of x must be between 0and 1, specifying theleft edge of each pulse in fractions of a period.opt is a scalar between 0 and 1 that specifies the length of eachpulsein fractions of a period. The default for opt is 0. 1. y is lengthl engt h( x) * f s / f c.

qam Quadrature amplitude modulation. Creates a quadrature

amplitude modulated signal from signals x and opt .y = x. *cos(2*pi * f c*t ) + opt . *s i n( 2*pi * f c*t )

opt must be the same size as x.

modulate

I f you do not specify ' met hod' , then modul at e assumes am. Except for the pwm

and pt mcases, y is the same size as x.

I f x is an array, modul at e modulates its columns.

[y, t ] = modul ate(x, f c, f s) returns theinternal timevector t that modul at e

uses in its computations.

See Also demod Demodulation for communications simulation.

vco Voltage controlled oscil lator.

Page 547: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 547/870

7-266

pburg

7pburgPurpose Estimate the power spectral density using the Burg method.

Syntax Pxx = pbur g( x, p)

[ Pxx, w] = pburg( x, p)[Pxx, w] = pburg( x, p, nf f t )

[ Pxx, f ] = pbur g(x, p, nf f t , f s )

[ Pxx, f ] = pbur g(x, p, nf f t , f s , ' r ange' )

[Pxx, w] = pburg( x, p, nf f t , ' r ange' )

pburg( . . . )

Description Pxx = pbur g( x, p) implements the Burg algorithm, a parametric spectral

estimation method, and returns Pxx, an estimate of the power spectral density(PSD) of the vector x The entries of x represent samples of a discrete-time

Page 548: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 548/870

7-267

(PSD) of the vector x. The entries of x represent samples of a discrete time

signal, and p is the integer specifying the order of an autoregressive (AR)prediction model for the signal, used in estimating the PSD.

The power spectral density is calculated in units of power per radians persample. Real-valued inputs produce full power one-sided (in frequency) PSDs(by default), while complex-valued inputs produce two-sided PSDs.

I n general, the length of the FFT and the values of the input x determine thelength of Pxx and the range of the corresponding normalized frequencies. F orthis syntax, the (default) FFT length is 256. The following table indicates thelength of Pxx and the range of the corresponding normali zed frequencies forthis syntax.

[ Pxx, w] = pburg( x, p) also returns w, a vector of frequencies at which thePSD is estimated. Pxx and whave thesame length. The units for frequency arerad/sample.

Table 7-9: PSD Vector Characteristics for an FFT Length of 256 (Default)

Real/ ComplexInput Data

Length of Pxx Range of the CorrespondingNormalized Frequencies

Real-valued 129 [0, π]

Complex-valued 256 [0, 2π)

pburg

[ Pxx, w] = pburg(x , p, nf f t ) uses theBurg method toestimatethePSD whilespecifying the length of the FFT with the integer nf f t . I f you specify nf f t as

the empty vector [ ] , it takes the default value of 256.

The length of Pxx and the frequency range for wdepend on nf f t and thevaluesof theinput x. The followingtable indicates thel ength of Pxx and the frequencyrange for win this syntax.

Table 7-10: PSD and Frequency Vector Characteristics

Real/ ComplexInput Data

nfft Even/ Odd Length of Pxx Range of w

Real-valued E ven ( nf f t / 2 + 1) [0, π]

Page 549: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 549/870

7-268

[ Pxx, f ] = pbur g(x, p, nf f t , f s) uses the sampling frequency f s specified as

an integer in hertz (Hz) tocomputetheP SD vector (Pxx) andthe corresponding

vector of frequencies (f ). I n this case, the units for the frequency vector arein H z. The spectral density produced is calculated in units of power per H z. I f you specify f s as the empty vector [ ] , thesampling frequency defaults to1 Hz.

The frequency range for f depends on nf f t , f s, and the values of the input x.

The length of Pxx is the same as in the table above. The following tableindicates the frequency range for f for this syntax.

Real-valued Odd ( nf f t + 1) / 2 [0, π)

Complex-valued Even or odd nf f t [0, 2π)

Table 7-11: PSD and Frequency Vector Characteristics with fs Specified

Real/ Complex Input Data nfft Even/ Odd Range of f

Real-valued Even [0, f s /2]

Real-valued Odd [0, f s /2)

Complex-valued E ven or odd [0, f s )

pburg

[ Pxx, f ] = pbur g(x, p, nf f t , f s , ' r ange' ) or

[Pxx, w] = pburg( x, p, nf f t , ' r ange' ) specifies the range of frequency valuestoincludein f or w. This syntax is useful when x is real. ' r ange' can be either:

• ' t wosi ded' : Compute the two-sided PSD over the frequency range [ 0, f s) . This is the default for determining the frequency range for complex-valuedx.

- I f you specify f s as the empty vector, [ ] , the frequency range is [ 0, 1) .

- I f you don’t specify f s, the frequency range is [0, 2π).

• ' onesi ded' : Computethe one-sided PSD over thefrequency ranges specifiedfor real x. This is the default for determining the frequency range forreal-valued x.

Page 550: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 550/870

7-269

Note You can put the string argument ' r ange' anywhere in the input

argument list after p.

pburg( . . . ) with no outputs plots the power spectral density in the currentfigure window. The frequency range on the plot is the same as the range of output w(or f ) for a given set of parameters.

Examples Becausethe Burg method estimates the spectral density by fitting an ARprediction model of a given order to the signal, first generate a signal from anAR (all-pole) model of a given order. You can use f r eqz to check the magnitudeof the frequency response of your AR filter. This will give you an idea of what

to expect when you estimate the PSD using pburg.a = [ 1 - 2. 2137 2. 9403 - 2. 1697 0. 9606] ; % AR f i l t er coef f i ci ent s

f reqz(1, a) % AR f i l ter f requency response

t i t l e( ' AR Syst em Frequency Response' )

pburg

−150

−100

−50

0

50

100

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 551: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 551/870

7-270

Now generate the input signal x by filtering white noisethrough theA R filter.EstimatetheP SD of x based on a fourth-order AR prediction model sincein this

case we know that the original AR system model a has order 4.

r andn( ' state' , 1) ;x = f i l t er( 1, a, randn( 256, 1) ) ; % AR system output

pbur g( x, 4) % Four t h- or der est i mat e

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

Normalized Frequency (×π rad/sample)

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

Remarks The power spectral density is computed as the distribution of power per unit

frequency.

This algorithm depends on your selecting an appropriate model order for your

signal.

Algorithm L inear prediction filters can be used to model the second-order statisticalcharacteristics of a signal. The prediction filter output can beused tomodel thesignal when the input is white noise.

The Burg method fits an AR linear prediction filter model of thespecified orderto theinput signal by minimizing (using least squares) the arithmetic mean of

the forward and backward prediction errors. The spectral density is thencomputed from the frequency response of the prediction fil ter. The AR filterparameters are constrained to satisfy the Levinson Durbin recursion

Page 552: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 552/870

7-271

parameters are constrained to satisfy the Levinson-Durbin recursion.

See Also ar bur g Compute an estimate of AR model parameters usingthe Burg method.

l pc Compute linear prediction filter coefficients.

pcov Estimate the power spectral density using thecovariance method.

pei g Estimate the pseudospectrum using the eigenvector

method.

peri odogr am Estimate the power spectral density using aperiodogram.

pmcov Estimate the power spectral density using the

modified covariance method.

pmt m Estimate the power spectral density using themultitaper method.

pmusi c Estimate the pseudospectrum using the MU SI C

algorithm.

pwel ch Estimate the power spectral density using Welch’smethod.

psdpl ot Plot power spectral density data.pyul ear Estimate the power spectral density using the

Yule-Walker AR method.

pburg

References [1] Marple, S.L . Digital Spectral Analysis, Englewood Cliffs, NJ , Prentice-Hall,

1987, Chapter 7.

[2] Stoica, P., and R.L. Moses, I ntroduction toSpectral Analysis, Prentice-Hall,

1997.

Page 553: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 553/870

7-272

pcov

7pcovPurpose Estimate the power spectral density using the covariance method.

Syntax Pxx = pcov( x, p)

[ Pxx, w] = pcov( x, p)

[Pxx, w] = pcov(x , p, nf f t )

[ Pxx, f ] = pcov(x, p, nf f t , f s)

[ Pxx, f ] = pcov(x, p, nf f t , f s, ' r ange' )

[ Pxx, w] = pcov(x ,p, nf f t , ' r ange' )

pcov( . . . )

Description Pxx = pcov( x, p) implements the covariancealgori thm, a parametric spectral

estimation method, and returns Pxx, an estimate of the power spectral density(PSD) of the vector x. The entries of x represent samples of a discrete-time

signal and where is theinteger specifying theorder of an autoregressive(AR)

Page 554: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 554/870

7-273

signal, and wherep is theinteger specifying theorder of an autoregressive(AR)prediction model for the signal, used in estimating the PSD.

The power spectral density is calculated in units of power per radians persample. Real-valued inputs produce full power one-sided (in frequency) PSDs(by default), while complex-valued inputs produce two-sided PSDs.

I n general, the length of the FFT and the values of the input x determine thelength of Pxx and the range of the corresponding normalized frequencies. F orthis syntax, the (default) FFT length is 256. The following table indicates thelength of Pxx and the range of the corresponding normali zed frequencies forthis syntax.

[ Pxx, w] = pcov( x, p) alsoreturns w, a vector of frequencies at which thePSDis estimated. Pxx and whave the same length. The units for frequency are

rad/sample.

Table 7-12: PSD Vector Characteristics for an FFT Length of 256 (Default)

Real/ ComplexInput Data

Length of Pxx Range of the CorrespondingNormalized Frequencies

Real-valued 129 [0, π]

Complex-valued 256 [0, 2π)

pcov

[ Pxx, w] = pcov( x, p, nf f t ) uses the covariance method to estimate the PSDwhile specifyingthelength of theF FT with theinteger nf f t . I f you specify nf f t

as the empty vector [ ] , it takes the default value of 256.

The length of Pxx and the frequency range for wdepend on nf f t and thevaluesof theinput x. The followingtable indicates thel ength of Pxx and the frequencyrange for win this syntax.

Table 7-13: PSD and Frequency Vector Characteristics

Real/ ComplexInput Data

nfft Even/ Odd Length of Pxx Range of w

Real-valued E ven ( nf f t / 2 + 1) [0, π]

Real-valued Odd ( nf f t + 1) / 2 [0, π)

Page 555: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 555/870

7-274

[ Pxx, f ] = pcov(x, p, nf f t , f s ) uses thesamplingfrequency f s specifiedasan

integer in hertz (Hz) to compute the PSD vector (Pxx) and the corresponding

vector of frequencies (f ). I n this case, the units for the frequency vector arein H z. The spectral density produced is calculated in units of power per H z. I f you specify f s as the empty vector [ ] , thesampling frequency defaults to1 Hz.

The frequency range for f depends on nf f t , f s, and the values of the input x.

The length of Pxx is the same as in the table above. The following tableindicates the frequency range for f for this syntax.

[ , )

Complex-valued Even or odd nf f t [0, 2π)

Table 7-14: PSD and Frequency Vector Characteristics with fs Specified

Real/ Complex Input Data nfft Even/ Odd Range of f

Real-valued Even [0, f s /2]

Real-valued Odd [0, f s /2)

Complex-valued E ven or odd [0, f s )

pcov

[ Pxx, f ] = pcov(x, p, nf f t , f s, ' r ange' ) or

[Pxx, w] = pcov(x ,p, nf f t , ' r ange' ) specifies the range of frequency valuestoincludein f or w. This syntax is useful when x is real. ' r ange' can be either:

• ' t wosi ded' : Compute the two-sided PSD over the frequency range [ 0, f s) . This is the default for determining the frequency range forcomplex-valued x.

- I f you specify f s as the empty vector, [ ] , the frequency range is [ 0, 1) .

- I f you don’t specify f s, the frequency range is [0, 2π).

• ' onesi ded' : Computethe one-sided PSD over thefrequency ranges specifiedfor real x. This is the default for determining the frequency range for

real-valued x.

Page 556: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 556/870

7-275

Note You can put the string argument ' r ange' anywhere in the input

argument list after p.

pcov( . . . ) with no outputs plots the power spectral density in the currentfigure window. The frequency range on the plot is the same as the range of output w(or f ) for a given set of parameters.

Examples Because the covariance method estimates the spectral density byfitting an ARprediction model of a given order to the signal, first generate a signal from anAR (all-pole) model of a given order. You can use f r eqz to check the magnitudeof the frequency response of your AR filter. This will give you an idea of what

to expect when you estimate the PSD using pcov.a = [ 1 - 2. 2137 2. 9403 - 2. 1697 0. 9606] ; % AR f i l t er coef f i ci ent s

f reqz(1, a) % AR f i l t er f requency response

t i t l e( ' AR Syst em Frequency Response' )

pcov

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

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 557: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 557/870

7-276

Now generate the input signal x by filtering white noisethrough theA R filter.EstimatetheP SD of x based on a fourth-order AR prediction model sincein thiscase we know that the original AR system model a has order 4.

randn( ' stat e' , 1) ;x = f i l t er( 1, a, randn( 256, 1) ) ; % Si gnal generat ed f rom AR f i l t er

pcov(x, 4) % Four t h- or der est i mat e

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1Normalized Frequency (×π rad/sample)

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

Remarks The power spectral density is computed as the distribution of power per unit

frequency.

This algorithm depends on your selecting an appropriate model order for your

signal.

Algorithm L inear prediction filters can be used to model the second-order statisticalcharacteristics of a signal. The prediction filter output can beused tomodel thesignal when the input is white noise.

The covariance method estimates the PSD of a signal using the covariancemethod. The covariance (or nonwindowed) method fits an AR linear prediction

filter model to the signal by minimizing the forward prediction error (based oncausal observations of your input signal) in the least squares sense. Thespectral estimate returned by pcov is the squared magnitudeof the frequency

Page 558: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 558/870

7-277

response of this AR model.

pcov

See Also ar cov Compute an estimate of AR model parameters usingthe covariance method.

l pc L inear prediction coefficients.

pburg Estimate the power spectral density using the Burgmethod.

pei g Estimate the pseudospectrum using the eigenvectormethod.

peri odogr am Estimate the power spectral density using aperiodogram.

pmcov Estimate the power spectral density using the

modified covariance method.pmt m Estimate the power spectral density using the

multitaper method.

Page 559: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 559/870

7-278

References [1] Marple, S.L . Digital Spectral Analysis, Englewood Cliffs, NJ , Prentice-Hall,1987, Chapter 7.

[2] Stoica, P., and R.L. Moses, I ntroduction toSpectral Analysis, Prentice-Hall,1997.

multitaper method.

pmusi c Estimate the pseudospectrum using the MUSI Calgorithm.

prony Prony’s method for time domain I I R fi lter design.

psdpl ot Plot power spectral density data.

pwel ch Estimate the power spectral density using Welch’smethod.

pyul ear Estimate the power spectral density using the Yule-Walker AR method.

peig

7peigPurpose Estimate the pseudospectrum using the eigenvector method.

Syntax [S, w] = pei g(x ,p)

[ S, w] = pei g( . . . , nf f t )

[ S, f ] = pei g( x, p, nf f t , f s )

[ S, f ] = pei g( . . . , ' corr ' )

[S, f ] = pei g( x, p, nf f t , f s , nwi n, nover l ap)

[ . . . ] = pei g( . . . , ' r ange' )

[ . . . , v, e] = pei g( . . . )

pei g( . . . )

Description [S, w] = pei g(x ,p) implements the eigenvector spectral estimation methodand returns S, the pseudospectrum estimate of the input signal x, and w, avector of normalized frequencies (in rad/sample) at which the pseudospectrum

Page 560: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 560/870

7-279

is evaluated. The pseudospectrum is calculated using estimates of theeigenvectors of a correlation matrix associated with the input data x, where x

is specified as either:

• A row or column vector representing one observation of the signal

• A rectangular array for which each row of x represents a separateobservation of the signal (for example, each row is one output of an array of

sensors, as in array processing), such that x' *x is an estimate of thecorrelation matrix

Note You can use the output of corr mt x to generate such an array x.

You can specify the second input argument p as either:

• A scalar integer. I n this case, the signal subspace dimension is p.

• A two-element vector. I n this case, p( 2) , the second element of p, representsa threshold that is multiplied by λmin, the smallest estimated eigenvalue of the signal’s correlation matrix. Eigenvalues below the threshold λmin*p(2)

areassigned to thenoisesubspace. I n this case, p(1) specifies the maximum

dimension of the signal subspace.

peig

The extra threshold parameter in the second entry in p provides you moreflexibility and control in assigning the noise and signal subspaces.

S and whavethe same length. I n general, thelength of theF F T and thevalues

of the input x determine the length of the computed S and the range of thecorresponding normalized frequencies. The following tableindicates the lengthof S (and w) and the range of the corresponding normalized frequencies for thissyntax.

Table 7-15: S Characteristics for an FFT Length of 256 (Default)

Real/ Complex

Input Data

Length of S and w Range of the Corresponding

Normalized Frequencies

Real-valued 129 [0, π]

Complex-valued 256 [0 2π)

Page 561: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 561/870

7-280

[ S, w] = pei g( . . . , nf f t ) specifies thelength of the FF T used to estimate thepseudospectrum with the integer nf f t . The default value for nf f t (entered asan empty vector [ ] ) is 256.

The following table indicates the length of S and w, and the frequency rangefor wfor this syntax.

[ S, f ] = pei g( x, p, nf f t , f s ) ) returns the pseudospectrum in the vector S

evaluated at the corresponding vector of frequencies f (in Hz). You supply thesampling frequency f s in H z. I f you specify f s with the empty vector [ ] , the

sampling frequency defaults to 1 Hz.

Complex-valued 256 [0, 2π)

Table 7-16: S and Frequency Vector Characteristics

Real/ ComplexInput Data

nfft Even/ Odd Length of Sand w

Range of w

Real-valued E ven( nf f t / 2 + 1)

[0,π

]Real-valued Odd ( nf f t + 1) / 2 [0, π)

Complex-valued Even or odd nf f t [0, 2π)

peig

The frequency range for f depends on nf f t , f s, and the values of the input x. The length of S (and f ) is the same as in Table 7-16. The following tableindicates the frequency range for f for this syntax.

[ S, f ] = pei g( . . . , ' corr ' ) forces the input argument x tobe interpreted as acorrelation matrix rather than matrix of signal data. For this syntax x must be

t i d ll f it i l t b ti

Table 7-17: S and Frequency Vector Characteristics with fs Specified

Real/ Complex Input Data nfft Even/ Odd Range of f

Real-valued Even [0, f s/ 2]

Real-valued Odd [0, f s/ 2)

Compl ex-val ued E ven or odd [0, f s)

Page 562: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 562/870

7-281

a square matrix, and all of its eigenvalues must be nonnegative.

[S, f ] = pei g( x, p, nf f t , f s , nwi n, nover l ap) allows you to specify nwi n, ascalar integer indicating a rectangular window length, or a real-valued vector

specifying window coefficients. Usethe scalar integer nover l ap in conjunction

with nwi n to specify the number of input sample points by which successivewindows overlap. nover l ap is not used if x is a matrix. The default value fornwi n is 2*p( 1) and nover l ap is nwi n- 1.

With this syntax, the input data x is segmented and windowed before the

matrix used to estimate the correlation matrix eigenvalues is formulated. Thesegmentation of the data depends on nwi n, nover l ap, and the form of x.Comments on the resulting windowed segments are described in the following

table.

Table 7-18: Windowed Data Depending on x and nwin

Input data x Form of nwin Windowed Data

Data vector Scalar Length is nwi n

Data vector Vector of coefficients Length is l engt h( nwi n)

peig

See Table 7-19 for related information on this syntax.

Note The arguments nwi n and nover l ap are ignored when you include thestring ' corr ' in the syntax.

Data matrix Scalar Data i s not windowed.

Data matrix Vector of coefficients l engt h( nwi n) must be thesame as the column length of x,and nover l ap is not used.

Table 7-18: Windowed Data Depending on x and nwin (Continued)

Input data x Form of nwin Windowed Data

Page 563: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 563/870

7-282

[ . . . ] = pei g( . . . , ' r ange' ) specifies therangeof frequency valuestoincludein f or w. This syntax is useful when x is real. ' r ange' can be either:

• ' whol e' : Compute the pseudospectrum over the frequency range [ 0, f s) .

This is thedefault for determiningthefrequency rangefor complex-valued x. - I f you specify f s as the empty vector, [ ] , the frequency range is [ 0, 1) .

- I f you don’t specify f s, the frequency range is [0, 2π).

• ' hal f ' : Compute the pseudospectrum over the frequency ranges specifiedfor real x. This is the default for determining the frequency range forreal-valued x.

Note You can put the string arguments ' r ange' or ' corr' anywhere in the

input argument list after p.

[ . . . , v, e] = pei g( . . . ) returns thematrix v of noiseeigenvectors, alongwiththe associated eigenvalues in the vector e. The columns of v span the noisesubspace of dimension s i ze( v, 2) . The dimension of the signal subspace is

s i ze(v , 1) - s i ze( v, 2) . For this syntax, e is a vector of estimated eigenvaluesof the correlation matrix.

peig

pei g( . . . ) with no output arguments plots thepseudospectrum in thecurrentfigure window.

Remarks I n the process of estimating the pseudospectrum, pei g computes the noiseand

signal subspaces from the estimated eigenvectors v j and eigenvalues λ j of thesignal’s correlation matrix. The smallest of these eigenvalues is used inconjunction with the threshold parameter p(2) to affect the dimension of thenoise subspace in some cases.

The length n of the eigenvectors computed bypei g is thesumof thedimensionsof the signal and noise subspaces. This eigenvector length depends on your

input (signal data or correlation matrix) and the syntax you use.

The following table summarizes the dependency of the eigenvector length onthe input argument.

Page 564: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 564/870

7-283

You should specify nwi n >p( 1) or l engt h( nwi n) >p( 1) if you want p( 2) >1 tohave any effect.

Table 7-19: Eigenvector Length Depending on Input Data and Syntax

Form of Input Data x Comments on the Syntax Length n of

Eigenvectors

Row or column vector nwi n is specified as a scalarinteger.

nwi n

Row or column vector nwi n is specified as a vector. l engt h(nwi n)

Row or column vector nwi n is not specified. 2*p( 1)

l-by-m matrix I f nwi n is specified as ascalar, it is not used. I f nwi n

is specified as a vector,

l engt h( nwi n) must equalm.

m

m-by-m nonnegative

definite matrix

The string ' corr' is

specified and nwi n is notused.

m

peig

Examples I mplement the eigenvector method to find the pseudospectrum of the sum of

three sinusoids in noise, using thedefault FFT length of 256. Usethe modifiedcovariance method for the correlation matrix estimate.

r andn( ' st at e' , 1) ; n=0: 99;s=exp( i *pi / 2*n)+2*exp( i *pi / 4*n)+exp( i *pi / 3*n)+r andn( 1, 100) ;

X=cor r mt x( s, 12, ' mod' ) ;

pei g( X, 3, ' whol e' ) % Uses t he def aul t NFFT of 256.

10

15

20

25

30Eigenvector Method Pseudospectrum

Page 565: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 565/870

7-284

Algorithm The eigenvector method estimates the pseudospectrum from a signal or acorrelation matrix using a weighted version of the MUSI C algorithm derivedfrom Schmidt’s eigenspace analysis method [1][2]. The algorithm performs

eigenspace analysis of the signal’s correlation matrix in order to estimate thesignal’s frequency content. The eigenvalues and eigenvectors of the signal’s

correlation matrix are estimated using svd if you don’t supply the correlationmatrix. This algorithm is particularly suitable for signals that are the sum of sinusoids with additive white Gaussian noise.

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8−15

−10

−5

0

5

Normalized Frequency (×π rad/sample)

d B

peig

The eigenvector method produces a pseudospectrum estimate given by

where N is the dimension of the eigenvectors and vk is the kth eigenvector of thecorrelation matrix of theinput signal. The integer p is thedimension of the

signal subspace, so the eigenvectors vk used in the sum correspond to thesmallest eigenvalues of thecorrelation matrix. The eigenvectors used in thePSD estimate span the noise subspace. The vector e(f ) consists of complex

exponentials, so the inner product

P ev f ( )1

vkH e f ( ) 2

k p 1+=

N

åè ø

λk ⁄

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

λk

vkH e f ( )

Page 566: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 566/870

7-285

amounts to a Fourier transform. This is used for computation of the PSDestimate. The FF T is computed for each vk and then the squared magnitudes

are summed and scaled.

peig

See Also cor r mt x Calculate a data vector for correlation matrixestimation.

pburg Estimate the power spectral density using the Burgmethod.

peri odogr am Estimate the power spectral density using aperiodogram.

pmt m Estimate the power spectral density using themultitaper method.

pmusi c Estimate the pseudospectrum using the MUSI Calgorithm.

prony Prony’s method for time domain I I R fi lter design.psdpl ot Plot power spectral density data.

pwel ch Estimate the power spectral density using Welch’smethod

Page 567: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 567/870

7-286

References [1] Marple, S.L . Digital Spectral Analysis, Englewood Cliffs, NJ , Prentice-Hall,1987, pp. 373-378.

[2] Schmidt, R.O, “Multiple Emitter L ocation and Signal ParameterEstimation,” I EEE Trans. Antennas Propagation, Vol. AP -34 (March 1986),pp. 276-280.

[3] Stoica, P., and R.L. Moses, I ntroduction toSpectral Analysis, Prentice-Hall,

1997.

method.

root ei g Estimate the frequency and power content using the

root eigenvector method.

r oot musi c Estimate the frequency and power content using the

root MUSI C algorithm.

periodogram

7periodogramPurpose Estimate the power spectral density (PSD) of a signal using a periodogram.

Syntax [ Pxx, w] = per i odogr am( x)

[ Pxx, w] = per i odogr am( x, wi ndow)

[ Pxx, w] = per i odogr am( x, wi ndow, nf f t )

[ Pxx, f ] = per i odogr am( x, wi ndow, nf f t , f s)

[Pxx, . . . ] = per i odogram(x , . . . , ' r ange' )

per i odogr am( . . . )

Description [ Pxx, w] = per i odogr am( x) returns the power spectral density (PSD)estimate Pxx of the sequence x using a periodogram. The power spectral

density is calculated in units of power per radians per sample. Thecorresponding vector of frequencies wis computed in radians per sample, andhas the same length as Pxx.

A real-valued input vector x produces a full power one-sided (in frequency)PSD

Page 568: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 568/870

7-287

A real valued input vector x produces a full power one sided (in frequency)PSD(by default), while a complex-valued x produces a two-sided PSD.

I n general, thelength N of the FF T and the values of the input x determine thelength of Pxx and the range of the corresponding normalized frequencies. F or

this syntax, the (default) length N of the F FT is the larger of 256 and the nextpower of two greater than the length of x. The following table indicates thelength of Pxx and the range of the corresponding normali zed frequencies forthis syntax.

[ Pxx, w] = per i odogr am( x, wi ndow) returns the PSD estimate Pxx computedusing the modified periodogram method. The vector wi ndowspecifies thecoefficients of the window used in computing a modified periodogram of the

input signal. Both input arguments must be vectors of the same length. Whenyou don’t supply the second argument wi ndow, or set it to the empty vector [ ] ,

Table 7-20: PSD Vector Characteristics for an FFT Length of N (Default)

Real/ Complex

Input Data

Length of Pxx Range of the Corresponding

Normalized Frequencies

Real-valued (N/2) +1 [0, π]

Complex-valued N [0, 2π)

periodogram

a rectangular window (boxcar ) is used by default. I n this case the standardperiodogram is calculated.

[ Pxx, w] = per i odogr am( x, wi ndow, nf f t ) uses the modified periodogram to

estimatetheP SD while specifyingthe length of theF FT with theinteger nf f t .I f you set nf f t to the empty vector [ ] , it takes the default value for N listed inthe previous syntax.

The length of Pxx and the frequency range for wdepend on nf f t and thevaluesof theinput x. The followingtable indicates thel ength of Pxx and the frequencyrange for wfor this syntax.

Table 7-21: PSD and Frequency Vector CharacteristicsReal/ ComplexInput Data

nfft Even/ Odd Length of Pxx Range of w

Real valued E ven ( nf f t / 2 + 1) [0 π]

Page 569: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 569/870

7-288

Note per i odogr amuses an nf f t -point FFT of the windowed data(x. *wi ndow) to compute the periodogram. I f the value you specify for nf f t isless than thel ength of x, then x. *wi ndowis wrapped modulonf f t . If the valueyou specify for nf f t is greater than the length of x, then x. *wi ndowis

zero-padded to compute the FFT.

[ Pxx, f ] = peri odogr am( x, wi ndow, nf f t , f s) uses the sampling frequency f s

specified as an integer in hertz (Hz) to compute the PSD vector (Pxx) and thecorresponding vector of frequencies (f ). I n this case, theunits for thefrequencyvector are in Hz. The spectral density produced is calculated in units of powerper H z. I f you specify f s as the empty vector [ ] , the sampling frequencydefaults to 1 Hz.

Real-valued E ven ( nf f t / 2 + 1) [0, π]

Real-valued Odd ( nf f t + 1) / 2 [0, π)

Complex-valued Even or odd nf f t [0, 2π)

periodogram

The frequency range for f depends on nf f t , f s, and the values of the input x. The length of Pxx is the same as in the table above. The following tableindicates the frequency range for f for this syntax.

[ Pxx, f ] = per i odogr am( x, wi ndow, nf f t , f s, ' r ange' ) or

[ Pxx, w] = per i odogr am( x, wi ndow, nf f t , ' r ange' ) specifies the range of frequency values to include in f or w This syntax is useful when x is real

Table 7-22: PSD and Frequency Vector Characteristics with fs Specified

Real/ Complex Input Data nfft Even/ Odd Range of f

Real-valued Even [0, f s/ 2]

Real-valued Odd [0, f s/ 2)

Compl ex-val ued E ven or odd [0, f s)

Page 570: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 570/870

7-289

frequency values to include in f or w. This syntax is useful when x is real.' r ange' can be either:

• ' t wosi ded' : Compute the two-sided PSD over the frequency range [ 0, f s) . This is the default for determining the frequency range for

complex-valued x.

- I f you specify f s as the empty vector, [ ] , the frequency range is [ 0, 1) .

- I f you don’t specify f s, the frequency range is [0, 2π).

• ' onesi ded' : Computethe one-sided PSD over thefrequency ranges specifiedfor real x. This is the default for determining the frequency range forreal-valued x.

Note You can put the string argument ' r ange' anywhere in the inputargument list after wi ndow.

per i odogr am( . . . ) with no outputs plots the power spectral density in dB perunit frequency in the current figure window. The frequency range on the plotis the same as the range of output w(or f ) for the syntax you use.

periodogram

Examples Compute the periodogram of a 200 Hz signal embedded in additivenoise using

the default window.

r andn( ' stat e' , 0) ;

Fs = 1000;

t = 0: 1/ Fs: . 3;

x = cos( 2*pi *t *200) +0. 1*r andn( si ze( t ) ) ;

per i odogr am( x, [ ] , ' t wosi ded' , 512, Fs)

40

−30

−20

−10

D e n s i t y ( d B / H z )

Periodogram PSD Estimate

Page 571: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 571/870

7-290

Algorithm The periodogram for a sequence [x1, ... , xn] is given by the following formula.

This expression forms an estimate of the power spectrum of the signal definedby the sequence [x1, ... , xn].

0 100 200 300 400 500 600 700 800 900−70

−60

−50

−40

Frequency (Hz)

P o w e r S p e c t r a l

S e j ω( ) 1n--- xl e j ω l–

l 1=

n

å

2

=

periodogram

I f you weight your signal sequence by a window [w1, ... , wn], then theweightedor modified periodogram is defined as

I n either case, peri odogr amuses an nf f t -point F FT to compute the power

spectral density as , where F is:

• 2π when you do not supply the sampling frequency

• f s when you supply the sampling frequency

S e j ω

( )

1n--- wl xl ej ωl–

l 1=

n

å

2

1n--- wl

2

l 1=

n

å

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

S e j ω

( ) F ⁄

Page 572: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 572/870

7-291

See Also pburg Estimate the power spectral density using the Burg

method.

pcov Estimate the power spectral density using the

covariance method.

pei g Estimate the pseudospectrum using the eigenvectormethod.

pmcov Estimate the power spectral density using themodified covariance method.

pmt m Estimate the power spectral density using the

multitaper method.

pmusi c Estimate the pseudospectrum using the MU SI Calgorithm.

psdpl ot Plot power spectral density data.

pwel ch Estimate the power spectral density using Welch’smethod.

pyul ear Estimate the power spectral density using the

Yule-Walker AR method.

periodogram

References [1] Stoica, P., and R.L. Moses, I ntroduction toSpectral Analysis, Prentice-Hall,

1997, pp. 24-26.

[2] Welch, P.D, “The Useof Fast Fourier Transform for theE stimation of Power

Spectra: A Method Based on T ime Averaging Over Short, ModifiedPeriodograms,” I EEE Trans. Audio Electroacoustics, Vol. AU -15 (J une1967),pp. 70-73.

[3] Oppenheim, A.V., and R.W. Schafer, Discrete-TimeSi gnal Processing,Prentice-Hall, 1989, pp. 730-742.

Page 573: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 573/870

7-292

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, nf f t )

[Pxx, f ] = pmcov( x, p, nf f t , f s )

[Pxx, f ] = pmcov( x, p, nf f t , f s , ' r ange' )

[ Pxx, w] = pmcov( x, p, nf f t , ' r ange' )

pmcov(. . . )

Description Pxx = pmcov(x, p) implements the modified covariance algorithm, aparametric spectral estimation method, and returns Pxx, an estimateof thepower spectral density (PSD) of thevector x. The entries of x represent samples

of a discrete-time signal, and p is the integer specifying the order of anautoregressive (AR) prediction model for the signal, used in estimating thePSD.

Page 574: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 574/870

7-293

The power spectral density is calculated in units of power per radians persample. Real-valued inputs produce full power one-sided (in frequency) PSDs

(by default), while complex-valued inputs produce two-sided PSDs.

I n general, the length of the FF T and the values of the input x determine thelength of Pxx and the range of the corresponding normalized frequencies. F orthis syntax, the (default) FFT length is 256. The following table indicates thelength of Pxx and the range of the corresponding normali zed frequencies for

this syntax.

[ Pxx, w] = pmcov( x, p) also returns w, a vector of frequencies at which the

PSD is estimated. Pxx and whave thesame length. The units for frequency arerad/sample.

Table 7-23: PSD Vector Characteristics for an FFT Length of 256 (Default)

Real/ Complex

Input Data

Length of Pxx Range of the Corresponding

Normalized Frequencies

Real-valued 129 [0, π]

Complex-valued 256 [0, 2π)

pmcov

[ Pxx, w] = pmcov( x, p, nf f t ) uses the covariance method to estimate the PSDwhile specifyingthelength of theF FT with theinteger nf f t . I f you specify nf f t

as the empty vector [ ] , it takes the default value of 256.

The length of Pxx and the frequency range for wdepend on nf f t and thevaluesof theinput x. The followingtable indicates thel ength of Pxx and the frequencyrange for wfor this syntax.

Table 7-24: PSD and Frequency Vector Characteristics

Real/ ComplexInput Data

nfft Even/ Odd Length of Pxx Range of w

Real-valued E ven( nf f t / 2 + 1)

[0, π]Real-valued Odd ( nf f t + 1) / 2 [0, π)

Complex-valued Even or odd nf f t [0, 2π)

Page 575: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 575/870

7-294

[ Pxx, f ] = pmcov(x, p, nf f t , f s) uses the sampling frequency f s specified as

an integer in hertz (Hz) tocomputetheP SD vector (Pxx) andthe correspondingvector of frequencies (f ). I n this case, the units for the frequency vector are

in H z. The spectral density produced is calculated in units of power per H z. I f you specify f s as the empty vector [ ] , thesampling frequency defaults to1 Hz.

The frequency range for f depends on nf f t , f s, and the values of the input x.

The length of Pxx isthesameasin Table 7-24. The followingtable indicates thefrequency range for f in this syntax.

Table 7-25: PSD and Frequency Vector Characteristics with fs Specified

Real/ Complex Input Data nfft Even/ Odd Range of f

Real-valued Even [0, f s /2]

Real-valued Odd [0, f s /2)

Complex-valued E ven or odd [0, f s )

pmcov

[Pxx, f ] = pmcov( x, p, nf f t , f s , ' r ange' ) or

[ Pxx, w] = pmcov( x, p, nf f t , ' r ange' ) specifies the range of frequency valuestoincludein f or w. This syntax is useful when x is real. ' r ange' can be either:

• ' t wosi ded' : Compute the two-sided PSD over the frequency range [ 0, f s) . This is the default for determining the frequency range forcomplex-valued x.

- I f you specify f s as the empty vector, [ ] , the frequency range is [ 0, 1) .

- I f you don’t specify f s, the frequency range is [0, 2π).

• ' onesi ded' : Computethe one-sided PSD over thefrequency ranges specifiedfor real x. This is the default for determining the frequency range for

real-valued x.

Note You can put the string argument ' r ange' anywhere in the input

argument list after p.

Page 576: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 576/870

7-295

g p

pmcov(. . . ) with no outputs plots the power spectral density in the current

figure window. The frequency range on the plot is the same as the range of output w(or f ) for a given set of parameters.

Examples Because the modified covariance method estimates the spectral density byfitting an AR prediction model of a given order to the signal, first generate asignal froman AR (all-pole) model of a given order. You can use f r eqz to checkthemagnitude of thefrequency responseof your AR filter. This will giveyou anidea of what to expect when you estimate the PSD using pmcov.

a = [ 1 - 2. 2137 2. 9403 - 2. 1697 0. 9606] ; % AR f i l t er coef f i ci ent s

f reqz(1, a) % AR f i l t er f requency response

t i t l e( ' AR Syst em Frequency Response' )

pmcov

Now generate the input signal x by filtering white noisethrough theA R filter.

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 577: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 577/870

7-296

EstimatetheP SD of x based on a fourth-order AR prediction model sincein thiscase we know that the original AR system model a has order 4.

r andn( ' state' , 1) ;

x = f i l ter ( 1, a, randn( 256, 1) ) ; % AR f i l ter output

pmcov(x, 4) % Four t h- or der est i mat e

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−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

Remarks The power spectral density is computed as the distribution of power per unit

frequency.

This algorithm depends on your selecting an appropriate model order for yoursignal.

Algorithm L inear prediction filters can be used to model the second-order statisticalcharacteristics of a signal. The prediction filter output can beused tomodel thesignal when the input is white noise.

pmcov estimates the PSD of the signal vector using the modified covariancemethod. This method fits an autoregressive (AR) linear prediction filter modelto the signal by simultaneously minimizing the forward and backward

prediction errors (based on causal observations of your input signal) in theleast squares sense. The spectral estimate returned by pmcov is themagnitudesquared frequency response of this AR model.

Page 578: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 578/870

7-297

pmcov

See Also ar mcov Compute an estimate of AR model parameters usingthe modified covari ance method.

l pc L inear prediction coefficients.

pburg Estimate the power spectral density using the Burg

method.

pcov Estimate the power spectral density using thecovariance method.

pei g Estimate the pseudospectrum using the eigenvectormethod.

peri odogr am Estimate the power spectral density using aperiodogram.

pmt m Estimate the power spectral density using themultitaper method.

pmusi c Estimate the pseudospectrum using the MUSI Calgorithm.

Page 579: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 579/870

7-298

References [1] Marple, S.L . Digital Spectral Analysis, Englewood Cliffs, NJ , Prentice-Hall,1987, Chapter 7.

[2] Stoica, P., and R.L. Moses, I ntroduction toSpectral Analysis, Prentice-Hall,1997.

prony Prony’s method for time domain I I R fi lter design.

psdpl ot Plot power spectral density data.

pwel ch Estimate the power spectral density using Welch’smethod.

pyul ear Estimate the power spectral density using the Yule-Walker AR method.

pmtm

7pmtmPurpose Estimate the power spectral density using the multitaper method (MTM).

Syntax [ Pxx, w] = pmt m( x, nw)

[ Pxx, w] = pmt m( x, nw, nf f t )

[ Pxx, f ] = pmt m( x, nw, nf f t , f s)[ Pxx, Pxxc, f ] = pmt m(x, nw, nf f t , f s)

[ Pxx, Pxxc, f ] = pmt m(x, nw, nf f t , f s , p)

[ Pxx, Pxxc, f ] = pmt m( x, e, v, nf f t , f s , p)

[ Pxx, Pxxc, f ] = pmt m( x, dpss_par ams, nf f t , f s, p)

[ . . . ] = pmt m( . . . , ' met hod' )

[ . . . ] = pmt m( . . . , ' r ange' )

pmt m( . . . )

Description pmt m estimates the power spectral density (PSD) of the time series x using themultitaper method (MTM) described in [1]. This method uses linear ornonlinear combinations of modified periodograms to estimate the PSD. Theseperiodograms are computed using a sequence of orthogonal tapers (windows in

Page 580: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 580/870

7-299

periodograms are computed using a sequence of orthogonal tapers (windows inthe frequency domain) specified from the discreteprolatespheroidal sequences(see dpss).

[ Pxx, w] = pmt m( x, nw) estimates the PSD Pxx for the input signal x, using2*nw- 1 discrete prolate spheroidal sequences as data tapers for the multitaper

estimation method. nwis the time-bandwidth product for the discrete prolatespheroidal sequences. I f you specify nwas the empty vector [ ] , a default valueof 4 is used. Other typical choices are 2, 5/2, 3, or 7/2. pmt malso returns w, avector of frequencies at which the PSD is estimated. Pxx and whave the samelength. The units for frequency are rad/sample.

The power spectral density is calculated in units of power per radians persample. Real-valued inputs produce (by default) full power one-sided (infrequency) PSDs, while complex-valued inputs produce two-sided PSDs.

I n general, thelength N of the FF T and the values of the input x determine thelength of Pxx and the range of the corresponding normalized frequencies. F orthis syntax, the (default) length N of the F FT is the larger of 256 and the nextpower of two greater than the length of the segment. The following table

pmtm

indicates the length of Pxx and the range of the corresponding normalizedfrequencies for this syntax.

[ Pxx, w] = pmt m( x, nw, nf f t ) uses themultitaper method toestimatethePSD

while specifyingthelength of theF FT with theinteger nf f t . I f you specify nf f tas the empty vector [ ] , it adopts the default value for N described in theprevious syntax.

The length of Pxx and the frequency range for wdepend on nf f t and thevalues

of theinput x. The followingtable indicates thel ength of Pxx and the frequency

Table 7-26: PSD Vector Characteristics for an FFT Length of N (Default)

Real/ Complex

Input Data

Length of Pxx Range of the Corresponding

Normalized Frequencies

Real-valued (N/2) +1 [0, π]

Complex-valued N [0, 2π)

Page 581: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 581/870

7-300

range for wfor this syntax.

[ Pxx, f ] = pmtm( x, nw, nf f t , f s) uses the sampling frequency f s specified asan integer in hertz (Hz) tocomputetheP SD vector (Pxx) andthe correspondingvector of frequencies (f ). I n this case, the units for the frequency vector f arein H z. The spectral density produced is calculated in units of power per H z. I f

you specify f s as the empty vector [ ] , thesampling frequency defaults to1 Hz.

Table 7-27: PSD and Frequency Vector Characteristics

Real/ Complex

Input Data

nfft Even/ Odd Length of Pxx Range of w

Real-valued Even (nf f t /2 +1) [0, π]

Real-valued Odd (nf f t +1)/2 [0, π)

Complex-valued Even or odd nf f t [0, 2π)

pmtm

The frequency range for f depends on nf f t , f s, and the values of the input x. Thel ength of Pxx isthesameasin Table 7-27. The followingtable indicates thefrequency range for f for this syntax.

[ Pxx, Pxxc, f ] = pmt m( x, nw, nf f t , f s) returns Pxxc, the 95% confidenceinterval for Pxx. Confidence intervals are computed using a chi-squaredapproach. Pxxc is a two-column matrix with the same number of rows as Pxx.Pxxc( : , 1) is the lower bound of the confidence interval and Pxxc( : , 2) is theupper bound of the confidence interval.

Table 7-28: PSD and Frequency Vector Characteristics with fs Specified

Real/ Complex Input Data nfft Even/ Odd Range of f

Real-valued Even [ 0, f s / 2]

Real-valued Odd [ 0, f s /2)

Complex-valued E ven or odd [0, f s)

Page 582: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 582/870

7-301

pp

[ Pxx, Pxxc, f ] = pmt m( x, nw, nf f t , f s , p) returns Pxxc, the p*100%confidenceinterval for Pxx, where p is a scalar between 0 and 1. I f you don’t specify p, orif you specify p as the empty vector [ ] , the default 95%confidence interval isused.

[ Pxx, Pxxc, f ] = pmt m( x, e, v, nf f t , f s , p) returns the PSD estimate Pxx, the

confidence interval Pxxc, and the frequency vector f from the data taperscontained in the columns of the matrix e, and their concentrations in thevector v. The length of v is the same as the number of columns in e. You canobtain the data to supply as these arguments from the outputs of dpss.

[ Pxx, Pxxc, f ] = pmt m( x, dpss_par ams, nf f t , f s, p) uses the cell array

dpss_params containing the input arguments to dpss (listed in order, butexcluding the first argument) to compute the data tapers. For example,pmt m( x, 3. 5, ' t r ace' , 512, 1000) calculates the prolate spheroidalsequences for nw=3. 5, usingnf f t =512, and f s =1000, and displays themethod that dpss uses for this calculation. See dpss for other options.

pmtm

[ . . . ] = pmt m( . . . , ' met hod' ) specifies the algorithm used for combining theindividual spectral estimates. The string ' met hod' can be one of the following:

• ' adapt ' : Thomson’s adaptive nonlinear combination (default)

' uni ty ' : A linear combination of the weighted periodograms with unityweights

• ' ei gen' : A linear combination of the weighted periodograms witheigenvalue weights

[ . . . ] = pmt m( . . . , ' r ange' ) specifies therangeof frequency valuestoincludein f or w. This syntax is useful when x is real. ' r ange' can be either:

• ' t wosi ded' : Compute the two-sided PSD over the frequency range [ 0 , f s ) . This is the default for determining the frequency range for complex-valuedx.

- I f you specify f s as the empty vector, [ ] , the frequency range is [ 0, 1) .

- I f you don’t specify f s, the frequency range is [0, 2π).

• ' onesi ded' : Computethe one-sided PSD over thefrequency ranges specified

Page 583: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 583/870

7-302

onesi ded : Computethe one sided PSD over thefrequency ranges specifiedfor real x. This is the default for determining the frequency range for

real-valued x.

Note You can put the string arguments ' r ange' or ' met hod' anywhere afterthe input argument nwor v.

pmt m( . . . ) with no output arguments plots the PSD estimate and theconfidence intervals in the current figure window. I f you don’t specify f s, the

95%confidence interval is plotted. I f you dospecify f s, the confidenceintervalsplotted depend on the value of p.

pmtm

Examples This example analyzes a sinusoid in white noise.

randn( ' state ' , 0) ;

f s = 1000; t = 0: 1/ f s: 0. 3;

x = cos(2*pi *t *200) + 0. 1*randn( si ze( t ) ) ;

[ Pxx, Pxxc, f ] = pmt m( x, 3. 5, 512, f s, 0. 99) ;psdpl ot ( [ Pxx Pxxc], f , ' hz ' , ' db' )

t i t l e( ' PMTM PSD Est i mat e wi t h 99% Conf i dence I nt er val s' )

−40

−30

−20

−10

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 584: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 584/870

7-303

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

−60

−50

Frequency (Hz)

P o w e

pmtm

See Also dpss Compute the discrete prolate spheroidal sequences(Slepian sequences).

pburg Estimate the power spectral density using the Burgmethod.

pcov Estimate the power spectral density using thecovariance method.

pei g Estimate the pseudospectrum using the eigenvectormethod.

per i odogr am Estimate the power spectral density using a

periodogram.

pmcov Estimate the power spectral density using themodified covariance method.

pmusi c Estimate the pseudospectrum using the MUSI Calgorithm.

psdpl ot Plot power spectral density data

Page 585: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 585/870

7-304

References [1] Percival, D.B., and A.T. Walden, Spectral Analysis for Physical

Applications: Multitaper and Conventional U nivariateTechniques, Cambridge

University Press, 1993.

[2] Thomson, D.J ., “Spectrum estimation and harmonic analysis,”Proceedingsof theI EE E , Vol. 70 (1982), pp. 1055-1096.

psdpl ot Plot power spectral density data.

pwel ch Estimate the power spectral density using Welch’s

method.pyul ear Estimate the power spectral density using the

Yule-Walker AR method.

pmusic

7pmusicPurpose Estimate the pseudospectrum using the MUSI C algorithm.

Syntax [ S, w] = pmusi c(x, p)

[S, w] = pmusi c( . . . , nf f t )

[ S, f ] = pmusi c( x, p, nf f t , f s) )[ S, f ] = pmusi c( . . . , ' corr ' )

[S, f ] = pmus i c(x , p, nf f t , f s , nwi n, nover l ap)

[ . . . ] = pmusi c( . . . , ' r ange' )

[ . . . , v, e] = pmusi c( . . . )

pmusi c(. . . )

Description [ S, w] = pmusi c(x, p) implementstheM USI C (MultipleSignal Classification)

algorithm and returns S, the pseudospectrum estimate of the input signal x,and a vector wof normalized frequencies (in rad/sample) at which thepseudospectrum is evaluated. The pseudospectrum is calculated usingestimates of the eigenvectors of a correlation matrix associated with the inputdata x, where x is specified as either:

Page 586: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 586/870

7-305

• A row or column vector representing one observation of the signal

• A rectangular array for which each row of x represents a separateobservation of the signal (for example, each row is one output of an array of

sensors, as in array processing), such that x' *x is an estimate of thecorrelation matrix

Note You can use the output of corr mt x to generate such an array x.

You can specify the second input argument p as either:

• A scalar integer. I n this case, the signal subspace dimension is p.

• A two-element vector. I n this case, p( 2) , the second element of p, representsa threshold that is multiplied by λmin, the smallest estimated eigenvalue of the signal’s correlation matrix. Eigenvalues below the threshold λmin*p(2)

areassigned to thenoisesubspace. I n this case, p(1) specifies the maximum

dimension of the signal subspace.

pmusic

The extra threshold parameter in the second entry in p provides you moreflexibility and control in assigning the noise and signal subspaces.

S and whavethe same length. I n general, thelength of theF F T and thevalues

of the input x determine the length of the computed S and the range of the

corresponding normalized frequencies. The following tableindicates the lengthof S (and w) and the range of the corresponding normalized frequencies for thissyntax.

[ S, w] = pmusi c( . . . , nf f t ) specifies the length of the FFT used to estimatethe pseudospectrum with the integer nf f t . The default value for nf f t (entered

Table 7-29: S Characteristics for an FFT Length of 256 (Default)

Real/ Complex

Input Data

Length of S and w Range of the Corresponding

Normalized Frequencies

Real-valued 129 [0, π]

Complex-valued 256 [0, 2π)

Page 587: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 587/870

7-306

the pseudospectrum with the integer nf f t . The default value for nf f t (enteredas an empty vector [ ] ) is 256.

The following table indicates thelength of S and w, and thefrequency range forw in this syntax.

[ S, f ] = pmusi c( x, p, nf f t , f s ) returns the pseudospectrum in the vector S

evaluated at the corresponding vector of frequencies f (in Hz). You supply thesampling frequency f s in H z. I f you specify f s with the empty vector [ ] , the

sampling 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

Real-valued E ven ( nf f t / 2 + 1) [0, π]

Real-valued Odd ( nf f t + 1) / 2 [0, π)

Complex-valued Even or odd nf f t [0, 2π)

pmusic

The frequency range for f depends on nf f t , f s, and the values of the input x. The length of S (and f ) is the same as in Table 7-30. The following tableindicates the frequency range for f for this syntax.

[ S, f ] = pmusi c( . . . , ' corr ' ) forces the input argument x tobeinterpreted asa correlation matrix rather than matrix of signal data. For this syntax x mustbe a square matrix, and all of its eigenvalues must benonnegative.

[S, f ] = pmus i c(x , p, nf f t , f s , nwi n, nover l ap) allows you to specify nwi n, ascalar integer indicating a rectangular window length, or a real-valued vector

Table 7-31: S and Frequency Vector Characteristics with fs Specified

Real/ Complex Input Data nfft Even/ Odd Range of f

Real-valued Even [0, f s/ 2]

Real-valued Odd [0, f s/ 2)

Compl ex-val ued E ven or odd [0, f s)

Page 588: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 588/870

7-307

g g g g ,

specifying window coefficients. Usethe scalar integer nover l ap in conjunctionwith nwi n to specify the number of input sample points by which successivewindows overlap. nover l ap is not used if x is a matrix. The default value fornwi n is 2*p( 1) and nover l ap is nwi n- 1.

With this syntax, the input data x is segmented and windowed before the

matrix used to estimate the correlation matrix eigenvalues is formulated. Thesegmentation of the data depends on nwi n, nover l ap, and the form of x.Comments on the resulting windowed segments are described in the followingtable.

Table 7-32: Windowed Data Depending on x and nwin

Input data x Form of nwin Windowed Data

Data vector Scalar Length is nwi n

Data vector Vector of coefficients Length is l engt h( nwi n)

pmusic

See Table 7-33 for related information on this syntax.

Note The arguments nwi n and nover l ap are ignored when you include thestring ' corr ' in the syntax.

[ . . . ] = pmusi c( . . . , ' r ange' ) specifies the range of frequency values toinclude in f or w. This syntax is useful when x is real. ' r ange' can beeither:

Data matrix Scalar Data i s not windowed.

Data matrix Vector of coefficients l engt h( nwi n) must be thesame as the column length of x,and nover l ap is not used.

Table 7-32: Windowed Data Depending on x and nwin (Continued)

Input data x Form of nwin Windowed Data

Page 589: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 589/870

7-308

• ' whol e' : Compute the pseudospectrum over the frequency range [ 0, f s) . This is thedefault for determiningthefrequency rangefor complex-valued x.

- I f you specify f s as the empty vector, [ ] , the frequency range is [ 0, 1) .

- I f you don’t specify f s, the frequency range is [0, 2π).

• ' hal f ' : Compute the pseudospectrum over the frequency ranges specifiedfor real x. This is the default for determining the frequency range forreal-valued x.

Note You can put the string arguments ' r ange' or ' corr' anywhere in theinput argument list after p.

[ . . . , v, e] = pmusi c( . . . ) returns the matrix v of noise eigenvectors, alongwith theassociated eigenvalues in thevector e. The columns of v span thenoisesubspace of dimension s i ze( v, 2) . The dimension of the signal subspace iss i ze(v , 1) - s i ze( v, 2) . For this syntax, e is a vector of estimated eigenvaluesof the correlation matrix.

pmusic

pmusi c(. . . ) with no output arguments plots the pseudospectrum in thecurrent figure window.

Remarks I n the process of estimating the pseudospectrum, pmusi c computes the noise

and signal subspaces from the estimated eigenvectors v j and eigenvalues λ j of the signal’s correlation matrix. The smallest of these eigenvalues is used inconjunction with the threshold parameter p(2) to affect the dimension of thenoise subspace in some cases.

The length n of the eigenvectors computed by pmusi c is the sum of thedimensions of the signal and noise subspaces. This eigenvector length depends

on your input (signal data or correlation matrix) and the syntax you use.

The following table summarizes the dependency of the eigenvector length onthe input argument.

Table 7-33: Eigenvector Length Depending on Input Data and Syntax

Form of Input Data x Comments on the Syntax Length n of

Eigenvectors

Page 590: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 590/870

7-309

You should specify nwi n >p( 1) or l engt h( nwi n) >p( 1) if you want p( 2) >1 to

have any effect.

Row or column vector nwi n is specified as a scalar

integer.

nwi n

Row or column vector nwi n is specified as a vector. l engt h(nwi n)

Row or column vector nwi n is not specified. 2*p( 1)

l-by-m matrix I f nwi n is specified as ascalar, it is not used. I f nwi n

is specified as a vector,

l engt h( nwi n) must equalm.

m

m-by-m nonnegative

definite matrix

The string ' corr' is

specified and nwi n is notused.

m

pmusic

Examples Example 1: pmusic with no Sampling Specified

This example analyzes a signal vector x, assuming that two real sinusoidalcomponents are present in the signal subspace. I n thi s case, the dimension of the signal subspace is 4 because each real sinusoid is the sum of two complex

exponentials.

randn( ' stat e' , 0) ;

n = 0: 199;

x = cos( 0. 257*pi *n) + si n( 0. 2*pi *n) + 0. 01*r andn( si ze( n) ) ;

pmusi c( x, 4)

20

30

40

50

60

d B

MUSIC Pseudospectrum

Page 591: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 591/870

7-310

Example 2: Specifying Sampling Frequency and Subspace Dimensions

This example analyzes the same signal vector x with an eigenvalue cutoff of 10% above the minimum. Setting p( 1) =I nf forces the signal/noise subspacedecision to bebased on the threshold parameter p( 2) . Specify the eigenvectorsof length 7 using thenwi n argument, and set the sampling frequency f s to

8 kHz.

randn( ' stat e' , 0) ;

n = 0: 199;

x = cos( 0. 257*pi *n) + si n( 0. 2*pi *n) + 0. 01*r andn( si ze( n) ) ;

[ P, f ] = pmus i c(x , [ I nf , 1. 1] , [ ] , 8000, 7) ; % Wi ndow l ength = 7

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−10

0

10

Normalized Frequency (×π rad/sample)

pmusic

Example 3: Entering a Correlation Matrix

Supply a positive definite correlation matrix R for estimating the spectraldensity. Use the default 256 samples.

R = toepl i tz( cos(0. 1*pi * [0: 6] ) ) + 0. 1*eye( 7) ;

[ P, f ] = pmusi c(R, 4, ' cor r ' ) ;

Example 4: Entering a Signal Data Matrix Generated from corrmtx

Enter a signal data matrix Xmgenerated from data using cor r mt x.

randn( ' state ' , 0) ;

n = 0: 699;

x = cos(0. 257*pi *( n) ) + 0. 1*randn( si ze( n) ) ;

Xm = cor r mt x( x, 7, ' mod' ) ;[ P, w] = pmusi c( Xm, 2) ;

Example 5: Using Windowing to Create the Effect of a Signal Data Matrix

Use the same signal, but let pmusi c form the 100-by-7 data matrix using itswindowing input arguments. I n addition, specify an FF T of length 512.

Page 592: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 592/870

7-311

randn( ' state ' , 0) ;

n = 0: 699;x = cos(0. 257*pi *( n) ) + 0. 1*randn( si ze( n) ) ;

[ PP, f f ] = pmus i c( x, 2, 512, [ ] , 7, 0) ;

Algorithm The name MUSIC is an acronym for M Ultiple SI gnal Classification. TheMUSI C algorithm estimates the pseudospectrum froma signal or a correlationmatrix using Schmidt’s eigenspace analysis method [1]. The algorithmperforms eigenspace analysis of the signal’s correlation matri x in order to

estimate thesignal’s frequency content. This algorithm is particularly suitablefor signals that are the sum of sinusoids with additive white Gaussian noise. The eigenvalues and eigenvectors of the signal’s correlation matrix areestimated if you don’t supply the correlation matri x.

The MUSI C pseudospectrum estimate is given by

Pmusic

f ( )1

eH f ( ) vkvkH

k p 1+=

N

åè ø

e f ( )

----------------------------------------------------------------1

vkH e f ( ) 2

k p 1+=

N

å

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

pmusic

where N is the dimension of the eigenvectors and vk is the k-th eigenvector of the correlation matrix. The integer p is the dimension of the signal subspace,so the eigenvectors vk used in the sum correspond to the smallest eigenvaluesand also span the noise subspace. The vector e(f ) consists of complex

exponentials, so the inner product

amounts to a Fourier transform. This is used for computation of thepseudospectrum estimate. The FFT is computed for each vk and then thesquared magnitudes are summed.

See Also

vkH e f ( )

cor r mt x Prepare input data for a correlation matrix estimate.

pburg Estimate the power spectral density using the Burg

method.

pei g Estimate the pseudospectrum using the eigenvectormethod.

per i odogr am Estimate the power spectral density using a

periodogram

Page 593: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 593/870

7-312

References [1] Marple, S.L . Digital Spectral Analysis, Englewood Cliffs, NJ , Prentice-Hall,1987, pp. 373-378.

[2] Schmidt, R.O, “Multiple Emitter L ocation and Signal Parameter

Estimation,” I EEE Trans. Antennas Propagation, Vol. AP -34 (March 1986),pp. 276-280.

periodogram.

pmt m Estimate the power spectral density using themultitaper method.

prony Prony’s method for time domain I I R fi lter design.

psdpl ot Plot power spectral density data.

pwel ch Estimate the power spectral density using Welch’smethod.

r oot ei g Estimate the frequency and power content using the

root eigenvector method.r oot musi c Estimate the frequency and power content using the

root MUSIC algorithm.

pmusic

[3] Stoica, P., and R.L. Moses, I ntroduction toSpectral Analysis, Prentice-Hall,Englewood Cliffs, NJ , 1997.

Page 594: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 594/870

7-313

poly2ac

7poly2acPurpose Convert a prediction filter polynomial to an autocorrelation sequence.

Syntax r = pol y2ac(a, ef i nal )

Description r = pol y2ac(a, ef i nal ) finds the autocorrelation vector r corresponding tothe prediction filter polynomial a. The autocorrelation sequence produced isapproximately the same as that of the output of the autoregressive predictionfilter whose coefficients are determined by a. pol y2ac also produces the finall engt h( r ) step prediction err or ef i nal . I f a(1) is not equal to 1, pol y2ac

normalizes the prediction fi lter polynomial by a(1) . a(1) cannot be 0.

Remarks You can apply this function to both real and complex polynomials.

Examples a = [ 1. 0000 0. 6147 0. 9898 0. 0004 0. 0034 - 0. 0077] ;

ef i nal = 0. 2;

r = pol y2ac( a, ef i nal )

r =

5. 5917

1 7277

Page 595: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 595/870

7-314

- 1. 7277

- 4. 4231

4. 3985

1. 6426

- 5. 3126

See Also

References [1] K ay, S.M. Modern Spectral E stimation, Englewood Cliffs, NJ ,Prentice-Hall, 1988.

ac2pol y Convert an autocorrelation sequence to a predictionfilter polynomial.

pol y2r c Convert a prediction filter polynomial to reflection

coefficients.r c2ac Convert reflection coefficients to an autocorrelation

sequence.

poly2lsf

7poly2lsf Purpose Convert prediction filter coefficients to li ne spectral frequencies.

Syntax l sf = pol y2l sf ( a)

Description l sf = pol y2l sf ( a) returns a vector l sf of li ne spectral frequencies (alsoknown as line spectrum pairs) from a vector a of prediction filter coefficients.

Examples a = [ 1. 0000 0. 6149 0. 9899 0. 0000 0. 0031 - 0. 0082] ;

l sf = pol y2l sf ( a)

l sf =

0. 7842

1. 5605

1. 8776

1. 8984

2. 3593

See Also l s f 2pol y Convert line spectral frequencies to prediction filtercoefficients.

Page 596: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 596/870

7-315

References [1] Deller, J .R., J .G. Proakis, and J .H.L. Hansen, “Discrete-TimeP rocessing of

Speech Signals,” Prentice-Hall, 1993.

[2] Rabiner, L.R., and R.W. Schafer, “Digital Processing of Speech Signals,”Prentice-Hall, 1978.

poly2rc

7poly2rcPurpose Convert a prediction filter polynomial to reflection coefficients.

Syntax k = pol y2rc (a)

[ k, r 0] = pol y2r c(a, ef i nal )

Description k = pol y2rc (a) converts the prediction filter polynomial a to the reflection

coefficients of the corresponding lattice structure. a can be real or complex, anda(1) cannot be 0. I f a( 1) is not equal to 1, pol y2r c normalizes the predictionfilter polynomial by a( 1) . k is a row vector of size l engt h( a) - 1.

[ k, r 0] = pol y2r c(a, ef i nal ) returns the zero-lag autocorrelation, r 0, basedon the final prediction error, ef i nal .

A simple, fast way to check if a has all of its roots inside the unit circle is tocheck i f each of the elements of k has magnitude less than 1.

stabl e = al l ( abs(pol y2rc( a) ) <1)

Examples a = [ 1. 0000 0. 6149 0. 9899 0. 0000 0. 0031 - 0. 0082] ;

ef i nal = 0. 2;

Page 597: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 597/870

7-316

[ k, r 0] = pol y2r c(a, ef i nal )

k =

0. 3090

0. 9801

0. 0031

0. 0081

- 0. 0082

r 0 =

5. 6032

Limitations I f abs( k( i ) ) == 1 for any i , finding the reflection coefficients is anil l-conditioned problem. pol y2r c returns some NaNs and provide a warning

message in this case.

poly2rc

Algorithm pol y2r c implements the recursive relationship

This relationship is based on L evinson’s recursion [1]. To implement it,pol y2r c loops through a in reverse order after discarding its first element. F oreach loop iteration i , the function:

1 Sets k( i ) equal to a( i )

2 Applies the second relationship above to elements 1 through i of thevector a.

a = ( a–k( i ) * f l i pl r ( a) ) / ( 1–k( i ) 2) ;

See Also

k n( ) an n( )=

an 1– m( )a

nm( ) k n( )a

nn m–( )–

1 k n( )2–---------------------------------------------------------- m 1= 2 … n 1–, , , ,=

ac2r c Convert an autocorrelation sequence to reflectioncoefficients.

l atc2t f Convert a lattice filter parameters to transferf ti f

Page 598: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 598/870

7-317

References [1] K ay, S.M. Modern Spectral Estimation, Englewood Cliffs, NJ ,Prentice-Hall, 1988.

function form.

l at cf i l t L attice and lattice-ladder filter implementation.

pol y2ac Convert a prediction filter polynomial to anautocorrelation sequence.

r c2pol y Convert reflection coefficients to a prediction filterpolynomial.

t f 2l at c Convert transfer function filter parameters to latticefilter form.

polyscale

7polyscalePurpose Scale the roots of a polynomial.

Syntax b = pol yscal e( a, al pha)

Description b = pol yscal e( a, al pha) scales the roots of a polynomial in the z-plane,where a is a vector containing the polynomial coefficients and al pha is thescaling factor.

I f al pha is a real valuein therange[ 0 1] , then theroots of a areradially scaledtoward the origin in the z-plane. Complex values for al pha allow arbitrary

changes to the root locations.

Remark By reducing the radius of the roots in an autoregressive polynomial, the

bandwidth of the spectral peaks in the frequency response is expanded(flattened). This operation is often referred to as bandwidth expansion.

See Also pol yst ab Stabilize a polynomial.

roots Polynomial roots (see the MATL AB documentation).

Page 599: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 599/870

7-318

polystab

7polystabPurpose Stabilize polynomial.

Syntax b = pol ystab( a)

Description pol yst ab stabilizes a polynomial with respect to theunit circle; it reflects rootswith magnitudes greater than 1 inside the unit circle.

b = pol ystab( a) returns a row vector b containing the stabilized polynomial,where a is a vector of polynomial coefficients, normally in the z-domain.

Examples pol yst ab can convert a linear-phase filter into a minimum-phase filter withthe same magnitude response.

h = f i r 1( 25, 0. 4) ;

hmi n = pol yst ab( h) * nor m( h) / nor m( pol yst ab( h) ) ;

Algorithm pol yst ab finds the roots of the polynomial and maps thoseroots found outsidethe unit circle to the inside of the unit circle.

a z( ) a 1( ) a 2( )z 1–L a na 1+( )z na–+ + +=

Page 600: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 600/870

7-319

v = r oot s( a) ;vs = 0. 5*(s i gn( abs(v)- 1) +1) ;

v = (1- vs) . *v + vs . / conj ( v) ;

b = a(1)*pol y(v ) ;

See Also roots Polynomial roots (see the MATLAB documentation).

prony

7pronyPurpose Prony’s method for time domain I I R fi lter design.

Syntax [ b, a] = prony( h, nb, na)

Description Prony’s method is an algorithm for finding an I I R filter with a prescribed timedomain impulse response. I t has applications in filter design, exponentialsignal modeling, and system identification (parametri c modeling).

[ b, a] = prony( h, nb, na) finds a filter with numerator order nb, denominatororder na, and the time domain impulse response in h. prony returns the filter

coefficients in row vectors b and a, of length nb +1 and na +1, respectively. Thefilter coefficients are in descending powers of z.

Examples Recover the coefficients of a Butterworth filter from its impulse response.

[b, a] = but t er ( 4, 0. 2)

b =

H z( )B z( )

A z( )-----------

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

a 1( ) a 2( )z 1–L a na 1+( )z na–+ + +

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

Page 601: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 601/870

7-320

0. 0048 0. 0193 0. 0289 0. 0193 0. 0048

a =

1. 0000 - 2. 3695 2. 3140 - 1. 0547 0. 1874

h = f i l t er ( b, a, [ 1 zer os(1, 25) ] ) ;

[ bb, aa] = prony( h, 4, 4)

bb =

0. 0048 0. 0193 0. 0289 0. 0193 0. 0048

ab =

1. 0000 - 2. 3695 2. 3140 - 1. 0547 0. 1874

Algorithm prony implements the method described in reference [1]. This method uses avariation of the covariance method of AR modeling to find the denominatorcoefficients a andthen finds the numerator coefficients b for which theimpulseresponseof the output filter matches exactly the first nb +1 samples of x. Thefilter is not necessarily stable, but potentially can recover the coefficients

prony

exactly if the data sequence is truly an autoregressivemoving average(ARM A)process of the correct order.

See Also

References [1] Parks, T.W., and C.S. Burrus, Digital Filter Design, J ohn Wiley & Sons,1987, pp. 226-228.

but t er Butterworth analog and digital filter design.

cheby1 Chebyshev type I filter design (passband ripple).cheby2 Chebyshev type I I filter design (stopband ripple).

el l i p Elliptic (Cauer) filter design.

i nvf r eqz I dentify discrete-time filter parameters fromfrequency response data.

l evi nson Compute the L evinson-Durbin recursion.

l pc Compute linear prediction filter coefficients.

st mcb Compute a linear model using Steiglitz-McBride

iteration.

Page 602: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 602/870

7-321

psdplot

7psdplotPurpose Plot power spectral density (PSD) data.

Syntax psdpl ot( Pxx, w)

psdpl ot ( Pxx, w, ' uni t s' )

psdpl ot ( Pxx, w, ' uni t s' , ' yscal e' )psdpl ot ( Pxx, w, ' uni t s' , ' yscal e' , ' t i t l e' )

Description psdpl ot( Pxx, w) plots the power spectral density data contained in the vectorPxx at the frequencies specifi ed in the vector w. The vectors Pxx and wmusthavethesamelength. Themagnitudeof thedata vector Pxx is plotted in dB per

radians per sample versus frequency won one plot. The units for frequency onthe plots are rad/sample.

psdpl ot ( Pxx, w, ' uni t s' ) displays the frequency units according to the string' uni t s' . This string can be either:

• ' r ad/ sampl e' (default)

• ' Hz'

psdpl ot ( Pxx, w, ' uni t s' , ' yscal e' ) displays the spectral density magnitudeunits according to the string ' yscal e' This string can be either:

Page 603: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 603/870

7-322

units according to the string yscal e . This string can be either:

• ' db' (default), for plotting the PSD in dB per units of frequency

• ' l i near ' , for plotting the PSD in units of power per units of frequency

psdpl ot ( Pxx, w, ' uni t s' , ' yscal e' , ' t i t l e' ) uses the contents of the string' t i t l e' as the title of the plot.

Examples t = 0: 0. 001: 0. 3;

x = cos( 2*pi *t *200) + r andn( si ze( t ) ) ;[ Pxx, w] = per i odogr am( x, [ ] , ' t wosi ded' , 512) ;

psdpl ot ( Pxx, w, ' ' , ' ' , ' Sampl e PSD Pl ot ' )

psdplot

See Also

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8−35

−30

−25

−20

−15

−10

−5

0

5

10

15

Normalized Frequency (×π rad/sample)

P o w e r S p e c t r a l D e n s i t y ( d B / r a d / s a m p l e )

Sample PSD Plot

f r eqzpl ot Plot frequency response data.

pburg Estimate the power spectral density using the Burgmethod.

Page 604: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 604/870

7-323

pcov Estimate the power spectral density using thecovariance method.

pei g Estimate the pseudospectrum using the eigenvectormethod.

peri odogr am Estimate the power spectral density using aperiodogram.

pmcov Estimate the power spectral density using the

modified covariance method.

pmusi c Estimate the pseudospectrum with theMUSI Calgorithm.

pwel ch Estimate the power spectral density using Welch’smethod.

pyul ear Estimate the power spectral density using the

Yule-Walker AR method.

pulstran

7pulstranPurpose Generate a pulse train.

Syntax y = pul st r an( t , d, ' f unc' )

y = pul st r an( t , d, ' f unc' , p1, p2, . . . )

y = pul st r an( t , d, p, f s)y = pul st r an( t , d, p)

Description pul st r an generates pulse trains from continuous functions or sampledprototype pulses.

y = pul st r an( t , d, ' f unc' ) generates a pulse train based on samples of a

continuous function, ' f unc' , where ' f unc' is:

• ' gauspul s' , for generating a Gaussian-modulated sinusoidal pulse

• ' rectpul s ' , for generating a sampled aperiodic rectangle

• ' t r i pul s' , for generating a sampled aperiodic triangle

pul st r an is evaluated l engt h( d) times and returns thesum of theevaluationsy = f unc( t - d( 1) ) + f unc( t - d( 2) ) + . . .

The function i s evaluated over the range of argument values specified in

Page 605: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 605/870

7-324

array t , after removing a scalar argument offset taken from the vector d. Notethat f unc must be a vectorized function that can take an array t as anargument.

An optional gain factor maybeapplied toeach delayed evaluation byspecifyingd as a two-column matrix, with the offset defined in column 1 and associatedgain in column 2 of d. Note that a row vector will be interpreted as specifying

delays only.

pul st r an( t , d, ' f unc' , p1, p2, . . . ) allows additional parameters to bepassedto ' f unc' as necessary. For example,

f unc(t - d( 1) , p1, p2, . . . ) + f unc(t - d( 2) , p1, p2, . . . ) + . . .

pul s t ran( t , d, p, f s ) generates a pulsetrain that is the sum of multipledelayed interpolations of the prototype pulse in vector p, sampled at therate f s, where p spans the time interval [ 0, ( l ength( p) - 1) / f s ] , and its

samples areidentically 0 outside this interval. By default, linear interpolationis used for generating delays.

pulstran

pul str an( t , d, p) assumes that the sampling rate f s is equal to 1 Hz.

pul st r an( . . . , ' f unc' ) specifies alternative interpolation methods. Seei nt er p1 for a list of available methods.

Examples Example 1 This example generates an asymmetric sawtooth waveform with a repetitionfrequency of 3 Hz and a sawtooth width of 0.1s. I t has a signal length of 1s anda 1 kHz sample rate.

t = 0 : 1/ 1e3 : 1; % 1 kHz sampl e f r eq f or 1 sec

d = 0 : 1/ 3 : 1; % 3 Hz repet i t i on f req

y = pul st r an( t , d, ' t r i pul s' , 0. 1, - 1) ;

pl ot ( t , y)

0.6

0.7

0.8

0.9

1

Page 606: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 606/870

7-325

0 0.2 0.4 0.6 0.8 10

0.1

0.2

0.3

0.4

0.5

pulstran

Example 2

This example generates a periodic Gaussian pulse signal at 10 kH z, with 50%bandwidth. Thepulserepetition frequency is 1 kHz, sample rateis 50 kHz, andpulsetrain length is 10 msec. The repetition amplitudeshould attenuateby 0.8

each time.t = 0 : 1/ 50E3 : 10e- 3;

d = [ 0 : 1/ 1E3 : 10e- 3 ; 0. 8. ( 0: 10) ] ' ;

y = pul st r an( t , d, ' gauspul s ' , 10e3, 0. 5) ;

pl ot ( t , y)

-0.2

0

0.2

0.4

0.6

0.8

1

Page 607: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 607/870

7-326

0 0.002 0.004 0.006 0.008 0.01-0.8

-0.6

-0.4

pulstran

Example 3

This example generates a train of 10 Hamming windows.

p = hammi ng( 32) ;

t = 0: 320; d = ( 0: 9) ' *32;

y = pul st r an( t , d, p) ;pl ot ( t , y)

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

Page 608: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 608/870

7-327

See Also

0 50 100 150 200 250 300 3500

chi rp Generate a swept-frequency cosine.

cos Compute the cosine of vector/matrix elements (seethe MATL AB documentation).

di r i c Compute the Dirichlet or periodic sinc function.

gauspul s Generate a Gaussian-modulated sinusoidal pulse.

r ectpul s Generate a sampled aperiodic rectangle.

sawt oot h Generate a sawtooth or triangle wave.

si n Compute the sine of vector/matrix elements (see theMAT L AB documentation).

s i nc Compute the sinc or sin(πt)/πt function.

square Generate a square wave.

t r i pul s Generate a sampled aperiodic triangle.

pwelch

7pwelchPurpose Estimate the power spectral density (PSD) of a signal using Welch’s method.

Syntax [ Pxx, w] = pwel ch( x)

[ Pxx, w] = pwel ch( x, nwi n)

[ Pxx, w] = pwel ch( x, nwi n, nover l ap)

[ Pxx, w] = pwel ch( x, nwi n, nover l ap, nf f t )

[ Pxx, f ] = pwel ch( x, nwi n, nover l ap, nf f t , f s)

[ . . . ] = pwel ch(x, nwi n, nover l ap, . . . , ' r ange' )

pwel ch( . . . )

Description [ Pxx, w] = pwel ch( x) estimates the power spectral density Pxx of the inputsignal vector x using Welch’s averaged modified peri odogram method of

spectral estimation. With this syntax:

• The vector x is segmented into eight sections of equal length, each with 50%overlap.

• Any remaining (trailing) entries in x that cannot be included in the eightsegments of equal length are discarded.

• Each segment is windowed with a Hamming window (see hammi ng) that isthe same length as the segment.

Page 609: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 609/870

7-328

The power spectral density is calculated in units of power per radians persample. The corresponding vector of frequencies wis computed in radians persample, and has the same length as Pxx.

A real-valued input vector x produces a full power one-sided (in frequency) PSD(by default), while a complex-valued x produces a two-sided PSD.

I n general, thelength N of the FF T and the values of the input x determine the

length of Pxx and the range of the corresponding normalized frequencies. Forthis syntax, the (default) length N of the FF T is the larger of 256 and the nextpower of two greater than the length of the segment. The following table

pwelch

indicates the length of Pxx and the range of the corresponding normalizedfrequencies for this syntax.

[ Pxx, w] = pwel ch( x, nwi n) calculates the modified periodogram using either:

• The window length nwi n for the Hamming window when nwi n is a positiveinteger

• The window weights specified in nwi n when nwi n is a vector

With this syntax, the input vector x is divided into an integer number of

segments with 50%overlap, and each segment is the same length as thewindow. Entries in x that are left over after it is divided into segments arediscarded. I f you specify nwi n as the empty vector [ ] , then the signal data is

divided into eight segments and a Hamming window is used on each one

Table 7-34: PSD Vector Characteristics for an FFT Length of N (Default)

Real/ ComplexInput Data

Length of Pxx Range of the CorrespondingNormalized Frequencies

Real-valued (N/2) +1 [0, π]

Complex-valued N [0, 2π)

Page 610: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 610/870

7-329

divided into eight segments, and a Hamming window is used on each one.

[ Pxx, w] = pwel ch( x, nwi n, nover l ap) divides x into segments according tonwi n, and uses the integer nover l ap to specify the number of signal samples(elements of x) that are common to two adjacent segments. nover l ap must beless than the length of the window you specify. I f you specify nover l ap as theempty vector [ ] , then pwel ch determines the segments of x sothat there is 50%overl ap (default).

[ Pxx, w] = pwel ch( x, nwi n, nover l ap, nf f t ) uses Welch’s method to estimatethePSD while specifyingthel ength of theF FT with theinteger nf f t . I f you setnf f t to the empty vector [ ] , it adopts the default value for N listed in theprevious syntax.

pwelch

The length of Pxx and the frequency range for wdepend on nf f t and thevaluesof theinput x. The followingtable indicates thel ength of Pxx and the frequencyrange for wfor this syntax.

[ Pxx, f ] = pwel ch( x, nwi n, nover l ap, nf f t , f s) uses the sampling frequency

f s specifiedasan integer in hertz (Hz) tocomputetheP SD vector (Pxx)andthecorresponding vector of frequencies (f ). I n this case, theunits for thefrequencyvector are in Hz. The spectral density produced is calculated in units of powerper H z. I f you specify f s as the empty vector [ ] , the sampling frequencydefaults to 1 Hz.

The frequency range for f depends on nf f t , f s, and the values of the input x.Th l th f P i th i T bl 7 35 Th f ll i t bl i di t th

Table 7-35: PSD and Frequency Vector Characteristics

Real/ Complex

Input Data

nfft Even/ Odd Length of Pxx Range of w

Real-valued E ven ( nf f t / 2 + 1) [0, π]

Real-valued Odd ( nf f t + 1) / 2 [0, π)

Complex-valued Even or odd nf f t [0, 2π)

Page 611: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 611/870

7-330

The length of Pxx isthesameasin Table 7-35. The followingtable indicates thefrequency range for f for this syntax.

Table 7-36: PSD and Frequency Vector Characteristics with fs Specified

Real/ Complex Input Data nfft Even/ Odd Range of f

Real-valued Even [0, f s /2]

Real-valued Odd [0, f s /2)

Complex-valued E ven or odd [0, f s )

pwelch

[ . . . ] = pwel ch(x ,nwi n, nover l ap, . . . , ' r ange' ) specifies the range of frequency values. This syntax is useful when x is real. Thestring ' r ange' can

be either:

• ' t wosi ded' : Compute the two-sided PSD over the frequency range [ 0, f s) .

This is the default for determining the frequency range forcomplex-valued x.

- I f you specify f s as the empty vector, [ ] , the frequency range is [ 0, 1) .

- I f you don’t specify f s, the frequency range is [0, 2π).

• ' onesi ded' : Computethe one-sided PSD over thefrequency ranges specified

for real x. This is the default for determining the frequency range forreal-valued x.

The string ' r ange' can appear anywhere in the syntax after nover l ap.

pwel ch( x, . . . ) with no output arguments plots the PSD estimate in dB perunit frequency in the current figure window.

Examples Estimate the PSD of a signal composed of a sinusoid plus noise, sampled at1000 Hz. Use33-sample windows with 32-sampleoverlap, and thedefault F FTlength, and display the two-sided PSD estimate.

randn( ' state ' 0) ;

Page 612: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 612/870

7-331

randn( state , 0) ;

Fs = 1000; t = 0: 1/ Fs: . 3;

x = cos( 2*pi *t *200) + r andn( si ze(t ) ) ; % 200Hz cosi ne pl us noi se

pwel ch( x, 33, 32, [ ] , Fs, ' t wosi ded' )

pwelch

Algorithm pwel ch calculates the power spectral density using Welch’s method (see

references):

1 The input signal vector x is divided into k overlapping segments accordingd ( h i d f l l )

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 613: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 613/870

7-332

The input signal vector x is divided into k overlapping segments accordingto nwi n and nover l ap (or their default values).

2 The specified (or default) window is applied to each segment of x.

3 An nf f t -point F FT is applied to the windowed data.

4 The (modified) periodogram of each windowed segment is computed.

5 The set of modified periodograms is averaged to form the spectrum estimateS(e jω).

6 The resulting spectrum estimate is scaled to compute the power spectraldensity as , where F is:

- 2π when you do not supply the sampling frequency

- f s when you supply the sampling frequency

S e j ω

( ) F ⁄

pwelch

The number of segments k that x is divided into is calculated as:

• Eight if you don’t specify nwi n, or if you specify it as the empty vector [ ]

• if you specify nwi n as a nonempty vector or a scalar

I n this equation, m is the length of the signal vector x, o is the number of overlapping samples (nover l ap), and l is the length of each segment (thewindow length).

See Also

km o–

l o–--------------=

pburg Estimate the power spectral density using the Burgmethod.

pcov Estimate the power spectral density using the

covariance method.pei g Estimate the pseudospectrum using the eigenvector

method.

peri odogr am Estimate the power spectral density using aperiodogram.

pmcov Estimate the power spectral density using themodified covariance method.

pmt m Estimate the power spectral density using the

Page 614: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 614/870

7-333

References [1] Hayes, M., Statistical Digital Signal Pr ocessing and Modeli ng, J ohn Wiley& Sons, 1996.

p p p y gmultitaper method.

pmusi c Estimate the pseudospectrum using the MU SI Calgorithm.

psdpl ot Plot power spectral density data.

pyul ear Estimate the power spectral density using the Yule-Walker AR method.

pwelch

[2] Stoica, P., and R.L. Moses, I ntroduction toSpectral Analysis, Prentice-Hall,Englewood Cli ffs, NJ , 1997, pp. 52-54.

[3] Welch, P.D, “The Useof Fast Fourier Transform for theE stimation of Power

Spectra: A Method Based on T ime Averaging Over Short, Modified

Periodograms,” I EEE Trans. Audio Electroacoustics, Vol. AU -15 (J une1967),pp. 70-73.

Page 615: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 615/870

7-334

pyulear

7pyulearPurpose Estimate the power spectral density using the Y ule-Walker AR method.

Syntax Pxx = pyul ear( x, p)

[Pxx, w] = pyul ear ( x, p, nf f t )

[ Pxx, f ] = pyul ear ( x, p, nf f t , f s)

[ Pxx, f ] = pyul ear ( x, p, nf f t , f s, ' r ange' )

[Pxx, w] = pyul ear ( x, p, nf f t , ' r ange' )

pyul ear ( . . . )

Description Pxx = pyul ear( x, p) implements the Y ule-Walker algorithm, a parametricspectral estimation method, andreturns Pxx, an estimateof the power spectraldensity (PSD) of the vector x. The entries of x represent samples of a

discrete-time signal. p is the integer specifying the order of an autoregressive(AR) prediction model for the signal, used in estimating the PSD.

The power spectral density is calculated in units of power per radians persample. Real-valued inputs produce full power one-sided (in frequency) PSDs(by default), while complex-valued inputs produce two-sided PSDs.

I n general, the length of the FF T and the values of the input x determine the

length of Pxx and the range of the corresponding normalized frequencies. F or

this syntax, the (default) FFT length is 256. The following table indicates thelength of Pxx and the range of the corresponding normali zed frequencies for

Page 616: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 616/870

7-335

length of Pxx and the range of the corresponding normali zed frequencies forthis syntax.

[ Pxx, w] = pyul ear( x, p) also returns w, a vector of frequencies at which thePSD is estimated. Pxx and whave thesame length. The units for frequency arerad/sample.

Table 7-37: PSD Vector Characteristics for an FFT Length of 256 (Default)

Real/ Complex

Input Data

Length of Pxx Range of the Corresponding

Normalized Frequencies

Real-valued 129 [0, π]

Complex-valued 256 [0, 2π)

pyulear

[ Pxx, w] = pyul ear ( x, p, nf f t ) uses the Yule-walker method to estimate thePSD whilespecifyingthelength of theF FT with theinteger nf f t . I f you specify

nf f t as the empty vector [ ] , it adopts the default value of 256.

The length of Pxx and the frequency range for wdepend on nf f t and thevalues

of theinput x. The followingtable indicates thel ength of Pxx and the frequencyrange for wfor this syntax.

[ Pxx, f ] = pyul ear ( x, p, nf f t , f s) uses the sampling frequency f s specified

as an integer i n hertz (Hz) to compute the PSD vector (Pxx) and thecorresponding vector of frequencies (f ). I n this case, theunits for thefrequencyvector are in Hz. The spectral density produced is calculated in units of powerper H z. I f you specify f s as the empty vector [ ] , the sampling frequency

Table 7-38: PSD and Frequency Vector Characteristics

Real/ ComplexInput Data

nfft Even/ Odd Length of Pxx Range of w

Real-valued E ven ( nf f t / 2 + 1) [0, π]

Real-valued Odd ( nf f t + 1) / 2 [0, π)

Complex-valued Even or odd nf f t [0, 2π)

Page 617: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 617/870

7-336

defaults to 1 Hz.

The frequency range for f depends on nf f t , f s, and the values of the input x. The length of Pxx isthesameasin Table 7-38. The followingtable indicates thefrequency range for f for this syntax.

Table 7-39: PSD and Frequency Vector Characteristics with fs Specified

Real/ Complex Input Data nfft Even/ Odd Range of f

Real-valued Even [0, f s /2]

Real-valued Odd [0, f s /2)

Complex-valued E ven or odd [0, f s )

pyulear

[ Pxx, f ] = pyul ear ( x, p, nf f t , f s, ' r ange' ) or

[Pxx, w] = pyul ear ( x, p, nf f t , ' r ange' ) specifies the range of frequencyvalues to include in f or w. This syntax is useful when x is real. ' r ange' can beeither:

• ' t wosi ded' : Compute the two-sided PSD over the frequency range [ 0, f s) . This is the default for determining the frequency range forcomplex-valued x.

- I f you specify f s as the empty vector, [ ] , the frequency range is [ 0, 1) .

- I f you don’t specify f s, the frequency range is [0, 2π).

• ' onesi ded' : Computethe one-sided PSD over thefrequency ranges specifiedfor real x. This is the default for determining the frequency range for

real-valued x.

Note You can put the string argument ' r ange' anywhere in the inputargument list after p.

pyul ear ( . . . ) plots the power spectral density in the current figure window. The frequency range on the plot i s the same as the range of output w(or f ) for

i t f t

Page 618: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 618/870

7-337

a given set of parameters.

Examples Because the Yule-walker method estimates the spectral density by fitti ng anAR prediction model of a given order to the signal, first generate a signal froman AR (all-pole) model of a given order. You can use f r eqz to check themagnitude of the frequency response of your AR filter. This will give you anidea of what to expect when you estimate the PSD using pyul ear .

a = [ 1 - 2. 2137 2. 9403 - 2. 1697 0. 9606] ; % AR f i l t er coef f i ci ent s

f reqz(1, a) % AR f i l t er f requency response

t i t l e( ' AR Syst em Frequency Response' )

pyulear

Now generate the input signal x by filtering white noisethrough theA R filter.Estimate the PSD of x based on a fourth-order AR prediction model, since inthis case, we know that the original AR system model a has order 4.

randn( ' stat e' , 1) ;

x = f i l t er( 1, a, randn( 256, 1) ) ; % AR system output

pyul ear ( x, 4) % Four t h- or der est i mat e

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

−150

−100

−50

0

50

100

Normalized Frequency (×π rad/sample)

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

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−20

−10

0

10

20

30

40

Normalized Frequency (×π rad/sample)

M a g n i t u d e ( d B )

AR System Frequency Response

Page 619: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 619/870

7-338

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

−25

−20

−15

−10

−5

0

5

10

15

20

25

Normalized Frequency (×π rad/sample)

P o w e r S p e c t r a l D e n s i t y ( d B / r a d / s a m p l e )

Yule−Walker PSD Estimate

pyulear

Remarks The power spectral density is computed as the distribution of power per unit

frequency.

This algorithm depends on your selecting an appropriate model order for yoursignal.

Algorithm L inear prediction filters can be used to model the second-order statisticalcharacteristics of a signal. The prediction filter output can beused tomodel thesignal when the input is white noise.

pyul ear estimates thePSD of an input signal vector using theY ule-Walker ARmethod. This method, alsocalled the autocorrelation or windowed method, fitsan autoregressive (AR) li near prediction filter model to the signal byminimizing theforward prediction error (based on all observations of thein putsequence) in the least squares sense. This formulation leads to the Yule-Walker equations, which are solved by the L evinson-Durbin recursion. The spectral estimate returned by pyul ear is the squared magnitude of the

frequency response of this AR model.

Page 620: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 620/870

7-339

pyulear

See Also ar yul e Compute an estimate of AR model parameters usingthe Yule-Walker method.

l pc L inear prediction coefficients.

pburg Estimate the power spectral density using the Burg

method.pcov Estimate the power spectral density using the

covariance method.

pei g Estimate the pseudospectrum using the eigenvectormethod.

peri odogr am Estimate the power spectral density using aperiodogram.

pmcov Estimate the power spectral density using themodified covariance method.

pmt m Estimate the power spectral density using themultitaper method.

pmusi c Estimate the pseudospectrum using the MUSI Calgorithm.

prony Prony’s method for time domain I I R fi lter design.

psdpl ot Plot power spectral density data.

pwel ch Estimate the power spectral density using Welch’s

Page 621: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 621/870

7-340

References [1] Marple, S.L., Digital Spectral Analysis, Prentice-Hall, 1987, Chapter 7.

[2] Stoica, P., and R.L. Moses, I ntroduction toSpectral Analysis, Prentice-Hall,

1997.

pwel ch Estimate the power spectral density using Welchsmethod.

rc2ac

7rc2acPurpose Convert reflection coefficients to an autocorrelation sequence.

Syntax r = r c2ac( k, r 0)

Description r = r c2ac( k, r 0) finds the autocorrelation coefficients, r , of theoutput of the

discrete-timeprediction error filter from the lattice-form reflection coefficientsk and initial zero-lag autocorrelation r 0.

Examples k = [ 0. 3090 0. 9800 0. 0031 0. 0082 - 0. 0082] ;

r 0 = 0. 1;

a = r c2ac( k, r 0)

a =

0. 1000- 0. 0309

- 0. 0791

0. 0787

0. 0294

- 0. 0950

See Also ac2r c Convert an autocorrelation sequence to reflection

coefficients.pol y2ac Convert a prediction filter polynomial to an

Page 622: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 622/870

7-341

References [1] K ay, S.M., Modern Spectral E stimation, Prentice-Hall, Englewood Cliffs,

NJ , 1988.

p p yautocorrelation sequence.

r c2pol y Convert reflection coefficients to a prediction filterpolynomial.

rc2is

7rc2isPurpose Convert reflection coefficients to inverse sine parameters.

Syntax i si n = r c2i s( k)

Description i si n = i s2r c( k) returns a vector of inverse sine parameters i s i n from a

vector of reflection coefficients k.

Examples k = [ 0. 3090 0. 9801 0. 0031 0. 0082 - 0. 0082] ;

i s i n = r c2i s( k)

i si n =

0. 2000 0. 8728 0. 0020 0. 0052 - 0. 0052

See Also i s2rc Convert inverse sine parameters to reflectioncoefficients.

References [1] Deller, J .R., J .G. Proakis, and J .H.L. Hansen, “Discrete-TimeP rocessing of

Speech Signals,” Prentice-Hall, 1993.

Page 623: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 623/870

7-342

rc2lar

7rc2larPurpose Convert reflection coefficients to log area ratio parameters.

Syntax g = r c2l ar ( k)

Description g = r c2l ar ( k) returns a vector of log area ratio parameters g from a vector of

reflection coefficients k.

Examples k = [ 0. 3090 0. 9801 0. 0031 0. 0082 - 0. 0082] ;

g = r c2l ar ( k)

g =

0. 6389 4. 6002 0. 0062 0. 0164 - 0. 0164

See Also l ar2rc Convert log area ratio parameters to reflectioncoefficients.

References [1] Deller, J .R., J .G. Proakis, and J .H.L. Hansen, “Discrete-TimeP rocessing of

Speech Signals,” Prentice-Hall, 1993.

Page 624: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 624/870

7-343

rc2poly

7rc2polyPurpose Convert reflection coefficients to a prediction filter polynomial.

Syntax a = rc2pol y(k )

[ a, ef i nal ] = r c 2pol y( k, r 0)

Description a = rc2pol y(k ) converts the reflection coefficients k corresponding to thelatticestructure totheprediction filter polynomial a,with a( 1) =1. The outputa is row vector of length l engt h( k)+1.

[ a, ef i nal ] = r c 2pol y( k, r 0) returns thefinal prediction error ef i nal basedon the zero-lag autocorr elation, r 0.

Example Consider a lattice I I R filter given by reflection coefficients k.

k = [ 0. 3090 0. 9800 0. 0031 0. 0082 - 0. 0082] ;

I ts equivalent prediction filter representation is given by

a = rc2pol y(k )

a =

1. 0000 0. 6148 0. 9899 0. 0000 0. 0032 - 0. 0082

Algorithm r c2pol y computes output a using L evinson’s recursion [1]. The function:

S t th t t t t th fi t l t f k

Page 625: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 625/870

7-344

1 Sets the output vector a to the first element of k

2 Loops through the remaining elements of k

For each loop iteration i , a = [a + a( i - 1: - 1: 1) * k( i ) k( i ) ] .

3 I mplements a = [ 1 a]

rc2poly

See Also

References [1] K ay, S.M., Modern Spectral E stimation, Prentice-Hall, Englewood Cliffs,NJ , 1988.

ac2pol y Convert an autocorrelation sequence to a predictionfilter polynomial.

l atc2t f L attice filter to transfer function conversion.

l at cf i l t L attice and lattice-ladder filter implementation.

pol y2r c Convert a prediction filter polynomial to reflectioncoefficients.

r c2ac Convert reflection coefficients to an autocorrelationsequence.

rc2i s Convert reflection coefficients to inverse sineparameters.

r c2l ar Convert reflection coefficients to log area ratio

parameters.t f 2l at c Convert transfer function to lattice filter.

Page 626: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 626/870

7-345

rceps

7rcepsPurpose Real cepstrum and minimum phase reconstruction.

Syntax y = r ceps(x)

[ y, ym] = rceps(x)

Description The real cepstrum is theinverseF ourier transform of thereal logarithm of themagnitude of the Fourier transform of a sequence.

r ceps( x) returns the real cepstrum of the real sequence x. The real cepstrumis a real-valued function.

[ y, ym] = rceps(x) returns both the real cepstrum y and a minimum phasereconstructed version ymof the input sequence.

Algorithm r ceps is an M-file implementation of algorithm 7.2 in [2], that is,

y = r eal ( i f f t ( l og( abs( f f t ( x) ) ) ) ) ;

Appropriate windowing in the cepstral domain forms the reconstructedminimum phase signal.

w = [ 1; 2*ones(n/2-1, 1) ; ones( 1 - r em( n, 2) , 1) ; zer os( n/ 2- 1, 1) ] ;

ym = r eal ( i f f t ( exp( f f t ( w. *y) ) ) ) ;

See Also cceps Complex cepstral analysis.

Page 627: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 627/870

7-346

References [1] Oppenheim, A.V., and R.W. Schafer, Digital Signal Processing, EnglewoodCliffs, NJ , Prentice-Hall, 1975.

[2] Programs for Digital Signal Processing, I EE E Press, New York, 1979.

p p y

f f t One-dimensional fast Fourier transform.

hi l bert Hilbert transform.

i cceps I nverse complex cepstrum.

unwr ap Unwrap phase angles.

rectpuls

7rectpulsPurpose Generate a sampled aperiodic rectangle.

Syntax y = r ect pul s( t )

y = r ect pul s( t , w)

Description y = r ect pul s( t ) returns a continuous, aperiodic, unity-height rectangularpulseat thesampletimes indicated in array t , centered about t =0 and with adefault width of 1. Note that theinterval of non-zero amplitudeis defined to beopen on the right, that is, r ectpul s( - 0. 5) =1 while r ectpul s( 0. 5) =0.

y = r ect pul s( t , w) generates a rectangle of width w.

r ectpul s is typically used in conjunction with the pulse train generating

function pul str an.

See Also chi rp Generate a swept-frequency cosine.

cos Compute the cosine of vector/matrix elements (seethe MATL AB documentation).

di r i c Compute the Dirichlet or periodic sinc function.

gauspul s Generate a Gaussian-modulated sinusoidal pulse.

pul str an Generate a pulse train.sawt oot h Generate a sawtooth or triangle wave.

i C t th i f t / t i l t ( th

Page 628: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 628/870

7-347

si n Compute the sine of vector/matrix elements (see theMAT L AB documentation).

s i nc Compute the sinc or sin(πt)/πt function.

square Generate a square wave.

t r i pul s Generate a sampled aperiodic triangle.

remez

7remezPurpose Compute the Parks-McClellan optimal FI R filter design.

Syntax b = remez(n, f , a)

b = remez(n, f , a, w)

b = remez(n, f , a, ' f t ype' )

b = remez(n, f , a, w, ' f type' )b = remez( . . . , l gr i d)

b = remez(n, f , ' f r esp' , w)

b = remez(n, f , ' f r esp' , w, ' f type' )

b = remez(n, f , ' f r esp' , p1, p2, . . . , w)

b = remez(n, f , ' f r esp' , p1, p2, . . . , w, ' f t ype' )

[ b, del t a] = r emez( . . . )

[b, del t a, opt ] = remez( . . . )

Description r emez designs a linear-phaseFI R filter using the Parks-McClellanalgorithm [1]. The Parks-McClellan algorithm uses the Remez exchangealgorithm and Chebyshev approximation theory to design filters with anoptimal fit between the desired and actual frequency responses. Thefil ters areoptimal in the sense that the maximum error between the desired frequencyresponseand the actual frequency responseis minimized. Filters designed this

way exhibit an equiripple behavior in their frequency responses and aresometimes called equiripple filters.

t t t i i th ffi i t f th

Page 629: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 629/870

7-348

b = remez(n, f , a) returns row vector b containing the n+1 coefficients of theorder n FI R filter whose frequency-amplitude characteri stics match thosegiven by vectors f and a.

The output fi lter coefficients (taps) in b obey the symmetry relation

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

remez

Vectors f and a specify the frequency-magnitude characteristics of the fil ter:

• f is a vector of pairs of normalized frequency points, specified in the rangebetween 0 and 1, where 1 corresponds to the Nyquist frequency. Thefrequencies must be in increasing order.

•a is a vector containing the desired amplitudes at the points specified in f . The desired amplitudeat frequencies between pairs of points (f (k), f (k+1)) fork odd is the line segment connecting the points (f (k), a(k)) and(f (k+1), a(k+1)).

The desired amplitudeat frequencies between pairs of points (f (k), f (k+1)) fork even is unspecified. The areas between such points are transition or “don’tcare” regions.

f and a must bethe same length. The length must be an even number. The relationship between the f and a vectors in defining a desired frequencyresponse is shown in the example below.

1.0

Desired amplitude

response (a)

f = [ 0 . 3 . 4 . 6 . 7 . 9]

a = [ 0 1 0 0 . 5 . 5]

Page 630: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 630/870

7-349

r emez always uses an even filter order for configurations with a passband at

the Nyquist frequency. This is because for odd orders, the frequency responseat theNyquist frequency is necessarily 0. I f you specify an odd-valued n, r emez

increments it by 1.

0.0

Normalized

frequency (f )

0.5

"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

r emez( n, f , a, w) uses theweights in vector wtoweight thefit in each frequencyband. The length of wis half the length of f and a, sothere is exactly oneweight

per band.

b = remez(n, f , a, ' f t ype' ) and

b = remez(n, f , a, w, ' f type' ) specify a filter type, where ' f t ype' is

• ' hi l ber t ' , for linear-phase filters with odd symmetry (type I I I and typeI V)

The output coefficients in b obey the relation b(k) =-b(n+2-k), k = 1, ...,n +1. This class of filters includes the Hi lbert transformer, which has a

desired amplitude of 1 across the entire band.

For example,

h = remez(30, [ 0. 1 0. 9] , [ 1 1] , ' hi l ber t ' ) ;

designs an approximate FI R Hilbert transformer of length 31.

• ' di f f erent i ator ' , for type I I I and type I V fil ters, using a special weighting

technique

For nonzero amplitude bands, it weights the error by a factor of 1/f sothatthe error at low frequencies is much smaller than at high frequencies. For

FI R differentiators, which have an amplitude characteristic proportional tofrequency, thesefilters minimizethemaximum relativeerror (themaximumof the ratio of the error to the desired amplitude).

Page 631: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 631/870

7-350

b = remez( . . . , l gr i d) uses the integer l gr i d to control the density of thefrequency grid, which has roughly ( l gr i d*n) / ( 2*bw) frequency points, wherebwis the fraction of the total frequency band interval [0,1] covered by f .I ncreasing l gr i d often results in filters that more exactly match an equiripple

filter, but that take longer to compute. The default value of 16 is theminimumvaluethat should bespecified for l gr i d. Notethat thel gr i d argument mustbe a 1-by-1 cell array.

b = remez(n, f , ' f r esp' , w) returns row vector b containing the n+1

coefficients of the order n FI R filter whosefrequency-amplitude characteristicsbest approximate the response specified by function f resp. The function is

called from within r emez with the following syntax.

[ dh, dw] = f resp( n, f , gf , w)

remez

The arguments are similar to those for r emez:

• n is the filter order.

• f is the vector of normalized frequency band edges that appear monotonicallybetween 0 and 1, where 1 is the Nyquist frequency.

• gf is a vector of grid points that have been li nearly interpolated over eachspecified frequency band by r emez . gf determines the frequency grid at

which the responsefunction must beevaluated, and contains the same datareturned by cr emez in the f gr i d field of theopt structure.

• wis a vector of real, positiveweights, oneper band, used duringoptimization.wis optional in the call to r emez; if not specified, it is set to unity weightingbefore being passed to f r esp.

dh and dware the desired complex frequency response and band weightvectors, respectively, evaluated at each frequency in grid gf .

Thepredefined frequency responsefunction f resp that r emez calls is r emezf r f

in the s i gnal / pr i vate directory.

b = remez(n, f , ' f resp' , p1, p2, . . . , w) allows you to specify additionalparameters (p1, p2, etc.) to pass to f r esp. Note that b = remez(n, f , a, w) is asynonym for b = r emez(n, f , ' remezf rf ' , a, w) , where a is a vector

containing the desired amplitudes at the points specified in f .

b = remez(n, f , ' f resp' , w, ' f type' ) and

Page 632: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 632/870

7-351

b = remez(n, f , ' f resp' , p1, p2, . . . , w, ' f t ype' ) design antisymmetric(odd) rather than symmetric (even) fil ters, where ' f t ype' is either ' d' for adifferentiator or ' h' for a Hilbert transformer.

I n the absence of a specification for f t ype, a preliminary call is made to f respto determine the default symmetry property sym. This call is made using thesyntax.

sym= f resp( ' def aul t s ' , n, f , [ ] , w, p1, p2, . . . )

The arguments n, f , w, etc., may be used as necessary in determining anappropriate value for sym, which r emez expects to beeither ' even' or ' odd' . I f the f resp function does not support this calling syntax, r emez defaults to even

symmetry.

remez

[ b, del t a] = r emez( . . . ) returns the maximum ripple height in del t a.

[b, del t a, opt ] = remez( . . . ) returns a structure with the following fields.

Example Graph the desired and actual frequency responses of a 17th-orderParks-McClellan bandpass filter.

f = [ 0 0. 3 0. 4 0. 6 0. 7 1] ; a = [ 0 0 1 1 0 0] ;

b = remez(17, f , a) ;

[ h, w] = f reqz(b, 1, 512) ;pl ot ( f , a, w/ pi , abs(h) )

l egend( ' I deal ' , ' r emez Desi gn' )

opt . f gr i d Frequency grid vector used for the filter design optimization

opt . des Desired frequency response for each point in opt . f gr i d

opt . wt Weighting for each point in opt . f gr i d

opt . H Actual frequency response for each point in opt . f gr i d

opt . er r or Error at each point in opt . f gr i d (opt . des- opt . H)

opt . i extr Vector of indices into opt . f gr i d for extremal frequencies

opt . f ext r Vector of extremal frequencies

Page 633: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 633/870

7-352

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.4Idealremez Design

remez

Algorithm r emez is a MEX-file version of the original Fortran code from [1], altered to

design arbitrarily long filters with arbitrarily many linear bands.

r emez designs type I , II , II I , and I V linear-phase filters. Type I and type II arethe defaults for n even and n odd, respectively, while type I I I (n even) andtype I V (n odd) are obtained with the ' hi l ber t ' and ' di f f erent i ator ' flags. Thedifferent types of filters havedifferent symmetries and certain constraintson their frequency responses (see [5] for more details).

Remarks I f you get the following warning message,

- – Fai l ur e t o Conver ge - –

Probabl e cause i s machi ne r oundi ng er r or .

it is possible that the filter design may still be correct. Verify the design by

checking its frequency response

Linear Phase

Filter Type

Filter

Order

Symmetry of Coefficients Response H(f),

f = 0

Response H(f),

f = 1 (Nyquist)

TypeI Even even: No restriction No restriction

TypeI I Odd No restriction H(1) = 0

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

Type I V Odd H(0) = 0 No restriction

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

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

Page 634: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 634/870

7-353

checking its frequency response.

remez

See Also but t er Design a Butterworth analog and digital filter .

cheby1 Design a Chebyshev type I filter (passband ripple).

cheby2 Design a Chebyshev type I I filter (stopband ripple).

cr emez Design a complex and nonlinear-phase equiripple

FIR filter.el l i p Design an elliptic (Cauer) filter.

f i r 1 Design a window-based finite impulseresponsefilter:

standard response.

f i r 2 Design a window-based finite impulseresponsefilter:arbitrary response.

f i r c l s Design a constrained least square FI R filter for

multiband filters.f i r c l s 1 Design a constrained least square filter for lowpass

and highpass linear phase FI R filters.

f i r l s Design a least square linear-phase FI R filter.

f i r r c os Design a raised cosine FI R filter.

gr emez Design a generalized Remez optimal FI R filter design(see the Filter Design Toolbox documentation).

r emezor d Estimate the Parks-McClellan optimal F I R filterorder.

yul ewal k Design a recursive digital filter.

Page 635: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 635/870

7-354

References [1] Programs for Digital Signal Processing, I EE E Press, New York, 1979,

Algorithm 5.1.

[2] Selected Papers in Di gital Signal Processing, I I , IE EE Press, New York,1979.

[3] Parks, T.W., and C.S. Burrus, Digital Filter Design, J ohn Wiley & Sons,

New York:, 1987, p. 83.

[4] Rabiner, L .R., J .H. McClellan, and T.W. Parks, “F I R Digital F ilter Design Techniques Using Weighted Chebyshev Approximations,” Proc. IE EE 63(1975).

yul ewal k Design a recursive digital filter.

remez

[5] Oppenheim, A.V., and R.W. Schafer, Discrete-TimeSi gnal Processing,Prentice-Hall, Englewood Cli ffs, NJ , 1989, pp. 256-266.

Page 636: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 636/870

7-355

remezord

7remezordPurpose Parks-McClell an optimal FI R filter order estimation.

Syntax [ n, f o, ao, w] = r emezord(f , a, dev)

[ n, f o, ao, w] = remezord( f , a, dev, f s)

c = remezord( f , a, dev, f s , ' cel l ' )

Description [ n, f o, ao, w] = r emezord(f , a, dev) finds the approximate order, normalizedfrequency band edges, frequency band amplitudes, and weights that meetinput specifications f , a, and dev.

• f is a vector of frequency band edges (between 0 and f s/2, where f s is thesampling frequency), and a is a vector specifying the desired amplitude onthe bands defined by f . The length of f is two less than twice thel ength of a.

The desired function is piecewise constant.• dev is a vector the same size as a that specifies the maximum allowable

deviation or ripples between the frequency response and the desiredamplitude of the output filter for each band.

User emez with theresulting order n, frequency vector f o, amplituderesponsevector ao, and weights wto design the filter b which approximately meets thespecifications given by r emezor d input parameters f , a, and dev.

b = r emez(n, f o, ao, w)

[ n, f o, ao, w] = remezord( f , a, dev, f s) specifies a sampling frequency f s.f s defaults to 2 Hz implying a Nyquist frequency of 1 Hz You can therefore

Page 637: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 637/870

7-356

f s defaults to 2 Hz, implying a Nyquist frequency of 1 Hz. You can thereforespecify band edges scaled to a particular application’s sampling frequency.

I n some cases r emezor d underestimates the order n. I f thefilter does not meetthe specifications, try a higher order such as n+1 or n+2.

c = remezord( f , a, dev, f s , ' cel l ' ) generates a cell-array whose elementsare the parameters to r emez.

Examples Example 1

Design a minimum-order lowpass filter with a 500 Hz passband cutoff frequency and 600 Hz stopband cutoff frequency, with a sampling frequency of 2000 Hz, at least 40 dB attenuation in the stopband, and less than 3 dB of

ripple in the passband.

remezord

rp = 3; % Passband r i ppl e

rs = 40; % St opband r i ppl e

f s = 2000; % Sampl i ng f r equency

f = [ 500 600] ; % Cut of f f r equenci es

a = [ 1 0] ; % Desi r ed ampl i t udes

% Comput e devi at i onsdev = [ ( 10 ( r p/ 20) - 1) / ( 10 ( r p/ 20) +1) 10 ( - r s/ 20) ] ;

[ n, f o, ao, w] = remezord( f , a, dev, f s) ;

b = remez( n, f o, ao, w) ;

f r eqz(b, 1, 1024, f s) ;

t i t l e( ' Lowpass Fi l t er Desi gned t o Speci f i cat i ons' ) ;

−400

−200

0

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 638: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 638/870

7-357

Note that thefilter falls slightly short of meeting thestopband attenuation and

passband ripple specifications. Using n+1 in the call to r emez instead of nachieves the desired amplitude characteristics.

Example 2

Design a lowpass filter with a 1500 Hz passband cutoff frequency and 2000 Hz

stopband cutoff frequency, with a sampling frequency of 8000 Hz, a maximumstopband amplitude of 0.1, and a maximum passband error (ripple) of 0.01.

0 100 200 300 400 500 600 700 800 900 1000−1200

−1000

−800

−600

Frequency (Hz)

P h a s e ( d e g

remezord

[ n, f o, ao, w] = r emezor d( [ 1500 2000] , [ 1 0] , [ 0. 01 0. 1] , 8000 );

b = r emez(n, f o, ao, w) ;

This is equivalent to

c = r emezor d( [ 1500 2000] , [ 1 0] , [ 0. 01 0. 1] , 8000, ' cel l ' ) ;

b = r emez(c: ) ;

Note I n some cases, r emezor d underestimates or overestimates the order n. I f the fil ter does not meet the specifications, try a higher order such as n+1

or n+2.

Results are inaccurate if the cutoff frequencies are near 0 or the Nyquistfrequency.

Algorithm r emezor d uses the algorithm suggested in [1]. This method is inaccurate for

band edges close to either 0 or the Nyquist frequency (f s / 2).

See Also but t or d Butterworth filter order selection.

cheb1ord Chebyshev type I filter order selection.

cheb2ord Chebyshev type I I filter order selection.

el l i pord Elliptic filter order selection.

kai ser or d Estimate parameters for an FI R filter design with

Page 639: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 639/870

7-358

References [1] Rabiner, L .R., and O. Herrmann, “The Predictabili ty of Certain OptimumFinite I mpulse Response Digital Filters,”I EE E Trans. on Circuit Theory,Vol. CT-20, No. 4 (J uly 1973), pp. 401-408.

[2] Rabiner, L .R., and B. Gold. Theory and Application of Digital Signal

Processing. Englewood Cliffs, NJ : Prentice-Hall, 1975, pp. 156-157.

p gK aiser window.

r emez Parks-McClellan optimal FIR filter design.

resample

7resamplePurpose Change sampling rate by any rational factor.

Syntax y = r esampl e( x, p, q)

y = r esampl e( x, p, q, n)

y = r esampl e( x, p, q, n, bet a)

y = r esampl e( x, p, q, b)[ y, b] = resampl e( x, p, q)

Description y = r esampl e( x, p, q) resamples the sequence in vector x at p/ q times the

original sampling rate, using a polyphase filter implementation. p and q mustbe positive integers. The length of y is equal to cei l ( l engt h( x) *p/ q) . I f x is amatrix, r esampl e works down the columns of x.

r esampl e applies an anti-aliasing (lowpass) FI R filter to x during theresampling process. I t designs the filter using f i r l s with a K aiser window.

y = r esampl e( x, p, q, n) uses n terms on either side of the current sample,x( k) , to perform the resampling. The length of the FI R filter r esampl e uses isproportional to n; larger values of n provide better accuracy at the expense of more computation time. The default for n is 10. If you let n =0, r esampl e

performs a nearest-neighbor interpolation

y( k) = x( r ound( ( k- 1) *q/ p) +1)

where y( k) =0 if the index tox is greater than l engt h( x) .

y r esampl e( x p q n bet a) uses beta as the design parameter for the

Page 640: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 640/870

7-359

y = r esampl e( x, p, q, n, bet a) uses beta as the design parameter for theK aiser window that r esampl e employs in designing the lowpass filter. Thedefault for beta is 5.

y = r esampl e( x, p, q, b) filters x using the vector of fil ter coefficients b.

[ y, b] = resampl e( x, p, q) returns the vector b, which contains thecoefficients of the filter applied to x during the resampling process.

resample

Examples Resample a simple linear sequence at 3/2 the original rate.

f s1 = 10; % Or i gi nal sampl i ng f requency i n Hz

t 1 = 0: 1/ f s1: 1; % Ti me vect or

x = t 1; % Def i ne a l i near sequence

y = r esampl e( x, 3, 2) ; % Now r esampl e i t

t 2 = ( 0: ( l engt h( y) - 1) ) *2/ ( 3*f s1) ; % New t i me vector

pl ot ( t 1, x, ' * ' , t 2, y, ' o' , - 0. 5: 0. 01: 1. 5, - 0. 5: 0. 01: 1. 5, ' : ' )

l egend( ' or i gi nal ' , ' resampl ed' ) ; xl abel ( ' Ti me' )

−0.5 0 0.5 1 1.5−0.5

0

0.5

1

1.5

Time

originalresampled

Page 641: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 641/870

7-360

Notice that the last few points of the output y are inaccurate. I n its filteringprocess, r esampl e assumes the samples at times before and after the givensamples in x are equal to zero. Thus large deviations from zero at the end

points of the sequence x can causeinaccuracies in y at its end points. Thefollowing two plots il lustrate this side effect of r esampl e.

x = [ 1: 10 9: - 1: 1] ; y = resampl e( x, 3, 2) ;

subpl ot ( 2, 1, 1) ;

pl ot ( 1: 19, x, ' * ' , ( 0: 28) *2/ 3 + 1, y, ' o' ) ;

t i t l e( ' Edge Ef f ects Not Not i ceabl e' ) ;

l egend( ' or i gi nal ' , ' resampl ed' ) ;

Time

resample

x = [10: - 1: 1 2: 10] ; y = resampl e(x , 3, 2) ;

subpl ot ( 2, 1, 2) ;

pl ot ( 1: 19, x, ' * ' , ( 0: 28) *2/ 3 + 1, y, ' o' )

t i t l e( ' Edge Ef f ects Ver y Not i ceabl e' ) ;

l egend( ' or i gi nal ' , ' r esampl ed' ) ;

See Also

0 5 10 15 200

2

4

6

8

10Edge Effects Not Noticeable

originalresampled

0 5 10 15 200

5

10

15Edge Effects Very Noticeable

originalresampled

deci mate Decrease the sampling rate for a sequence(decimation).

f i r l s L east square linear-phase F I R filter design

Page 642: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 642/870

7-361

f i r l s L east square linear phase F I R filter design.

i nterp I ncrease sampling rate by an integer factor(interpolation).

i nt er p1 One-dimensional data interpolation (table lookup)(see the MATLAB documentation).

i nt f i l t Interpolation FIR filter design.

kai ser K aiser window.

spl i ne Cubic spline interpolation (see the MATL ABdocumentation).

upf i r dn Upsample, apply an F I R filter, and downsample.

residuez

7residuezPurpose z-transform partial-fraction expansion.

Syntax [ r , p, k] = r esi duez(b, a)

[b, a] = r esi duez( r , p, k)

Description r esi duez converts a discrete time system, expressed as the ratio of twopolynomials, topartial fraction expansion, or residue, form. I t also converts thepartial fraction expansion back to the ori ginal polynomial coefficients.

[ r , p, k] = r esi duez(b, a) finds the residues, poles, and direct terms of apartial fraction expansion of the ratio of two polynomials, b(z) and a(z).Vectors b and a specify the coefficients of the polynomials of the discrete-timesystem b(z)/ a(z) in descending powers of z.

I f there are no multiple roots and a >n- 1,

The returned column vector r contains the residues, column vector p containsthe pole locations, and row vector k contains the direct terms. The number of poles is

n l engt h( a) 1 l engt h( r ) l engt h( p)

b z( ) b0 b1z 1– b2z 2–L bmz m–+ + + +=

a z( ) a0 a1z 1– a2z 2–L anz 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 643: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 643/870

7-362

n = l engt h( a) - 1 = l engt h( r ) = l engt h( p)

The direct term coefficient vector k is empty if l engt h( b) is less thanl engt h( a) ; otherwise

l engt h( k) = l engt h( b) - l engt h( a) + 1

I f p( j ) = . . . = p( j +s- 1) is a pole of multiplicity s, then the expansionincludes terms of the form

r j( )

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

r j 1+( )

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

r j sr 1–+( )

1 p j( )z 1––( )sr

------------------------------------+ + +

residuez

[ b, a] = r esi duez ( r , p, k) with three input arguments and two outputarguments, converts the partial fraction expansion back to polynomials with

coefficients in row vectors b and a.

The r esi due function in the standard MATL AB language is very similar tor esi duez. I t computes the partial fraction expansion of continuous-time

systems in the L aplace domain (see reference [1]), rather than discrete-timesystems in the z-domain as does r esi duez.

Algorithm r esi duez applies standard MATL AB functions and partial fraction techniquesto find r , p, and k from b and a. I t finds:

1 The direct terms a using deconv (polynomial long division) whenl engt h( b) >l engt h( a) - 1.

2 The poles using p =roots(a) .

3 Any repeated poles, reordering the poles according to their multiplicities.

4 The residue for each nonrepeating pole pi by multiplying b(z)/a(z) by1/(1 - piz

-1) and evaluating the resulting rational function at z =pi.

5 The residues for the repeated poles by solving

S2*r2 = h - S1* r1

for r 2 using \ . h is the impulse response of the reduced b(z)/ a(z), S1 is amatrix whose columns are impulse responses of the first-order systemsmade up of the nonrepeating roots, and r 1 is a column containing the

residues for thenonrepeating roots. Each column of matrix S2 is an impulseresponse For each root pj of multiplicity sj S2 contains sj columns

Page 644: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 644/870

7-363

response. For each root p j of multiplicity s j, S2 contains s j columnsrepresenting the impulse responses of each of the following systems.

The vector h and matrices S1 and S2 have n+xt ra rows, where n is thetotalnumber of roots and the internal parameter xt ra, set to 1 by default,determines the degree of overdetermination of the system of equations.

1

1 pjz 1––-----------------------

1

1pj z 1––

( )

2------------------------------- L

1

1 pjz1–

–( )

s j

--------------------------------, , ,

residuez

See Also

References [1] Oppenheim, A.V., and R.W. Schafer, Digital Signal Processing,Prentice-Hall, Englewood Cliffs, NJ , 1975, pp. 166-170.

convmt x Convolution matrix.

deconv Deconvolution and polynomial division (see theMATL AB documentation).

pol y Polynomial with specified roots (see the MATL AB

documentation).

prony Prony’s method for time domain I I R fi lter design.

r esi due Partial fraction expansion (see the MATL ABdocumentation).

roots Polynomial roots (see the MATL AB documentation).

ss2tf Convert state-space filter parameters tozero-pole-gain form.

t f 2ss Convert transfer function filter parameters tostate-space form.

t f 2zp Convert transfer function filter parameters tozero-pole-gain form.

zp2ss Convert zero-pole-gain filter parameters tostate-space form.

Page 645: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 645/870

7-364

rlevinson

7rlevinsonPurpose Compute the reverse L evinson-Durbin recursion.

Syntax r = r l evi nson(a, ef i nal )

[ r , u] = r l evi nson(a, ef i nal )

[ r , u, k] = r l evi nson(a, ef i nal )

[ r , u, k, e] = r l evi nson(a, ef i nal )

Description The reverse Levinson-Durbin recursion implements the step-down algorithmfor solving the following symmetric Toeplitz system of linear equations for r,where r =[ r(1) L r(p+1)] and r(i)* denotes the complex conjugate of r(i).

r = r l evi nson(a, ef i nal ) solves the above system of equations for r givenvector a, where a = [1 a(2) L a(p+1)]. I n l inear prediction applications, r

represents the autocorrelation sequence of the input to the prediction errorfilter, where r (1) is the zero-lag element. The figure below shows the typicalfilter of this type, where H(z) is the optimal linear predictor, x(n) is the input

signal, is the predicted signal, and e(n) is the prediction error.

r 1( ) r 2( )∗

L r p( )∗

r 2( ) r 1( )L

r p 1–( )∗

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

a 2( )

a 3( )

a p 1+( )

r 2( )–

r 3( )–

r p 1+( )–

=

x n( )

Prediction Error

Page 646: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 646/870

7-365

I nput vector a represents the polynomial coefficients of this prediction err orfilter in descending powers of z.

H z( ) a– 2( )z1–

a– 3( )z2–L– a– n 1+( )z

p–= Σ

x n( )x n( )

–+

e n( )

A z( )

A z( ) 1 a 2( )z 1–L a n 1+( )z p–+ + +=

rlevinson

The filter must be minimum phase to generate a valid autocorrelationsequence. ef i nal is the scalar prediction error power, which is equal to thevariance of the prediction error signal, σ2(e).

[ r , u] = r l evi nson(a, ef i nal ) returns upper triangular matrix U from theUDU * decomposition

where

and E is a diagonal matrix with elements returned in output e (seebelow). Thisdecomposition permits the efficient evaluation of the inverse of theautocorrelation matrix, R-1.

Output matrix u contains the prediction filter polynomial, a, from each

iteration of the reverse L evinson-Durbin recursion

R1–

U E1–

U∗

=

R

r 1( ) r 2( )∗

L r p( )∗

r 2( ) r 1( ) L r p 1–( )∗

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

=

a1 1( )∗

a2 2( )∗

L ap 1+p 1+( )

0 a2 1( )∗

ap 1+p( )

Page 647: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 647/870

7-366

whereai( j)isthe jth coefficient of the ith order prediction filter polynomial (i.e.,step i in the recursion). F or example, the 5th order prediction filter polynomialis

a5 = u(5: - 1: 1, 5) '

Note that u( p+1: - 1: 1, p+1) ' is the input polynomial coefficient vector a.

U2( ) p 1+

p( )

0 0 ap 1+p 1–( )

0 L 0 ap 1+1( )

=

rlevinson

[ r , u, k] = r l evi nson(a, ef i nal ) returns a vector k of length (p+1) containingthe reflection coefficients. The reflection coefficients are the conjugates of the

values in the first row of u.

k = conj ( u(1, 2: end))

[ r , u, k, e] = r l evi nson(a, ef i nal ) returns a vector of length p+1 containingthe prediction errors from each i teration of the reverse L evinson-Durbinrecursion: e(1) is the prediction error from the first-order model, e( 2) is the

prediction error from the second-order model, and so on.

These prediction error values form the diagonal of the matrix E in the UDU*

decomposition of R-1.

.

See Also

References [1] K ay, S.M., Modern Spectral E stimation: Theory and Application,Prentice-Hall, Englewood Cli ffs, NJ , 1988.

R1–

U E1–

U∗

=

l evi nson Compute the L evinson-Durbin recursion.

l pc Compute linear prediction filter coefficients.

prony Prony’s method for time domain I I R filter design.

st mcb Compute a linear model using Steiglitz-McBrideiteration.

Page 648: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 648/870

7-367

rooteig

7rooteigPurpose Estimate frequency and power content using the eigenvector method.

Syntax [ w, pow] = root ei g( x, p)

[ f , pow] = r oot ei g( . . . , f s )

[w, pow] = r oot ei g( . . . , ' corr ' )

Description [ w, pow] = root ei g( x, p) estimates thefrequency content in thetimesamplesof a signal x, and returns w, a vector of frequencies in rad/sample, and thecorresponding signal power in the vector powin dB per rad/sample. The inputsignal x is specified either as:

• A row or column vector representing one observation of the signal

• A rectangular array for which each row of x represents a separate

observation of the signal (for example, each row is one output of an array of sensors, as in array processing), such that x' *x is an estimate of thecorrelation matrix

Note You can use the output of cor r mt x to generate such an array x.

You can specify the second input argument p as either:

• A scalar integer. I n this case, the signal subspace dimension is p.

• A two-element vector. I n this case, p(2) , the second element of p, representsa threshold that is multiplied by λmin, the smallest estimated eigenvalue of th i l’ l ti t i Ei l b l th th h ld λ ( )

Page 649: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 649/870

7-368

the signal’s correlation matrix. Eigenvalues below the threshold λmin*p(2)

areassigned to thenoise subspace. I n this case, p( 1) specifies the maximumdimension of the signal subspace.

The extra threshold parameter in the second entry in p provides you moreflexibility and control in assigning the noise and signal subspaces.

The length of the vector wis the computed dimension of the signal subspace.For real-valued input data x, the length of the corresponding power vector pow

is given by

l engt h( pow) = 0. 5*l engt h( w)

For complex-valued input data x, powand whave the same length.

rooteig

[ f , pow] = r oot ei g( . . . , f s ) returns the vector of frequencies f calculatedin H z. You supply the sampling frequency f s in H z. I f you specify f s with the

empty vector [ ] , the sampling frequency defaults to 1 Hz.

[w, pow] = r oot ei g( . . . , ' corr ' ) forces the input argument x to beinterpreted as a correlation matrix rather than a matrix of signal data. For this

syntax, you must supply a square matrix for x, and all of its eigenvalues mustbe nonnegative.

Note You can place the string ' corr ' anywhere after p.

Examples Find the frequency content in a signal composed of threecomplex exponentialsin noise. Use the modified covariance method to estimate the correlationmatrix used by the eigenvector method.

r andn( ' st at e' , 1) ; n=0: 99;

s = exp( i *pi / 2*n) +2*exp( i *pi / 4*n) +exp( i *pi / 3*n) +r andn( 1, 100) ;

% Est i mat e corr el ati on mat r i x usi ng modi f i ed covar i ance met hod.

X=corr mt x( s, 12, ' mod' ) ;

[ W, P] = r oot ei g( X, 3)

W =

0. 7811

1. 5767

Page 650: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 650/870

7-369

1. 0554

P =

3. 99711. 1362

1. 4102

Algorithm The eigenvector method used by r oot ei g is thesame as that used by pei g.Thealgorithm performs eigenspace analysis of the signal’s correlation matrix inorder to estimate the signal’s frequency content.

rooteig

The difference between pei g and r oot ei g is:

• pei g returns the pseudospectrum at all frequency samples.

• r oot ei g returns the estimated discrete frequency spectrum, along with thecorresponding signal power estimates.

r oot ei g is most useful for frequency estimation of signals made up of a sum of sinusoids embedded in additive white Gaussian noise.

See Also cor r mt x Calculate a data matrix for correlation estimation.

pei g Estimate the pseudospectrum using the eigenvectormethod.

pmusi c Estimate the pseudospectrum using the MUSI C

algorithm.

r oot musi c Estimate frequency and power content using the root

MUSIC algorithm.

Page 651: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 651/870

7-370

rootmusic

7rootmusicPurpose Estimate frequency and power content using the root MUSI C algorithm.

Syntax [ w, pow] = r oot musi c(x, p)

[ f , pow] = rootmusi c( . . . , f s)

[w, pow] = rootmus i c( . . . , ' corr ' )

Description [ w, pow] = r oot musi c(x, p) estimates the frequency content in the timesamples of a signal x, and returns w, a vector of frequencies in rad/sample, andthe corresponding signal power in the vector powin dB per rad/sample. Theinput signal x is specified either as:

• A row or column vector representing one observation of the signal

• A rectangular array for which each row of x represents a separate

observation of the signal (for example, each row is one output of an array of sensors, as in array processing), such that x' *x is an estimate of thecorrelation matrix

Note You can use the output of corr mt x to generate such an array x.

You can specify the second input argument p as either:

• A scalar integer. I n this case, the signal subspace dimension is p.

• A two-element vector. I n this case, p( 2) , the second element of p, representsa threshold that is multiplied by λmin, the smallest estimated eigenvalue of the signal’s correlation matrix Eigenvalues below the threshold λmin*p(2)

Page 652: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 652/870

7-371

the signal s correlation matrix. Eigenvalues below the threshold λmin p(2)

areassigned to thenoisesubspace. I n this case, p(1) specifies the maximumdimension of the signal subspace.

The extra threshold parameter in the second entry in p provides you moreflexibil ity and control in assigning the noise and signal subspaces.

The length of the vector wis the computed dimension of the signal subspace.For real-valued input data x, the length of the corresponding power vector pow

is given by

l engt h( pow) = 0. 5*l engt h( w)

For complex-valued input data x, powand whave the same length.

rootmusic

[ f , pow] = rootmus i c( . . . , f s ) returns the vector of frequencies f calculatedin H z. Y ou supply the sampling frequency f s in H z. I f you specify f s with theempty vector [ ] , the sampling frequency defaults to 1 Hz.

[ w, pow] = root mus i c( . . . , ' corr ' ) forces the input argument x to beinterpreted as a correlation matrix rather than a matrix of signal data. For this

syntax, you must supply a square matrix for x, and all of its eigenvalues mustbe nonnegative.

Note You can place the string ' corr ' anywhere after p.

Examples Find the frequency content in a signal composed of threecomplex exponentialsin noise. Use the modified covariance method to estimate the correlationmatrix used by the MU SI C algorithm.

r andn( ' st at e' , 1) ; n=0: 99;

s = exp( i *pi / 2*n) +2*exp( i *pi / 4*n) +exp( i *pi / 3*n) +r andn( 1, 100) ;

% Est i mate cor r el at i on matr i x usi ng modi f i ed covari ance method.

X=cor r mt x( s, 12, ' mod' ) ;

[ W, P] = r oot musi c( X, 3)

W =

1. 5769

0. 7817

1. 0561

Page 653: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 653/870

7-372

P =

1. 1358

3. 9975

1. 4102

Algorithm The MU SI C algorithm used by r oot musi c is thesame as that used by pmusi c. The algorithm performs eigenspace analysis of the signal’s correlation matrixin order to estimate the signal’s frequency content.

rootmusic

The difference between pmusi c and r oot musi c is:

• pmusi c returns the pseudospectrum at all frequency samples.

• r oot musi c returns the estimated discrete frequency spectrum, along withthe corresponding signal power estimates.

r oot musi c is most useful for frequency estimation of signals made up of a sumof sinusoids embedded in additive white Gaussian noise.

See Also cor r mt x Calculate a data matrix for correlation estimation.

pei g Estimate the pseudospectrum using the eigenvectormethod.

pmusi c Estimate the pseudospectrum using the MUSI C

algorithm.

root ei g Estimate frequency and power content using the root

eigenvector method.

Page 654: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 654/870

7-373

sawtooth

7sawtoothPurpose Generate a sawtooth or triangle wave.

Syntax x = sawtooth( t )

x = sawt oot h( t , wi dt h)

Description sawt ooth( t ) generates a sawtooth wave with period 2π for the elements of time vector t . sawt oot h( t ) is similar to si n( t ) , but creates a sawtooth wavewith peaks of -1 and 1 instead of a sine wave. The sawtooth wave is defined tobe -1 at multiples of 2π and toincrease linearly with time with a slope of 1/π atall other times.

sawt oot h( t , wi dt h) generates a modified tri angle wavewhere wi dt h, a scalarparameter between 0 and 1, determines the point between 0 and 2π at which

the maximum occurs. The function increases from -1 to 1 on the interval 0 to2π*wi dt h, then decreases linearly from 1 to -1 on the interval 2π*wi dt h to 2π. Thus a parameter of 0.5 specifies a standard triangle wave, symmetric abouttimeinstant π with peak-to-peak amplitude of 1. sawt oot h( t , 1) is equivalentto sawt ooth( t ) .

See Also chi rp Generate a swept-frequency cosine.

cos Compute the cosine of vector/matrix elements (see the

MATL AB documentation).

di r i c Compute the Dirichlet or periodic sinc function.

gauspul s Generate a Gaussian-modulated sinusoidal pulse.

pul st r an Generate a pulse train.

Page 655: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 655/870

7-374

r ect pul s Generate a sampled aperi odic rectangle.

si n Compute the sine of vector/matrix elements (see theMATL AB documentation).

s i nc Compute the sinc or sin(πt)/πt function.

square Generate a square wave.

t r i pul s Generate a sampled aperiodic triangle.

schurrc

7schurrcPurpose Compute reflection coefficients from an autocorrelation sequence.

Syntax k = schur r c( r )

[ k, e] = schur r c( r )

Descriptionk = s chur r c ( r )

uses the Schur algorithm to compute a vectork

of reflectioncoefficients from a vector r representing an autocorrelation sequence. k and r

are the same size. The reflection coefficients represent the lattice parametersof a prediction filter for a signal with the given autocorrelation sequence, r .When r is a matrix, schurrc treats each column of r as an independentautocorrelation sequence, and produces a matrix k, the same size as r . Eachcolumn of k represents the reflection coefficients for the lattice filter for

predicting the process with the corresponding autocorrelation sequence r .

[ k, e] = schur r c( r ) alsocomputesthe scalar e, the prediction error variance.When r is a matrix, e is a row vector. The length of e is thesame as thenumberof columns of r .

Examples Createan autocorrelation sequencefromtheMAT L AB speech signal containedin mt l b. mat , andusethe Schur algorithm to computethe reflection coefficientsof a latti ce prediction filter for this autocorrelation sequence.

l oad mt l br = xcor r ( mt l b( 1: 5) , ' unbi ased' ) ;

k = schur r c( r ( 5: end) )

k =

- 0. 7583

Page 656: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 656/870

7-375

0. 1384

0. 7042

- 0. 3699

See Also l evi nson Compute a prediction filter using the L evinsonalgorithm.

References [1] Proakis, J . and D. Manolakis, Digital Si gnal P rocessing: Pri nciples,

Algori thms, and Applications, Third edition, Prentice-Hall, 1996, pp. 868-873.

seqperiod

7seqperiodPurpose Compute the period of a sequence.

Syntax p = seqper i od( x)

[ p, num] = seqper i od( x)

Description p = seqper i od( x) returns the integer p that corresponds to the period of the

sequence in a vector x. The period p is computed as the minimum length of asubsequencex( 1: p) of x that repeats itself continuously every p samples in x. The length of x does not have to be a multiple of p, so that an incompleterepetition is permitted at the end of x. I f the sequence x is not periodic, thenp =l engt h( x) .

• I f x is a matrix, then seqper i odchecks for periodicity along each column of x. The resulting output p is a row vector with thesame number of columns asx.

• I f x is a multidimensional array, then seqperi od checks for periodicity along

the first nonsingleton dimension of x. I n this case:

- p is a multidimensional array of integers with a leading singleton

dimension.

- The lengths of the remaining dimensions of p correspond to those of thedimensions of x after the first nonsingleton one.

[ p, num] = seqper i od( x) alsoreturns thenumber numof repetiti ons of x(1: p)

in x. nummight not be an integer.

Examples x = [4 0 1 6;

2 0 2 7;

4 0 1 5;

Page 657: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 657/870

7-376

4 0 1 5;

2 0 5 6] ;

p = seqper i od( x)

p =

2 1 4 3

seqperiod

The result implies:

• The first column of x has period 2.

• The second column of x has period 1.

• The third column of x is not periodic, sop( 3) is just the number of rows of x.

The fourth column of x has period 3, although the last (second) repetition of the periodic sequence is incomplete.

Page 658: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 658/870

7-377

sgolay

7sgolayPurpose Savitzky-Golay filter design.

Syntax b = sgol ay( k, f )

b = sgol ay(k , f , w)

Description b = sgol ay( k, f ) designs a Savitzky-Golay FI R smoothing filter b. The

polynomial order k must be less than the frame size, f , which must be odd. I f k =f - 1, the designed filter produces no smoothing. The output, b, i s a n f -by-f matrix whose rows represent the time-varying FI R filter coefficients. I n asmoothing filter implementation (for example, sgol ayf i l t ), the last ( f - 1) / 2

rows (each an FI R filter) are applied tothe signal during thestartup transient,and the first ( f - 1) / 2 rows are applied to the signal during the terminal

transient. The center row is applied to the signal in the steady state.

b = sgol ay(k , f , w) specifies a weighting vector wwith length f , whichcontains the real, positive-valued weights to beused during the least-squaresminimization.

Remarks Savitzky-Golay smoothing filters (also called digital smoothing polynomialfilters or least squares smoothing filters) are typically used to “smooth out” anoisy signal whose frequency span (without noise) is large. I n this type of

application, Savitzky-Golay smoothing filters perform much better thanstandard averaging F I R filters, which tend to filter out a significant portion of the signal’s high frequency content along with the noise. AlthoughSavitzky-Golay filters are more effective at preserving the pertinent highfrequency components of the signal, they are less successful than standardaveraging F I R filters at rejecting noise.

Page 659: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 659/870

7-378

Savitzky-Golay filters are optimal in the sense that they minimize theleast-squares error in fitting a polynomial to each frame of noisy data.

See Also f i r 1 Window-based finite impulse responsefilter design –standard response.

f i r l s L east square linear-phase F I R filter design.

f i l t er Filter data with a recursive (II R) or nonrecursive(FI R) filter.

sgol ayf i l t Savitzky-Golay filtering.

sgolay

References [1] Orfanidis, S.J ., I ntroduction toSignal Processing, Prentice-Hall, Englewood

Cliffs, NJ , 1996.

Page 660: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 660/870

7-379

sgolayfilt

7sgolayfiltPurpose Savitzky-Golay filtering.

Syntax y = sgol ayf i l t ( x, k, f )

y = sgol ayf i l t ( x, k, f , w)

Description y = sgol ayf i l t ( x, k, f ) applies a Savitzky-Golay FI R smoothing filter to the

data in vector x. I f x is a matrix, sgol ayf i l t operates on each column. Thepolynomial order k must be less than the frame size, f , which must be odd. I f k =f - 1, the filter produces no smoothing.

y = sgol ayf i l t ( x, k, f , w) specifies a weighting vector wwith length f , whichcontains the real, positive-valued weights to beused during the least-squaresminimization.

Remarks Savitzky-Golay smoothing filters (also called digital smoothing polynomialfilters or least-squares smoothing filters) are typically used to “smooth out” a

noisy signal whose frequency span (without noise) is large. I n this type of application, Savitzky-Golay smoothing filters perform much better thanstandard averaging F I R filters, which tend to filter out a significant portion of the signal’s high frequency content along with the noise. AlthoughSavitzky-Golay filters are more effective at preserving the pertinent high

frequency components of the signal, they are less successful than standardaveraging F I R filters at rejecting noise.

Savitzky-Golay filters are optimal in the sense that they minimize theleast-squares error in fitting a polynomial to frames of noisy data.

Example Smooth the mt l b signal by applying a cubic Savitzky-Golay filter to dataf f l th 41

Page 661: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 661/870

7-380

frames of length 41.

l oad mt l b % Load t he dat a.smt l b = sgol ayf i l t ( mt l b, 3, 41) ; % Appl y the 3rd- order f i l ter .

subpl ot ( 2, 1, 1)

pl ot ( [ 1: 2000] , mt l b( 1: 2000) ) ; axi s( [ 0 2000 - 4 4] ) ;

t i t l e( ' mt l b' ) ; gr i d;

subpl ot ( 2, 1, 2)

pl ot ( [ 1: 2000] , smt l b( 1: 2000) ) ; axi s( [ 0 2000 - 4 4] ) ;

t i t l e( ' smt l b' ) ; gr i d;

sgolayfilt

See Also

References [1] Orfanidis, S.J ., I ntroduction toSignal Processing, Prentice-Hall, Englewood

Cliffs, NJ , 1996.

0 500 1000 1500 2000−4

−2

0

2

4mtlb

0 500 1000 1500 2000−4

−2

0

2

4smtlb

medf i l t 1 One-dimensional median filtering.

f i l t er Filter data with a recursive (II R) or nonrecursive

(FI R) filter.

sgol ay Savitzky-Golay fil ter design.

sosf i l t Second-order (biquadratic) I I R digital filtering.

Page 662: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 662/870

7-381

sinc

7sincPurpose Sinc function.

Syntax y = si nc( x)

Description s i nc computes the sinc function of an input vector or array, where the sincfunction is

This function i s the continuous inverse Fourier transform of the rectangularpulse of width 2π and height 1.

y = si nc( x) returns an array y the same size as x, whose elements are thes i nc function of the elements of x.

The space of functions bandlimited in the frequency range isspanned by theinfinite (yet countable) set of sincfunctions shifted by integers. Thus any such bandlimited function g(t) can bereconstructed fromits samplesat integer spacings.

sinc t( )

1 t 0=,

πt( )sinπt

------------------- t 0≠,î

=

sinc t( )1

2π------ e j ωt ωd

π–

π

ò =

ω π – π [ , ]∈

g t( ) g n( )sinc t n–( )

=

Page 663: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 663/870

7-382

Example Perform ideal bandlimited interpolation by assuming that the signal to beinterpolated is 0 outsideof thegiven timeinterval and that it has been sampledat exactly the Nyquist frequency.

t = ( 1: 10) ' ; % A col umn vect or of t i me sampl es

randn( ' stat e' , 0) ;

x = r andn( si ze( t ) ) ; % A col umn vect or of dat a

n ∞–=

sinc

t s = l i nspace( - 5, 15, 600) ' ; %t i mes at whi ch to i nterpol ate data

y = si nc( t s( : , ones( s i ze( t ) ) ) - t ( : , ones( s i ze( t s) ) ) ' ) * x;

pl ot ( t , x, ' o' , t s , y)

See Also

−5 0 5 10 15−2

1.5

−1

0.5

0

0.5

1

1.5

2

chi rp Generate a swept-frequency cosine.

cos Compute the Cosine of vector/matrix elements (see

the MATL AB documentation).di r i c Compute the Dirichlet or periodic sinc function.

gauspul s Generate a Gaussian-modulated sinusoidal pulse.

pul str an Generate a pulse train.

r ectpul s Generate a sampled aperiodic rectangle.

sawt oot h Generate a sawtooth or triangle wave

Page 664: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 664/870

7-383

sawt oot h Generate a sawtooth or triangle wave.

si nCompute the sine of vector/matrix elements (see theMAT L AB documentation).

square Generate a square wave.

t r i pul s Generate a sampled aperiodic triangle.

sos2cell

7sos2cellPurpose Convert a second-order section matrix to cell arrays.

Syntax c = sos2cel l ( m)

c = sos2cel l ( m, g)

Description c = sos2cel l (m) changes an L -by-6 second-order section matrix mgeneratedby t f 2sos into a 1-by-L cell array of 1-by-2 cell arrays c. You can usec tospecify a quantized filter with L cascaded second-order sections.

The matrix mshould have the form

m = [ b1 a1; b2 a2; . . . ; bL aL]

where both bi and ai , with i =1, ..., L , are 1-by-3 row vectors. The resulting c

is a 1-by-L cell array of cells of the form

c = b1 a1 b2 a2 . . . bL aL

c = sos2cel l ( m, g) with the optional gain term g, prepends the constantvalue g to c. When you use the added gain term in the command, c is a 1-by-L

cell array of cells of the form

c = g, 1 b1, a1 b2, a2. . . bL, aL

Examples Usesos2cel l to convert the 2-by-6 second-order section matrix produced byt f 2sos into a 1-by-2 cell array c of cells. Display the second entry in the firstcell in c.

[ b, a] = el l i p( 4, 0. 5, 20, 0. 6) ;

m = t f 2sos( b, a) ;

c = sos2cel l ( m) ;

12

Page 665: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 665/870

7-384

c12

ans =

1. 0000 0. 1677 0. 2575

See Also t f 2sos Convert transfer functions to second-order sections.

cel l 2sos Convert cell arrays for second-order sections to amatrix.

sos2ss

7sos2ssPurpose Convert digital filter second-order section parameters to state-space form.

Syntax [ A, B, C, D] = sos2ss( sos)

[ A, B, C, D] = sos2ss( sos, g)

Description sos2ss converts a second-order section representation of a given digital filter

to an equivalent state-space representation.

[ A, B, C, D] = sos2ss( sos) converts the system sos, in second-order sectionform, to a single-input, single-output state-space representation.

The discrete transfer function in second-order section form is given by

sos is a L -by-6 matrix organized as

The entries of sos must be real for proper conversion to state space. Thereturned matrix A is size N by N where N =2L 1 B is a length N 1 column

x n 1+[ ] Ax n[ ] B u n[ ]+=

y n[ ] Cx n[ ] Du n[ ]+=

H z( ) H k z( )

k 1=

L

∏b0k b1kz 1– b2kz 2–+ +

1 a1kz 1– a2kz 2–+ +----------------------------------------------------------

k 1=

L

∏= =

sos

b01 b11 b21 1 a11 a21

b02 b12 b22 1 a12 a22

M M M M M M

b0L b1L b2L 1 a1L a2L

=

Page 666: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 666/870

7-385

returned matrix A is size N-by-N, where N =2L -1, B is a length N-1 column

vector, C is a length N-1 row vector, and D is a scalar.

[ A, B, C, D] = sos2ss( sos, g) converts the system sos in second-order sectionform with gain g.

H z( ) g H k z( )

k 1=

L

∏=

sos2ss

Example Compute the state-space representation of a simple second-order section

system 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 0

0 1 0 0

0 0 1 0

B =

1

0

00

C =

21 2 - 16 - 1

D =

- 2

Algorithm sos2ss first converts from second-order sections to transfer function usingsos2tf , and then from transfer function to state-space using t f2ss.

See Also sos2t f Convert digital filter second-order section

parameters to transfer function form.

sos2zp Convert digital filter second-order sectionparameters to zero-pole-gain form.

Page 667: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 667/870

7-386

pa a e e s o e o po e ga o

ss2sos Convert state-space data for a digital filter tosecond-order sections form.

t f 2ss Convert transfer function data for a fil ter tostate-space form.

zp2ss Convert zero-pole-gain data for a filter to state-spaceform.

sos2tf

7sos2tf Purpose Convert digital filter second-order section data to transfer function form.

Syntax [ b, a] = sos2t f ( s os)

[b, a] = sos2t f ( sos ,g)

Description sos2t f converts a second-order section representation of a given digital filter

to an equivalent transfer function representation.

[ b, a] = sos2t f ( s os) returns the numerator coefficients b and denominatorcoefficients a of the transfer function that descri bes a discrete-time systemgiven by sos in second-order section form. The second-order section format of H(z) is given by

sos is an L -by-6 matrix that contains the coefficients of each second-ordersection stored in its rows.

Row vectors b and a contain the numerator and denominator coefficients of H(z) stored in descending powers of z.

H z( ) H k z( )

k 1=

L

∏b

0kb

1kz 1– b

2kz 2–+ +

1 a1kz 1– a2kz 2–+ +----------------------------------------------------------

k 1=

L

∏= =

sos

b01 b11 b21 1 a11 a21

b02 b12 b22 1 a12 a22M M M M M M

b0L b1L b2L 1 a1L a2L

=

b b 1 b n

Page 668: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 668/870

7-387

[b, a] = sos2t f ( sos ,g) returns the transfer function that describes a

discrete-time system given by sos in second-order section form with gain g.

H z( )

B z( )

A z( )-----------

b1 b2z 1– bn 1+z n–+ + +

a1 a2z 1– am 1+z m–+ + +------------------------------------------------------------------------= =

H z( ) g H k z( )

k 1=

L

∏=

sos2tf

Algorithm sos2tf uses the conv function to multiply all of the numerator and

denominator second-order polynomials together.

Example Compute the transfer function representation of a simple second-order sectionsystem.

sos = [ 1 1 1 1 0 - 1; - 2 3 1 1 10 1];[ b, a] = sos2t f ( s os)

b =

- 2 1 2 4 1

a =

1 10 0 - 10 - 1

See Also l at c2t f L attice filter to transfer function conversion.sos2ss Convert digital filter second-order sections data to

state-space form.

sos2zp Convert digital filter second-order sections data tozero-pole-gain form.

ss2tf Convert state-space data for a filter to transferfunction form.

t f 2sos Convert transfer function data for a digital fil ter tosecond-order sections form.

zp2t f Convert zero-pole-gain data for a fil ter to transfer

function form.

Page 669: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 669/870

7-388

sos2zp

7sos2zpPurpose Convert digital filter second-order section parameters to zero-pole-gain form.

Syntax [z , p, k] = sos2zp(sos)

[z , p, k] = sos2zp(sos , g)

Description sos2zp converts a second-order section representation of a given digital filter

to an equivalent zero-pole-gain representation.

[z , p, k] = sos2zp(sos) returns the zeros z, poles p, and gain k of the systemgiven by sos in second-order section form. The second-order section format of H(z) is given by

sos is an L -by-6 matrix that contains the coefficients of each second-order

section in its rows.

Column vectors z and p contain the zeros and poles of the transferfunction H(z).

H z( ) H k z( )

k 1=

L

b0k b1kz 1– b2kz 2–+ +

1 a1kz 1–

a2kz 2–

+ +

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

k 1=

L

∏= =

sos

b01 b11 b21 1 a11 a21

b02 b12 b22 1 a12 a22

M M M M M Mb0L b1L b2L 1 a1L a2L

=

H z( ) kz z1–( ) z z2–( ) z zn–( )

p p( ) p p( ) p p( )----------------------------------------------------------------------=

Page 670: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 670/870

7-389

where the orders n and m are determined by the matrix sos.

[z , p, k] = sos2zp(sos , g) returns the zeros z, poles p, and gain k of thesystem given by sos in second-order section form with gain g.

p p1–( ) p p2–( ) p pm–( )

H z( ) g H k z( )

k 1=

L

∏=

sos2zp

Example Compute the poles, zeros, and gain of a simple system in second-order section

form.

sos = [ 1 1 1 1 0 - 1; - 2 3 1 1 10 1];

[ z , p, k] = sos2zp(sos)

z =

- 0. 5000 + 0. 8660i- 0. 5000 - 0. 8660i

1. 7808

- 0. 2808

p =

- 1. 0000

1. 0000

- 9. 8990- 0. 1010

k =

- 2

Algorithm sos2zp finds the poles and zeros of each second-order section by repeatedlycalling t f 2zp.

See Also sos2ss Convert digital filter second-order sectionparameters to state-space form.

sos2t f Convert digital filter second-order sectionparameters to transfer function form.

ss2zp Convert state-space filter parameters tozero-pole-gain form.

t f 2 C t t f f ti filt t t

Page 671: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 671/870

7-390

t f 2zp Convert transfer function filter parameters tozero-pole-gain form.

zp2sos Convert digital filter zero-pole-gain parameters tosecond-order sections form.

sosfilt

7sosfiltPurpose Second-order (biquadratic) I I R digital filtering.

Syntax y = sosf i l t ( sos, x)

Description y = sosf i l t ( sos, x) applies the second-order section digital filter sos to thevector x. The output, y, is the same length as x.

sos represents the second-order section digital filter H(z)

by an L -by-6 matrix containing the coefficients of each second-order section in

its rows.

I f x is a matrix, sosf i l t applies the filter to each column of x independently.Output y is a matrix of the same size, containing the filtered datacorresponding to each column of x.

See Also

H z( ) H k z( )

k 1=

L

∏b0k b1kz 1– b2kz 2–+ +

1 a1kz 1– a2kz 2–+ +----------------------------------------------------------

k 1=

L

∏= =

sos

b01 b11 b21 1 a11 a21

b02 b12 b22 1 a12 a22

M M M M M M

b0L b1L b2L 1 a1L a2L

=

f i l t er Apply a filter to data.

medf i l t 1 One-dimensional median filtering.

sgol ayf i l t Savitzky-Golay filtering.

Page 672: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 672/870

7-391

References [1] Orfanidis, S.J ., I ntroduction toSignal Processing, Prentice-Hall, EnglewoodCliffs, NJ , 1996.

specgram

7specgramPurpose Time-dependent frequency analysis (spectrogram).

Syntax B = specgr am( a)

B = specgram( a, nf f t )

[ B, f ] = specgram( a, nf f t , f s )

[B, f , t ] = specgram(a, nf f t , f s )

B = specgr am( a, nf f t , f s, wi ndow)

B = specgr am( a, nf f t , f s, wi ndow, numover l ap)

specgr am( a)

B = specgr am( a, f , f s, wi ndow, numover l ap)

Description specgr amcomputes the windowed discrete-time Fourier transform of a signal

using a sliding window. The spectrogram is the magnitude of this function.

B = specgr am( a) calculates the spectrogram for the signal in vector a. Thissyntax uses the default values:

• nf f t = mi n( 256, l ength(a) )

• f s = 2

• wi ndow is a periodic Hann (Hanning) window of length nf f t .

• numover l ap = l engt h( wi ndow) / 2

n f f t specifies the FF T length that specgramuses. This value determines thefrequencies at which the discrete-time Fourier transform is computed. f s is ascalar that specifies the sampling frequency. wi ndowspecifies a windowing

function and the number of samples specgr amuses in its sectioning of vector a.numover l ap is the number of samples by which the sections overlap. Anyarguments that you omit from the end of the input parameter l ist use thedefault values shown above.

Page 673: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 673/870

7-392

I f a is real, specgr amcomputes the discrete-time Fourier transform at positivefrequencies only. I f n is even, specgr amreturns nf f t / 2+1 rows (including thezero and Nyquist frequency terms). I f n is odd, specgr amreturns nf f t / 2 rows. The number of columns in B is

k = f i x(( n- numover l ap) / ( l engt h( wi ndow) - numover l ap) )

I f a is complex, specgr amcomputes the discrete-timeFourier transform at bothpositiveand negativefrequencies. I n this case, B is a complex matrix with nf f t

specgram

rows. Time increases linearly across the columns of B, starting with sample 1in column 1. Frequency increases linearly down the rows, starting at 0.

B = specgr am( a, nf f t ) uses the specified FFT length nf f t in its calculations.

[B, f ] = specgram(a, nf f t , f s ) returns a vector f of frequencies at which the

function computes the discrete-timeF ourier transform. f s has noeffect on theoutput B; it is a frequency scaling multiplier.

[B, f , t ] = specgram(a, nf f t , f s ) returns frequency and time vectors f and t

respectively. t is a column vector of scaled times, with l ength equal to the

number of columns of B. t ( j ) is the earliest time at which the jth windowintersects a. t (1) is always equal to 0.

B = specgr am( a, nf f t , f s, wi ndow) specifies a windowing function and thenumber of samples per section of thex vector. I f you supply a scalar for wi ndow,specgr amuses a Hann window of that length. The length of the window mustbe less than or equal to nf f t .

B = specgr am( a, nf f t , f s, wi ndow, numover l ap) overlaps the sections of x bynumover l ap samples.

You can use the empty matrix [ ] to specify the default value for any input

argument. For example,

B = specgr am( x, [ ] , 10000)

is equivalent to

B = specgr am( x)

but with a sampling frequency of 10,000 Hz instead of the default 2 Hz.

Page 674: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 674/870

7-393

specgr am( . . . ) with nooutput arguments displays thescaled logarithm of thespectrogram in the current figure window using

i magesc(t , f , 20*l og10( abs( b) ) ) , axi s xy, col or map( j et )

The axi s xy modedisplays thelow-frequency content of the first portion of thesignal in the lower-left corner of the axes. specgr amuses f s to label the axesaccording to true time and frequency.

specgram

B = specgr am( a, f , f s, wi ndow, numover l ap) computes the spectrogram at thefrequencies specified in f , using either thechirp z-transform (for more than 20

evenly spaced frequencies) or a polyphase decimation filter bank. f is a vectorof frequencies in hertz; it must have at least two elements.

Algorithm specgr amcalculates the spectrogram for a given signal as follows:

1 I t splits the signal into overlapping sections and applies the window

specified by the wi ndowparameter to each section.

2 I t computes the discrete-time Fourier transform of each section with alength nf f t FFT to produce an estimate of the short-term frequency contentof the signal; these transforms make up the columns of B. The quantity( l ength( wi ndow) - numover l ap) specifies by how many samples specgr am

shifts the window.

3 For real input, specgr amtruncates the spectrogram to the first nf f t / 2 +1

points for nf f t even and ( n f f t +1) /2 for nf f t odd.

Example Plot the spectrogram of a digitized speech signal.

l oad mt l b

specgr am( mt l b, 512, Fs, kai ser ( 500, 5) , 475)

t i t l e( ' Spectr ogr am' )

c y

Spectrogram

2500

3000

3500

Page 675: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 675/870

7-394

Time

F r e q u e n

c

0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45

0

500

1000

1500

2000

specgram

Diagnostics An appropriate diagnostic message is displayed when incorrect arguments are

used.

Requi r es wi ndow' s l engt h t o be no great er t han t he FFT l ength.

Requi r es NOVERLAP to be st r i ct l y l ess t han t he wi ndow l engt h.

Requi r es posi t i ve i nteger val ues f or NFFT and NOVERLAP.

Requi r es vect or i nput .

See Also

References [1] Oppenheim, A.V., and R.W. Schafer, Discrete-TimeSi gnal Processing,

Prentice-Hall, Englewood Cli ffs, NJ , 1989, pp. 713-718.

[2] Rabiner, L.R., and R.W. Schafer, Digital P rocessing of Speech Signals,Prentice-Hall, Englewood Cli ffs, NJ , 1978.

cohere Estimate magnitude squared coherence functionbetween two signals.

csd Estimate the cross spectral density (CSD) of twosignals.

pwel ch Estimate the power spectral density (PSD) of a signalusing Welch’s method.

t f e Transfer function estimate from input and output.

Page 676: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 676/870

7-395

sptool

7sptoolPurpose Open the digital signal processing GU I (SPTool).

Syntax spt ool

Description spt ool opens SPT ool, a graphical user interface (GUI ) that manages a suite of four other GUI s. These GUI s provide access to many of the signal, filter, and

spectral analysis functions in the toolbox. When you type spt ool at thecommand line, the following GUI opens.

Using SPTool you can:

• Analyze signals listed in the Signals list box with the Signal Browser

• Design or edit filters with the Filter Designer (includes a Pole/Zero Editor)

• Analyzefilter responses for filters listed in theFilters list box with theF ilter

Page 677: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 677/870

7-396

Viewer• Apply filters in the Filters list box to signals in the Signals list box

• Create and analyze signal spectra with the Spectrum Viewer

You can activate the four integrated signal processing GUI s from SPT ool.

sptool

Signal Browser

The Signal Browser allows you to view, measure, and analyzethe time-domaininformation of one or more signals. To activate the Signal Browser, press theView button under the Signals list box in SP Tool.

Filter Designer The Filter Designer allows you to design and edit F I R and I I R filters of variouslengths and types, with standard (lowpass, highpass, bandpass, bandstop, andmultiband) configurations. To activate the F ilter Designer, press either theNew Design button or the Edit Design button under the Filters list box in

SPTool.

Page 678: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 678/870

7-397

sptool

The Filter Designer has a Pole/Zero Editor you can accessfrom theAlgorithms

menu.

Page 679: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 679/870

7-398

sptool

Filter Viewer

The F ilter Viewer allows you to view the characteristics of a designed orimportedfilter, including its magnituderesponse, phaseresponse, groupdelay,pole-zero plot, impulse response, and step response. To activate the FilterViewer, press the View button under the Filters list box in SP Tool.

You can analyze multiple filter responses by checking several response plotoptions, as shown in the next figure.

Page 680: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 680/870

7-399

sptool

Spectrum Viewer

The Spectrum Viewer allowsyou tographically analyzefrequency-domain data

using a variety of methods of spectral density estimation, including the Burgmethod, the FFT method, the multitaper method (MT M), the MUSIC

eigenvector method, Welch’s method, and the Yule-Walker AR method. Toactivate the Spectrum Viewer:

• Press the Create button under the Spectra list box to compute the powerspectral density for a signal selected in the Signals list box in SPTool.

• Press theView button to analyzespectra selected under the Spectra list boxin SPTool.

• Press the Update button under the Spectra list box in SP Tool to modify a

selected power spectral density signal

Page 681: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 681/870

7-400

selected power spectral density signal.

sptool

I n addition, you can right-click in any plot display area of the GUI s to modify

signal properties.

See Chapter 6, “SPTool: A Signal Processing GUI Suite,”for a full discussion of how to use SPTool.

See Also f datool Open the Filter Design and Analysis Tool.

Page 682: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 682/870

7-401

square

7squarePurpose Generate a square wave.

Syntax x = square( t )

x = square( t , duty)

Description x = squar e( t ) generates a square wave with period 2π for the elements of

time vector t . squar e( t ) is similar to s i n( t ) , but creates a square wave withpeaks of ±1 instead of a sine wave.

x = square( t , duty) generates a square wavewith specified duty cycle, dut y. The duty cycle is the percent of the period in which the signal is positive.

See Also chi rp Generate a swept-frequency cosine.

cos Compute the cosine of vector/matrix elements (see

the MATL AB documentation).

di r i c Compute the Dirichlet or periodic sinc function.

gauspul s Generate a Gaussian-modulated sinusoidal pulse.

pul st r an Generate a Pulse train.

r ectpul s Generate a sampled aperiodic rectangle.

sawt oot h Generate a sawtooth or triangle wave.

si n Compute the sine of vector/matrix elements (see theMATL AB documentation).

s i nc Compute the sinc or sin(πt)/πt function.

t r i pul s Generate a sampled aperiodic triangle.

Page 683: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 683/870

7-402

ss2sos

7ss2sosPurpose Convert digital filter state-space parameters to second-order sections form.

Syntax [ sos, g] = ss2sos(A, B, C, D)

[ sos, g] = ss2sos(A, B, C, D, i u)

[ sos, g] = ss2sos(A, B, C, D, ' order ' )

[sos , g] = ss2sos(A, B, C, D, i u, ' order ' )

[sos , g] = ss2sos(A, B, C, D, i u, ' order ' , ' scal e' )sos = ss2sos( . . . )

Description ss2sos converts a state-space representation of a given digital fi lter to anequivalent second-order section representation.

[ sos, g] = ss2sos(A, B, C, D) finds a matrix sos in second-order section formwith gain g that is equivalent to the state-space system represented by input

arguments A, B, C, andD. The input system must be single output and real. sosis an L -by-6 matrix

whose rows contain the numerator and denominator coefficients bik and aik of the second-order sections of H(z).

[ sos, g] = ss2sos(A, B, C, D, i u) specifies a scalar i u that determines which

sos

b01 b11 b21 1 a11 a21

b02 b12 b22 1 a12 a22

M M M M M M

b0L b1L b2L 1 a1L a2L

=

H z( ) g H k z( )

k 1=

L

∏ gb0k b1kz 1– b2kz 2–+ +

1 a1kz 1– a2kz 2–+ +----------------------------------------------------------

k 1=

L

∏= =

Page 684: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 684/870

7-403

[ sos, g] ss2sos(A, B, C, D, i u) specifies a scalar i u that determines whichinput of the state-space system A, B, C, D is used in the conversion. The defaultfor i u is 1.

ss2sos

[ sos, g] = ss2sos(A, B, C, D, ' order ' ) and

[ sos , g] = ss2sos(A, B, C, D, i u, ' order ' ) specify theorder of therows in sos,where ' order ' is:

• ' down' , to order thesections so thefirst row of sos contains the poles closestto the unit circle

• ' up' , to order the sections sothefirst row of sos contains the poles farthestfrom the unit circle (default)

The zeros are always paired with the poles closest to them.

[ sos , g] = ss2sos(A, B, C, D, i u, ' order ' , ' scal e' ) specifies the desiredscaling of the gain and the numerator coefficients of all second-order sections,

where ' scal e' is:

• ' none' , to apply no scaling (default)

• ' i nf ' , to apply infinity-norm scaling

• ' t wo' , to apply 2-norm scaling

Using infinity-norm scaling in conjunction with up-ordering minimizes theprobability of overflow in the realization. Using 2-norm scaling in conjunctionwith down-ordering minimizes the peak round-off noise.

sos = ss2sos( . . . ) embeds the overall system gain, g, in the first section,H 1(z), so that

Example Find a second-order section form of a Butterworth lowpass filter.

H z( ) H k z( )

k 1=

L

∏=

Page 685: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 685/870

7-404

p p

[ A, B, C, D] = but t er ( 5, 0. 2) ;

sos = ss2sos( A, B, C, D)

sos =

0. 0013 0. 0013 0 1. 0000 - 0. 5095 0

1. 0000 2. 0008 1. 0008 1. 0000 - 1. 0966 0. 3554

1. 0000 1. 9979 0. 9979 1. 0000 - 1. 3693 0. 6926

ss2sos

Algorithm ss2sos uses a four-step algorithm to determine the second-order section

representation for an input state-space system:

1 I t finds the poles and zeros of the system given by A, B, C, and D.

2 I t uses the function zp2sos, which first groups the zeros and poles intocomplex conjugatepairs usingthecpl xpai r function. zp2sos then formsthe

second-order sections by matching the pole and zero pairs according to thefollowing rules:

a Match the poles closest to the unit circle with the zeros closest to thosepoles.

b Match the poles next closest to the unit circle with the zeros closest tothose poles.

c Continue until all of the poles and zeros are matched.

ss2sos groups real poles into sections with the real poles closest to them inabsolute value. The same rule holds for real zeros.

3 I t orders thesections accordingto theproximity of thepole pairs to theunit

circle. ss2sos normally orders the sections with poles closest to the unitcircle last in the cascade. You can tell ss2sos to order the sections in thereverse order by specifying the ' down' flag.

4 ss2sos scales the sections by the norm specified in the ' scal e' argument.For arbitrary H(ω), the scaling is defined by

where p can be either ∞ or 2. See the references for details. This scaling is

an attempt to minimizeoverflow or peak round-off noise in fixed point filter

implementations.

H p1

2π------ H ω( )

pωd

0

ò

1p---

=

Page 686: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 686/870

7-405

Diagnostics I f there is more than one input to thesystem, ss2sos gives the following errormessage.

State- space syst em must have onl y one i nput .

ss2sos

See Also

References [1] J ackson, L .B., Digital Fil ters and Signal Processing, 3rd ed., K luwerAcademic Publishers, Boston, 1996. Chapter 11.

[2] Mitra, S.K ., Digital Signal Processing: A Computer-B ased Approach,McGraw-Hill , New York, 1998. Chapter 9.

[3] Vaidyanathan, P.P .,“Robust Digital Fil ter Structures,” Handbook for

Digital Signal Processing, S.K . Mitra and J .F. K aiser, ed., J ohn Wiley & Sons,

New York, 1993, Chapter 7.

cpl xpai r Group complex numbers into complex conjugatepairs.

sos2ss Convert digital filter second-order sectionsparameters to state-space form.

ss2tf Convert state-space filter parameters to transferfunction form.

ss2zp Convert state-space filter parameters tozero-pole-gain form.

t f 2sos Convert digital fil ter transfer function parameters tosecond-order sections form.

zp2sos Convert digital filter zero-pole-gain parameters tosecond-order sections form.

Page 687: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 687/870

7-406

ss2tf

7ss2tf Purpose Convert state-space filter parameters to transfer function form.

Syntax [b, a] = ss2t f (A, B, C, D, i u)

Description ss2tf converts a state-space representation of a given system to an equivalenttransfer function representation.

[b, a] = ss2t f (A, B, C, D, i u) returns the transfer function

of the system

from the i u-th input. Vector a contains the coefficients of the denominator indescending powers of s. The numerator coefficients arereturned in arrayb withas many rows as there areoutputs y. ss2t f also works with systems in discretetime, in which case it returns the z-transform representation.

The ss2tf function is part of the standard MATL AB language.

Algorithm The ss2tf function uses pol y to find the characteristic polynomial det(sI-A)and the equality

H s( )B s( )

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

x· Ax B u+=

y Cx Du+=

H s( ) C sI A–( ) 1– Bdet sI A– B C+( ) det sI A–( )–

det sI A–( )------------------------------------------------------------------------------= =

Page 688: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 688/870

7-407

ss2tf

See Also l at c2t f L attice filter to transfer function conversion.

sos2t f Convert digital filter second-order sectionparameters to transfer function form.

ss2sos Convert digital filter state-space parameters to

second-order sections form.

ss2zpConvert state-space filter parameters tozero-pole-gain form.

t f 2ss Convert transfer function filter parameters tostate-space form.

zp2t f Convert zero-pole-gain filter parameters to transferfunction form.

Page 689: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 689/870

7-408

ss2zp

7ss2zpPurpose Convert state-space filter parameters to zero-pole-gain form.

Syntax [ z , p, k] = ss2zp( A, B, C, D, i )

Description ss2zp converts a state-space representation of a given system to an equivalentzero-pole-gain representation. The zeros, poles, and gains of state-space

systems represent the transfer function in factored form.

[z , p, k] = ss2zp( A, B, C, D, i u) calculates the transfer function in factoredform

of the continuous-time system

from the i th input (using the i th columns of B and D). The column vector p

contains the pole locations of the denominator coefficients of the transferfunction. The matrix z contains the numerator zeros in its columns, with asmany columns as there are outputs y (rows in C). The column vector k containsthe gains for each numerator transfer function.

ss2zp alsoworks for discreteti me systems. The input state-space system mustbe real.

The ss2zp function is part of the standard MATL AB language.

Example Here are two ways of finding the zeros, poles, and gains of a discrete-time

transfer function

H s( )Z s( )

P s( )---------- k

s z1–( ) s z2–( )L s zn–( )

s p1–( ) s p2–( )L s pn–( )------------------------------------------------------------------= =

x· Ax B u+=

y Cx Du+=

1–

Page 690: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 690/870

7-409

b = [ 2 3] ;

a = [ 1 0. 4 1] ;

[ b, a] = eqt f l engt h( b, a) ;

[ z , p, k] = t f 2zp( b, a)

H z( )2 3z

1–+

1 0.4z1–

z2–

+ +

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

ss2zp

z =

0. 0000

- 1. 5000

p =

- 0. 2000 + 0. 9798i

- 0. 2000 - 0. 9798i

k =

2

[A, B, C, D] = t f 2ss(b, a) ;

[ z , p, k] = ss2zp( A, B, C, D, 1)

z =

0. 0000

- 1. 5000

p =

- 0. 2000 + 0. 9798i

- 0. 2000 - 0. 9798i

k =

2

Algorithm ss2zp finds the poles from the eigenvalues of the A array. The zeros are thefinite solutions to a generalized eigenvalue problem.

z = ei g( [ A B; C D] , di ag( [ ones(1, n) 0] ) ;

I n many situations this algorithm produces spurious large, but finite, zeros.ss2zp interprets these large zeros as infinite.

ss2zp finds the gains by solving for the first nonzero Markov parameters.

Page 691: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 691/870

7-410

ss2zp

See Also

References [1] L aub, A.J ., and B.C. Moore, “Calculation of Transmission Zeros Using QZ Techniques,” Automatica 14 (1978), p. 557.

pzmap Pole-zero map of LTI system (see the Control System Toolbox documentation).

sos2zp Convert digital filter second-order section parametersto zero-pole-gain form.

ss2sos Convert digital filter state-space parameters to

second-order sections form.ss2tf Convert state-space filter parameters to transfer

function form.

t f 2zp Convert transfer function filter parameters to

zero-pole-gain form.

zp2ss Convert zero-pole-gain filter parameters tostate-space form.

Page 692: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 692/870

7-411

stmcb

7stmcbPurpose Compute a linear model using Steiglitz-McBride iteration.

Syntax [ b, a] = stmcb( x, nb, na)

[ b, a] = stmcb( x, u, nb, na)

[ b, a] = stmcb( x, nb, na, ni t er)

[ b, a] = stmcb( x, u, nb, na, ni ter)

[ b, a] = stmcb( x, nb, na, ni te r , ai )[ b, a] = stmcb( x, u, nb, na, ni ter , ai )

Description Steiglitz-McBride iteration is an algorithm for finding an I I R filter with aprescribed time domain impulse response. I t has applications in both filterdesign and system identification (parametric modeling).

[ b, a] = stmcb( x, nb, na) finds the coefficients b and a of the system b(z)/ a(z)

with approximate impulse response x, exactly nb zeros, and exactly na poles.

[ b, a] = stmcb( x, u, nb, na) finds the system coefficients b and a of thesystemthat, given u as input, has x as output. x and u must be the same length.

[ b, a] = stmcb( x, nb, na, ni t er) and

[ b, a] = stmcb( x, u, nb, na, ni ter) useni t er iterations. The default for ni t er

is 5.

[ b, a] = stmcb( x, nb, na, ni te r , ai ) and

[ b, a] = stmcb( x, u, nb, na, ni ter , ai ) usethevector ai astheinitial estimateof the denominator coefficients. I f ai is not specified, st mcb uses the outputargument from [b, ai ] = prony(x, 0, na) as the vector ai .

st mcb returns the I I R filter coefficients in length nb+1 and na+1 row vectors b

and a. The filter coefficients are ordered in descending powers of z.

B z( ) b 1( ) b 2( )z 1– b n b 1( )z nb–

Page 693: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 693/870

7-412

H z( )B z( )

A z( )-----------

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

a 1( ) a 2( )z 1–L a na 1+( )z na–+ + +

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

stmcb

Example Approximate the impulse response of a Butterworth filter with a system of

lower order.

[ b, a] = but t er ( 6, 0. 2) ;

h = f i l t er ( b, a, [1 zeros (1, 100) ] ) ;

f r eqz( b, a, 128)

[ bb, aa] = stmcb( h, 4, 4) ;

f r eqz( bb, aa, 128)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−600

−500

−400

−300

−200

−100

0

Normalized Frequency (×π rad/sample)

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

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−300

−250

−200

−150

−100

−50

0

50

Normalized Frequency (×π rad/sample)

M a g n i t u d e ( d B )

20

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 694: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 694/870

7-413

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−100

−80

−60

−40

−20

0

20

Normalized Frequency (×π rad/sample)

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

stmcb

Algorithm st mcb attempts to minimize thesquared error between theimpulseresponsex'

of b(z)/ a(z) and the input signal x.

st mcb iterates using two steps:

1 It prefilters x and u using 1/a(z).

2 I t solves a system of linear equations for b and a using \ .

st mcb repeats this processni t er times. No checking is doneto seeif theb and a

coefficients have converged in fewer than ni ter iterations.

Diagnostics I f x and u havedifferent lengths, st mcb gives the following error message.

X and U must have same l ength.

See Also

References [1] Steiglitz, K .,andL .E. McBride, “A Techniquefor theI dentification of L inearSystems,” I EE E T rans. Automatic Control, Vol. AC-10 (1965), pp. 461-464.

[2] L jung, L ., System I dentification: Theory for the User, Prentice-Hall,Englewood Cliffs, NJ , 1987, p. 297.

mina b,

x i( ) x' i( )– 2

i 0=

å

l evi nson Compute the Levinson-Durbin recursion.

l pc Compute li near prediction filter coefficients.

ar yul e Compute an estimate of AR model parameters usingthe Yule-Walker method.

prony Prony’s method for time domain I I R fi lter design.

Page 695: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 695/870

7-414

strips

7stripsPurpose Strip plot.

Syntax s t r i ps (x)

s t r i ps (x, n)

s t r i ps (x, sd, f s )

s t r i ps (x, sd, f s , scal e)

Description s t r i ps (x) plots vector x in horizontal strips of length 250. I f x is a matrix,s t r i ps (x) plots each column of x. The left-most column (column 1) is the tophorizontal strip.

s t r i ps (x, n) plots vector x in strips that are each n samples long.

s t r i ps (x, sd, f s ) plots vector x in strips of duration sd seconds, given a

sampling frequency of f s samples per second.

s t r i ps (x, sd, f s , scal e) scales the vertical axes.

I f x is a matrix, s t r i ps (x, n) , s t r i ps (x, sd, f s ) , and s t r i ps (x, sd, f s , scal e)

plot the different columns of x on the same strip plot.

st r i ps ignores the imaginary part of complex-valued x.

Example Plot two seconds of a frequency modulated sinusoid in 0.25 second strips.f s = 1000; % Sampl i ng f r equency

t = 0: 1/ f s :2; % Ti me vector

x = vco( s i n( 2*pi * t ) , [ 10 490] , f s) ; % FM wavef orm

st r i ps (x, 0. 25, f s )

Page 696: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 696/870

7-415

strips

See Also

0 0.05 0.1 0.15 0.2 0.25

1.75

1.5

1.25

1

0.75

0.5

0.25

0

pl ot L inear two-dimensional plot (see the MATL ABdocumentation).

stem Pl ot discrete sequence data (see the MATL ABdocumentation).

Page 697: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 697/870

7-416

tf2latc

7tf2latcPurpose Convert transfer function fil ter parameters to lattice filter form.

Syntax [ k, v] = t f 2l at c( b, a)

k = t f 2l at c( 1, a)

[ k, v] = t f 2l at c( 1, a)

k = t f 2l at c( b)

Description [ k, v] = t f 2l at c( b, a) finds the lattice parameters k and the ladderparameters v for an I I R (ARM A) lattice-ladder filter, normalized by a(1) . Notethat an error is generated if one or more of the lattice parameters are exactly

equal to 1.

k = t f 2l at c( 1, a) finds the lattice parameters k for an I I R all-pole (AR)lattice filter.

[ k, v] = t f 2l at c( 1, a) returns the scalar l adder coefficient at the correctposition in vector v. All other elements of v are zero.

k = t f 2l at c( b) finds the lattice parameters k for an F I R (MA) lattice filter,normalized by b( 1) .

See Also l atc2t f Convert lattice filter parameters to transfer function

form.l at cf i l t L attice and lattice-ladder filter implementation.

t f 2sos Convert transfer function digital fil ter parameters tosecond-order sections form.

t f 2ss Convert transfer function filter parameters tostate-space form.

t f 2zp Convert transfer function filter parameters to

zero-pole-gain form.

Page 698: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 698/870

7-417

tf2sos

7tf2sosPurpose Convert digital filter transfer function data to second-order sections form.

Syntax [ sos ,g] = t f 2sos(b, a)

[ s os, g] = t f 2s os(b, a, ' order ' )

[ s os, g] = t f 2s os(b, a, ' order ' , ' scal e' )

sos = t f 2sos( . . . )

Description t f 2sos converts a transfer function representation of a given digital filter toanequivalent second-order section representation.

[ sos ,g] = t f 2sos(b, a) finds a matrix sos in second-order section form with

gain g that is equivalent to the digital filter represented by transfer functioncoefficient vectors a and b.

sos is an L -by-6 matrix

whose rows contain the numerator and denominator coefficients bik and aik of

the second-order sections of H(z).

H z( ) B z( )A z( )----------- b1 b2z

1–L

bnb 1+ z

nb–+ + +

a1 a2z 1–L ana 1+

z na–+ + +----------------------------------------------------------------------------= =

sos

b01 b11 b21 1 a11 a21

b02 b12 b22 1 a12 a22

b0L b1L b2L 1 a1L a2L

=

H z( ) g H k z( )

k 1=

L

∏ gb0k b1kz 1– b2kz 2–+ +

1 a1k

z 1– a2k

z 2–+ +----------------------------------------------------------

k 1=

L

∏= =

Page 699: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 699/870

7-418

tf2sos

[ s os, g] = t f 2sos (b, a, ' order ' ) specifies theorder of therows in sos, where' order ' is:

• ' down' , toorder thesections sothe first row of sos contains the poles closestto the unit circle

• ' up' , to order thesections sothe first row of sos contains the poles farthestfrom the unit circle (default)

[ s os, g] = t f 2sos (b, a, ' order ' , ' scal e' ) specifies the desired scaling of thegain and numerator coefficients of all second-order sections, where ' scal e' is:

• ' none' , to apply no scaling (default)

• ' i nf ' , to apply infinity-norm scaling

• ' t wo' , to apply 2-norm scaling

Using infinity-norm scaling in conjunction with up-ordering minimizes theprobability of overflow in the realization. Using 2-norm scaling in conjunction

with down-ordering minimizes the peak round-off noise.

sos = t f 2sos( . . . ) embeds the overall system gain, g, in the first section,H1(z), so that

Algorithm t f 2sos uses a four-step algorithm to determine the second-order sectionrepresentation for an input transfer function system:

1 I t finds the poles and zeros of the system given by b and a.

2 I t uses the function zp2sos, which first groups the zeros and poles into

complex conjugatepairs usingthecpl xpai r function. zp2sos then formsthesecond-order sections by matching the pole and zero pairs according to thefollowing rules:

H z( ) H k z( )

k 1=

L

∏=

Page 700: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 700/870

7-419

following rules:

a Match the poles closest to the unit circle with the zeros closest to thosepoles.

b Match the poles next closest to the unit circle with the zeros closest tothose poles.

tf2sos

c Continue until all of the poles and zeros are matched.

t f 2sos groups real poles into sections with the real poles closest to them inabsolute value. The same rule holds for real zeros.

3 I t orders thesections accordingto theproximity of thepole pairs to theunit

circle. t f 2sos normally orders the sections with poles closest to the unitcircle last in the cascade. You can tell t f 2sos to order the sections in the

reverse order by specifying the ' down' flag.4 t f 2sos scales the sections by the norm specified in the ' scal e' argument.

For arbitrary H(ω), the scaling is defined by

where p can be either ∞ or 2. See the references for details on the scaling. This scaling is an attempt to minimize overflow or peak round-off noise in

fixed point filter i mplementations.

See Also

H p1

2π------ H ω( )

pωd

0

ò

1p---

=

cpl xpai r Group complex numbers into complex conjugatepairs.

sos2t f Convert digital filter second-order section

parameters to transfer function form.ss2sos Convert digital filter state-space parameters to

second-order sections form.

t f 2ss Convert transfer function filter parameters tostate-space form.

t f 2zp Convert transfer function filter parameters tozero-pole-gain form.

zp2sos Convert digital filter zero-pole-gain parameters tosecond-order sections form.

Page 701: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 701/870

7-420

References [1] J ackson, L .B., Digital Fil ters and Signal Processing, 3rd ed., K luwerAcademic Publishers, Boston, 1996, Chapter 11.

[2] Mitra, S.K ., Digital Signal Processing: A Computer-B ased Approach,McGraw-Hill , New York, 1998, Chapter 9.

tf2sos

[3] Vaidyanathan, P.P., “Robust Digital Filter Structures,” Handbook for

Digital Signal Processing, S.K . Mitra and J .F. K aiser, ed., J ohn Wiley & Sons,New York, 1993, Chapter 7.

Page 702: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 702/870

7-421

tf2ss

7tf2ssPurpose Convert transfer function filter parameters to state-space form.

Syntax [ A, B, C, D] = t f 2ss (b, a)

Description t f2ss converts the parameters of a transfer function representation of a givensystem to those of an equivalent state-space representation.

[A, B, C, D] = t f 2ss (b, a) returns theA, B, C, and Dmatrices of a state spacerepresentation for the single-input transfer function

in controller canonical form

The input vector a contains the denominator coefficients in descending powersof s. Therowsof thematrix b contain the vectors of numerator coefficients (eachrow correspondstoan output). I n thediscrete-timecase, you must supply b anda to correspond to the numerator and denominator polynomials withcoefficients in descending powers of z.

For discrete-time systems you must makeb havethe samenumber of columnsas thelength of a. You can dothis by padding each numerator represented in b

(and possibly the denominator represented in the vector a) with trailing zeros. You can use the function eqt f l engt h to accomplish this if b and a are vectorsof unequal lengths.

The t f 2ss function is part of the standard MATL AB language.

Example Consider the system

H s( )B s( )

A s( )-----------

b1snb 1–L bnb 1–

s bnb+ + +

a1sna 1–L ana 1–

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

x· Ax B u+=

y Cx Du+=

2s 3+

Page 703: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 703/870

7-422

H s( )

2s 3+

s2 2s 1+ +

s2 0.4s 1+ +---------------------------------=

tf2ss

To convert this system to state-space, type

b = [0 2 3; 1 2 1] ;

a = [1 0. 4 1] ;

[ A, B, C, D] = t f 2ss (b, a)

A =

- 0. 4000 - 1. 0000

1. 0000 0

B =

1

0

C =

2. 0000 3. 0000

1. 6000 0

D =

0

1

Note There is disagreement in the literature on naming conventions for thecanonical forms. I t is easy, however, to generate similarity transformations

that convert these results to other forms.

See Also sos2ss Convert a digital fi lter second-order sections form tostate-space form.

ss2tf Convert state-space filter parameters to transferfunction form.

t f 2sos Convert digital fil ter transfer function parameters tosecond-order sections form.

t f 2zp Convert transfer function filter parameters to

Page 704: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 704/870

7-423

p Convert transfer function filter parameters tozero-pole-gain form.

zp2ss Convert zero-pole-gain filter parameters tostate-space form.

tf2zp

7tf2zpPurpose Convert transfer function filter parameters to zero-pole-gain form.

Syntax [ z , p, k] = t f 2zp( b, a)

Description t f2zp finds the zeros, poles, and gains of a transfer function.

[ z , p, k] = t f 2zp( b, a) finds the matrix of zeros z, the vector of poles p, andthe associated vector of gains k from the transfer function parameters b and a:

• The numerator polynomials are represented as columns of the matrix b.

• The denominator polynomial is represented in the vector a.

Given a SI MO continuous-time system in polynomial transfer function form

or

you can use the output of t f2zp to produce the single-input, multioutput(SIMO) factored transfer function form

or

H s( )

B s( )

A s( )-----------

b1snb 1–L bnb 1–

s bnb+ + +

a1sna 1–L

ana 1– s ana+ + +------------------------------------------------------------------------------= =

H z( )B z( )A z( )------------

b1 b2z1–

L bnb 1–z nb– bnbz nb– 1–+ + +

a1 a2z1–

L ana 1–z na– anaz na– 1–+ + +

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

H s( )Z s( )

P s( )---------- k

s z1–( ) s z2–( )L s zm–( )

s p1–( ) s p2–( )L s pn–( )------------------------------------------------------------------= =

H z( )

Z z( )

P z( )---------- k

z z1–( ) z z2–( )L z zm–( )

z p1–( ) z p2–( )L

z pn–( )-------------------------------------------------------------------= =

Page 705: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 705/870

7-424

tf2zp

The following describes the input and output arguments for t f 2zp:

• The vector a specifies the coefficients of the denominator polynomial A(s)(or A(z)) in descending powers of s (z-1).

• The ith row of the matrix b represents the coefficients of the ith numeratorpolynomial (the ith row of B(s) or B(z)). Specify as many rows of b as thereare outputs.

• For continuous-timesystems, choosethe number nbof columnsof b tobelessthan or equal to the length na of the vector a.

• For discrete-timesystems, choosethe number nb of columns of b to be equalto the length na of the vector a. You can use the function eqt f l engt h toprovide equal length vectors in the case that b and a are vectors of unequallengths. Otherwise, pad the numerators in the matrix b (and, possibly, the

denominator vector a) with zeros.

• The zero locations arereturned in thecolumns of thematrix z, with as manycolumns as there are rows in b.

• The pole locations arereturned in thecolumn vector p and the gains for eachnumerator transfer function in the vector k.

The t f 2zp function is part of the standard MATL AB language.

Example Find the zeros, poles, and gains of the discrete-time system

b = [ 2 3] ;

a = [ 1 0. 4 1] ;

[ b, a] = eqt f l engt h( b, a) ; % Make l engt hs equal .

[ z, p, k] = t f 2zp( b, a) % Obt ai n t he zer o- pol e- gai n f or m.

H z( )2 3z

1–+

1 0.4z1–

z2–

+ +

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

Page 706: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 706/870

7-425

tf2zp

z =

0

- 1. 5000

p =

- 0. 2000 + 0. 9798i

- 0. 2000 - 0. 9798i

k =

2

See Also sos2zp Convert digital filter second-order sectionsparameters to zero-pole-gain form.

ss2zp Convert state-space filter parameters tozero-pole-gain form.

t f 2sos Convert digital fil ter transfer function parameters tosecond-order sections form.

t f 2ss Convert transfer function filter parameters tostate-space form.

zp2t f Convert zero-pole-gain filter parameters to transferfunction form.

Page 707: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 707/870

7-426

tfe

7tfePurpose Estimate the transfer function from input and output.

Syntax Txy = t f e( x, y)

Txy = t f e( x, y, nf f t )

[ Txy, f ] = t f e( x, y, nf f t , f s )

Txy = t f e( x, y, nf f t , f s, wi ndow)

Txy = t f e( x, y, nf f t , f s, wi ndow, numover l ap) Txy = t f e( x, y, . . . , ' df l ag' )

t f e(x , y)

Description Txy = t f e( x, y) finds a transfer function estimate Txy given input signalvector x and output signal vector y. The transfer function is the quotient of thecross spectrum of x and y and the power spectrum of x.

The relationship between the input x and output y is modeled by the linear,time-invariant transfer function Txy.

Vectors x and y must be the same length. Txy = t f e( x, y) uses the followingdefault values:

•nf f t = mi n( 256, ( l ength( x) )

• f s = 2

• wi ndow is a periodic Hann (Hanning) window of length nf f t

• numover l ap = 0

nf f t specifies the FFT length that t f e uses. This value determines thefrequencies at which the power spectrum is estimated. f s is a scalar thatspecifies the sampling frequency. wi ndowspecifies a windowing function and

the number of samples t f e uses in its sectioning of the x and y vectors.numover l ap is the number of samples by which the sections overlap. Anyarguments that are omitted from the end of the parameter list use the default

values shown above.

T xy f ( )P

xyf ( )

P xx f ( )---------------=

Page 708: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 708/870

7-427

I f x is real, t f e estimates the transfer function at positive frequencies only; inthis case, the output Txy is a column vector of length nf f t / 2+1 for nf f t evenand ( nf f t +1) / 2 for nf f t odd. I f x or y is complex, t f e estimates the transferfunction for both positi ve and negative frequencies and Txy has length nf f t .

tfe

Txy = t f e( x, y, nf f t ) uses the specified FF T length nf f t in estimating thetransfer function.

[ Txy, f ] = t f e( x, y, nf f t , f s ) returns a vector f of frequencies at which t f e

estimates thetransfer function.f s is thesampling frequency. f is thesamesizeas Txy, sopl ot ( f , Txy) plots the transfer function estimate versus properlyscaled frequency. f s has no effect on the output Txy; it is a frequency scaling

multiplier.

Txy = t f e( x, y, nf f t , f s, wi ndow) specifies a windowing function and thenumber of samples per section of thex vector. I f you supply a scalar for wi ndow, Txy uses a Hann window of that length. The length of thewindow must be lessthan or equal to nf f t ; t f e zero pads the sections if the length of the windowexceeds nf f t .

Txy = t f e( x, y, nf f t , f s, wi ndow, numover l ap) overlaps the sections of x bynumover l ap samples.

You can use the empty matrix [ ] to specify the default value for any inputargument except x or y. For example,

Txy = t f e( x, y, [ ] , [ ] , kai ser ( 128, 5) )

uses 256 as the value for nf f t and 2 as the value for f s.

Txy = t f e( x, y, . . . , ' df l ag' ) specifies a detrend option, where ' df l ag' is:

• ' l i near ' , to removethe best straight-line fit fromthe prewindowed sectionsof x and y

• ' mean' , to remove the mean from the prewindowed sections of x and y

• ' none' , for no detrending (default)

The ' df l ag' parameter must appear last in the li st of input arguments. t f e

recognizes a ' df l ag' string no matter how many intermediate arguments areomitted.

t f e( ) with no output arguments plots the magnitude of the transfer

Page 709: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 709/870

7-428

t f e( . . . ) with no output arguments plots the magnitude of the transfer

function estimate as decibels versus frequency in the current figure window.

tfe

Example Compute and plot the transfer function estimate between two colored noise

sequences x and y.

h = f i r1( 30, 0. 2, boxcar ( 31) ) ;

x = r andn( 16384, 1) ;

y = f i l t er ( h, 1, x) ;

t f e( x, y, 1024, [ ] , [ ] , 512)

t i t l e( ' Tr ansf er Funct i on Est i mat e' )

Algorithm t f e uses a four-step algorithm:

1 I t multiplies the detrended sections by wi ndow.

2 I t takes the length nf f t FF T of each section.

3 I t averages the squares of the spectra of the x sections to form Pxx and

averages the products of the spectra of the x and y sections to form Pxy.4 I t calculates Txy:

Txy = Pxy. / Pxx

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

-40

-35

-30

-25

-20

-15

-10

-5

0

5

Frequency

T r a n f e r F u n c t i o n E s t i m

a t e ( d B )

Transfer Function Estimate

Page 710: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 710/870

7-429

tfe

Diagnostics An appropriate diagnostic message is displayed when incorrect arguments are

used.

Requi r es wi ndow' s l ength t o be no great er t han the FFT l engt h.

Requi r es NOVERLAP to be st r i ct l y l ess t han t he wi ndow l ength.

Requi r es posi t i ve i nt eger val ues f or NFFT and NOVERLAP.

Requi r es vect or ( ei t her r ow or col umn) i nput .

Requi r es i nput s X and Y t o have t he same l ength.

See Also et fe Compute empirical transfer function estimate andperiodogram (see the System I dentification Toolboxdocumentation).

cohere Estimate magnitude squared coherence functionbetween two signals.

csd Estimate the cross spectral density (CSD) of twosignals.

pwel ch Estimate the power spectral density (PSD) of a signal

using Welch’s method.

spa Perform spectral analysis for input-output data (seethe System I dentification Toolbox documentation).

Page 711: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 711/870

7-430

triang

7triangPurpose Compute a tri angular window.

Syntax w = t r i ang(n)

Description t r i ang( n) returns an n-point triangular window in the column vector w. Thecoefficients of a triangular window are

F or n odd:

For n even:

The triangular window is very similar to a Bartlett window. The Bartlettwindow always ends with zeros at samples 1 and n, while thetriangularwindow is nonzero at those points. For n odd, the center n- 2 points of

t r i ang( n- 2) are equivalent to bart l et t ( n) .

Example w = t r i ang(200) ;

pl ot ( w)

t i t l e( ' Tr i angul ar Wi ndow' )

w k[ ]

2k

n 1+------------- 1 k

n 1+

2-------------≤ ≤,

2 n k 1+–( )n 1+

-------------------------------n 1+

2------------- k n≤ ≤,

î

=

w k[ ]

2k 1–

n---------------- 1 k

n

2---≤ ≤,

2 n k 1+–( )n

-------------------------------n

2--- 1+ k n≤ ≤,

î

=

Page 712: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 712/870

7-431

triang

See Also

References [1] Oppenheim, A.V., and R.W. Schafer, Discrete-TimeSi gnal Processing,Prentice-Hall, Englewood Cliffs, 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

bart l et t Compute a Bartlett window.

bl ackman Compute a Blackman window.

boxcar Compute a rectangular window.

chebwi n Compute a Chebyshev window.

hammi ng Compute a Hamming window.

hannCompute a Hann window.

kai ser Compute a K aiser window.

Page 713: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 713/870

7-432

tripuls

7tripulsPurpose Generate a sampled aperiodic triangle.

Syntax y = t r i pul s( T)

y = t r i pul s( T, w)

y = t r i pul s( T, w, s)

Description y = t r i pul s( T) returns a continuous, aperiodic, symmetric, unity-heighttriangular pulseat thetimes indicated in array T, centered about T=0 and witha default width of 1.

y = t r i pul s( T, w) generates a triangular pulse of width w.

y = t r i pul s( T, w, s) generates a triangular pulse with skew s, where- 1 <s <1. When s is 0, a symmetric triangular pulse is generated.

See Also chi rp Generate a swept-frequency cosine.

cos Computethe cosine of vector/matrix elements (see theMATLAB documentation).

di r i c Compute the Dirichlet or periodic sinc function.

gauspul s Generate a Gaussian-modulated sinusoidal pulse.

pul st r an Generatea pulse train.

r ectpul s Generate a sampled aperiodic rectangle.

sawt oot h Generate a sawtooth or triangle wave.

si n Compute the sine of vector/matrix elements (see theMATLAB documentation).

s i nc Compute the sinc or sin(πt)/πt function.

square Generate a square wave.

Page 714: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 714/870

7-433

udecode

7udecodePurpose Decode 2n-level quantized integer inputs to floating-point outputs.

Syntax y = udecode( u, n)

y = udecode( u, n, v)

y = udecode(u, n, v, ' sat urat emode' )

Description y = udecode( u, n) inverts the operation of uencode and reconstructsquantized floating-point values from an encoded multidimensional array of integers u. The input argument n must be an integer between 2 and 32. Theinteger n specifies that there are 2n quantization levels for the inputs, so thatentries in u must be either:

• Signed integers in the range [-2n/2, (2n/2) - 1]

• Unsigned integers in the range [0, 2n-1]

I nputs can be real or complex values of any integer data type (ui nt 8, ui nt 16,ui nt 32, i nt 8, i nt 16, i nt32). Overflows (entries in u outside of the ranges

specified above) are saturated to the endpoints of the range interval. Theoutput y has the same dimensions as u. I ts entries have values in the range[ - 1, 1] .

y = udecode( u, n, v) decodes u such that the output y has values in therange[ - v, v] , where the default value for v is 1.

y = udecode( u, n, v, ' Sat urat eMode' ) decodes u and treats input overflows(entries in u outside of [ - v ,v ] ) according to thestring ' sat urat emode' , whichcan be one of the following:

• ' sat ur at e' : Saturate overflows. This is the default method for treatingoverflows.

- Entries in signed inputs u whose values are outside of the range

[-2

n

/2, (2

n

/2) - 1]areassigned thevalue determined bytheclosest endpointof this interval.

- Entries in unsigned inputs u whose values are outside of the range[0, 2n-1] are assigned the value determined by the closest endpoint of thisinterval.

Page 715: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 715/870

7-434

interval.

udecode

• ' wr ap' : Wrap all overflows according to the following:

- Entries in signed inputs u whose values are outside of the range[-2n/2, (2n/2) - 1] are wrapped back into that range using modulo 2n

arithmetic (calculated using u =mod(u+2 n/ 2, 2 n) - ( 2 n/ 2) ).

- Entries in unsigned inputs u whose values are outside of the range

[0, 2n-1] are wrapped back into the required range before decoding using

modulo 2n

arithmetic (calculated using u =mod( u, 2 n) ).

Examples u = i nt 8( [ - 1 1 2 - 5] ) ; % Cr eat e a si gned 8- bi t i nt eger str i ng.

ysat = udecode( u, 3) % Decode wi th 3 bi t s .

ysat =

- 0. 2500 0. 2500 0. 5000 - 1. 0000

Notice the last entry in u saturates to 1, the default peak input magnitude.

Change the peak input magnitude.

ysat v = udecode(u, 3, 6) % Set t he peak i nput magni t ude to 6.

ysat v =

- 1. 5000 1. 5000 3. 0000 - 6. 0000

The last input entry still saturates. Try wrapping the overflows.

ywr ap = udecode( u, 3, 6, ' wr ap' )

ywr ap =

- 1. 5000 1. 5000 3. 0000 4. 5000

Try adding more quantization levels.

yprec = udecode( u, 5)

ypr ec =

- 0. 0625 0. 0625 0. 1250 - 0. 3125

Algorithm The algorithmadheres tothedefinition for uniform decodingspecified in I TU -TRecommendation G.701. I nteger input values are uniquely mapped (decoded)from one of 2n uniformly spaced integer values to quantized floating-point

Page 716: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 716/870

7-435

y p g q g pvalues in the range [ - v ,v ] . The smallest integer input value allowed ismapped to -v and the largest integer input value allowed is mapped to v.

udecode

Values outside of the allowable input range are either saturated or wrapped,according to specification.

The real and imaginary components of complex inputs are decoded

independently.

See Also uencode Quantize and encode floating-point data.

References General Aspects of Digital T ransmission Systems: Vocabulary of Digital

Transmission and M ultiplexing, and PulseCodeModulation (PCM ) Terms,I nternational Telecommunication Union, I TU-T Recommendation G.701,March, 1993.

Page 717: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 717/870

7-436

uencode

7uencodePurpose Quantize and encode floating-point inputs to integer outputs.

Syntax y = uencode(u, n)

y = uencode( u, n, v)

y = uencode( u, n, v, ' Si gnFl ag' )

Description y = uencode( u, n) quantizes the entries in a multidimensional array of floating-point numbers u and encodes them as integers using 2n-levelquantization. n must be an integer between 2 and 32 (inclusive). I nputs can bereal or complex, double- or single-precision. The output y and the input u arearrays of the same size. The elements of the output y are unsigned integers

with magnitudes in the range [0, 2n-1]. Elements of the input u outside of therange [ - 1, 1] are treated as overflows and are saturated.

• For entries in the input u that are less than -1, the value of the output of

uencode is 0.

• For entries in the input u that are greater than 1, the value of the output of uencode is 2n-1.

y = uencode( u, n, v) allows the input u to have entries with floating-point

values in therange[ - v, v] before saturating them (thedefault value for v is 1).Elements of the input u outside of the range [ - v, v] are treated as overflowsand are saturated.

• For input entries less than -v, the value of the output of uencode is 0.

• For input entries greater than v, the value of the output of uencode is 2n-1.

y = uencode( u, n, v, ' Si gnFl ag' ) maps entriesi n a multidimensional arrayof floating-point numbers u whose entries have values in the range [- v , v] to aninteger output y. I nput entries outside this range are saturated. The integer

type of the output depends on the string ' Si gnFl ag' and the number of

quantization levels 2n. Thestring ' Si gnFl ag' can be one of the following:

• ' si gned' : Outputs are signed integers with magnitudes in therange[-2n/2, (2n/2) - 1].

• ' unsi gned' (default): Outputs areunsigned integers with magnitudes in the

Page 718: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 718/870

7-437

unsi gned (default): Outputs areunsigned integers with magnitudes in therange [0, 2n-1].

uencode

The output data types are optimized for the number of bits as shown in thetable below.

Examples Map floating-point scalars in [-1, 1] toui nt 8 (unsigned) integers, and producea staircase plot. Notethat thehorizontal axis plots from -1 to1 and theverticalaxis plots from 0 to7 (2 3- 1).

u = [ - 1: 0. 01: 1] ;

y = uencode( u, 3) ;pl ot ( u, y, ' . ' )

n Unsigned Integer Signed Integer

2 to 8 ui nt 8 i nt 8

9 to 16 ui nt 16 i nt 16

17 to 32 ui nt 32 i nt 32

−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 719: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 719/870

7-438

uencode

Now look at saturation effects when you under specify the peak value for theinput.

u = [ - 2: 0. 5: 2] ;

y = uencode( u, 5, 1)

y =

0 0 0 8 16 24 31 31 31

Now look at the output for

u = [ - 2: 0. 5: 2] ;

y = uencode( u, 5, 2, ' si gned' )

y =

- 8 - 4 0 4 8 12 16 20 23

Algorithm uencode maps thefloating-point input value to an integer value determined bythe requirement for 2n levels of quantization. This encoding adheres to the

definition for uniform encoding specified in I TU-T Recommendation G.701. The input range [ - v, v] is divided into 2n evenly spaced intervals. I nputentries in therange [ - v, v] are first quantized according to this subdivision of theinput range, and then mapped tooneof 2n integers. The rangeof theoutputdepends on whether or not you specify that you want signed integers.

See Also udecode Decode 2n-level quantized integers to floating-point.

References General Aspects of Digital T ransmission Systems: Vocabulary of Digital

Transmission and Multiplexing, and Pulse CodeModulation (PC M) Terms,I nternational Telecommunication Union, I TU-T Recommendation G.701,March, 1993.

Page 720: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 720/870

7-439

unwrap

7unwrapPurpose Unwrap phase angles.

Syntax p = unwr ap( p)

Description p = unwr ap( p) corrects the phase angles in vector p by adding multiples of , where needed, to smooth the transitions across branch cuts. When p is a

matrix, unwr ap corrects the phase angles down each column. The phase must

be in radians.

The unwr ap function is part of the standard MAT LAB language.

Limitations unwr ap tri es to detect branch cut crossings, but it can be fooled by sparse,rapidly changing phase values.

See Also

2π±

abs Absolute value (magnitude).

angl e Phase angle.

Page 721: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 721/870

7-440

upfirdn

7upfirdnPurpose Upsample, apply an FI R fi lter, and downsample.

Syntax yout = upf i rdn(x i n, h)

yout = upf i rdn(x i n, h, p)

yout = upf i rdn(x i n, h, p, q)

[ yout , zf ] = upf i r dn( xi n, h, . . . , zi )

Description upf i r dn performs a cascade of three operations:

1 Upsampling the input data in the matrix xi n by a factor of the integer p

(inserting zeros)

2 FI R filteringtheupsampled signal data with theimpulseresponsesequencegiven in the vector or matrix h

3 Downsampling the result by a factor of the integer q (throwing away

samples)upf i r dn has been implemented as a ME X-file for maximum speed, soonly theoutputs actually needed are computed. The FI R filter is usually a lowpassfilter, which you must design using another function such as r emez or f i r 1.

Note The function r esampl e performs an FI R design using f i r l s, followedby rate changing implemented with upf i r dn.

yout = upf i rdn(x i n, h) filters theinput signal xi n with theF I R filter havingimpulse responseh. I f xi n is a row or column vector, then it represents a singlesignal. I f xi n is a matrix, then each column is filtered independently. I f h is a

row or column vector, then it represents one FI R filter. I f h is a matrix, theneach column is a separate FI R impulse response sequence. I f yout is a row or

column vector, then it represents one signal. I f yout is a matrix, then eachcolumn is a separate output. No upsampling or downsampling is implementedwith this syntax.

yout = upf i rdn(x i n, h, p) specifies the integer upsampling factor p, where p

has a default value of 1.

Page 722: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 722/870

7-441

upfirdn

yout = upf i rdn( xi n, h, p, q) specifies the integer downsampling factor q,where q has a default value of 1.

[ yout , zf ] = upf i r dn( xi n, h, . . . , zi ) specifies initial state conditions in thevector zi .

The sizeof theinitial condition vector zi must bethesameas l engt h( h) - 1,thenumber of delays in the FI R filter.

When xi n is a vector, the size of the final condition vector zf is l engt h( h) - 1,the number of delays in the filter. When xi n is a matrix, zf is an matrix with( l engt h( h) - 1) rows and ( s i ze(x i n, 2) ) columns.

Note Since upf i r dn performs convolution and rate changing, the yout

signals have a different length than xi n. The number of rows of yout is

approximately p/ q times the number of rows of xi n.

Remarks Usually thei nputs xi n and the filter h are vectors, in which case only oneoutput signal is produced. However, when these arguments are arrays, eachcolumn is treated as a separate signal or filter. Valid combinations are:

1 xi n is a vector and h is a vector.

There is one filter and one signal, so the function convolves xi n with h. Theoutput signal yout is a row vector if xi n is a row;otherwise, yout is a column

vector.

2 xi n is a matrix and h is a vector.

There is one filter and many signals, so the function convolves h with eachcolumn of xi n. The resulting yout will be an matrix with the same numberof columns as xi n.

3 xi n is a vector and h is a matrix.

There aremany filters and onesignal, sothefunction convolves each columnof h with xi n. The resultingyout will bean matrix with thesame number of columns as h.

Page 723: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 723/870

7-442

upfirdn

4 xi n is a matrix and h is a matrix, both with the same number of columns.

There are many filters and many signals, so the function convolvescorresponding columns of xi n and h. The resulting yout is an matrix withthe same number of columns as xi n and h.

Examples If both p and q are equal to 1 (that is, there is no rate changing), the result isordinary convolution of two signals (equivalent to conv).

yy = upf i rdn( xx, hh) ;

This example implements a seven-channel filter bank by convolving sevendifferent fil ters with one input signal, then downsamples by five.

% Assume t hat hh i s an L- by- 7 ar r ay of f i l t er s.

yy = upf i rdn( xx, hh, 1, 5) ;

I mplement a rate change from 44.1 kHz (CD sampling rate) to 48 kHz (DATrate), a ratio of 160/147. This requires a lowpass filter with cutoff frequency atωc =2π/160.

% Desi gn l owpass f i l t er wi t h cut of f at 1/ 160t h of f s.

hh = f i r 1( 300, 2/ 160) ; % Need a ver y l ong l owpass f i l t er

yy = upf i r dn( xx, hh, 160, 147) ;

I n this example, thefilter design and resampling areseparatesteps. Notethatr esampl e would do both steps as one.

Algorithm upf i r dn uses a polyphaseinterpolation structure. Thenumber of multiply-add

operations in the polyphase structure is approximately (LhL x-pL x)/q where L h

and L x are the lengths of h[n] and x[n], respectively.

A more accurate flops count is computed in the program, but the actual countis still approximate. For l ong signals x[n], the formula is quite often exact.

Page 724: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 724/870

7-443

upfirdn

See Also

References [1] Crochiere, R.E., and L.R. Rabiner, Multi-Rate Signal Processing,Prentice-Hall, Englewood Cliffs, NJ , 1983, pp. 88-91.

[2] Crochiere, R.E ., “A General Program to Perform Sampling Rate Conversion

of Data by Rational Ratios,” Programs for Di gital Signal P rocessing, I E E EPress, New York, 1979, pp. 8.2-1 to 8.2-7.

conv Convolution and polynomial multiplication.

deci mat e Decrease the sampling rate for a sequence(decimation).

f i l t er Filter data with a recursive (II R) or nonrecursive

(FI R) filter.

i nterp I ncrease sampling rate by an integer factor

(interpolation).i nt f i l t Interpolation FIR filter design.

r esampl e Change sampling rate by any rational factor.

Page 725: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 725/870

7-444

vco

7vcoPurpose Voltage controlled oscil lator.

Syntax y = vco( x, f c, f s )

y = vco( x, [ Fmi n Fmax] , f s)

Description y = vco( x, f c, f s ) creates a signal that oscillates at a frequency determined

by thereal input vector or array x with sampling frequency f s. f c is thecarrier

or reference frequency; when x is 0, y is an f c Hz cosine with amplitude 1sampled at f s Hz. x ranges from - 1 to 1, where x =- 1 corresponds to0 frequency output, x =0 corresponds to f c, and x =1 corresponds to 2*f c.Output y is the same size as x.

y = vco( x, [ Fmi n Fmax] , f s ) scales the frequency modulation range so that

±1 values of x yield oscillations of Fmi n Hz and Fmax Hz respectively. F or bestresults, Fmi n and Fmax should be in the range 0 to f s / 2.

By default, f s is 1 and f c is f s / 4.

I f x is a matrix, vco produces a matrix whosecolumns oscillate according to the

columns of x.

Example Generate two seconds of a signal sampled at 10,000 samples/second whose

instantaneous frequency is a triangle function of time.

f s = 10000;t = 0: 1/ f s : 2;

x = vco( sawt oot h( 2*pi * t , 0. 75) , [ 0. 1 0. 4] * f s , f s) ;

Plot the spectrogram of the generated signal.

specgr am( x, 512, f s, kai ser ( 256, 5) , 220)

Page 726: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 726/870

7-445

vco

Algorithm vco performs FM modulation using the modul at e function.

Diagnostics I f any values of x lie outside [-1, 1], vco gives the following error message.

X out si de of r ange [- 1, 1] .

See Also

Time

F r e q u e n c y

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.80

500

1000

1500

2000

2500

3000

3500

4000

4500

5000

demod Demodulation for communications simulation.

modul at e Modulation for communications simulation.

Page 727: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 727/870

7-446

xcorr

7xcorrPurpose Estimate the cross-correlation function.

Syntax c = xcor r ( x, y)

c = xcor r ( x)

c = xcor r ( x, y, ' opt i on' )

c = xcor r ( x, ' opt i on' )

c = xcorr ( x, y, maxl ags)

c = xcor r( x, maxl ags)

c = xcorr ( x, y, maxl ags, ' opt i on' )

c = xcorr ( x, maxl ags, ' opt i on' )

[ c, l ags] = xcor r ( . . . )

Description xcorr estimates the cross-correlation sequence of a random process.Autocorrelation is handled as a special case.

The true cross-correlation sequence is

where xn and yn arejointly stationary random processes, , and E ·is the expected value operator. xcor r must estimate the sequence because, inpractice, only a finite segment of one realization of the infinite-length randomprocess is available.

c = xcor r ( x, y) returns the cross-correlation sequence in a length 2*N-1vector, where x and y are length N vectors (N>1). I f x and y are not the same

length, the shorter vector is zero-padded to the length of the longer vector.

By default, xcor r computes raw correlations with no normali zation.

The output vector c has elements given by c(m) = cxy(m-N), m=1, ..., 2N-1.

R xy m( ) E xn m+y*n E xny*n m– ==

∞– n ∞< <

R xy m( )

xn m+

yn

*

n 0=

N m– 1–

åm

0≥

yx*

m–( ) m 0<î

=

Page 728: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 728/870

7-447

I n general, the correlation function requires normali zation to produce anaccurate estimate (see below).

xcorr

c = xcor r ( x) is the autocorrelation sequence for the vector x. I f x isan N-by-P

matrix, c is a matrix with 2N-1 rows whoseP 2 columns contain the

cross-correlation sequences for all combinations of the columns of x.

c = xcor r ( x, y, ' opt i on' ) specifies a normali zation option for thecross-correlation, where ' opt i on' is:

• ' bi ased' : Biased estimate of the cross-correlation function

• ' unbi ased' : Unbiased estimate of the cross-correlation function

• ' coef f ' : Normalizes the sequence so the autocorrelations at zero lag areidentically 1.0

• ' none' , to use the raw, unscaled cross-correlations (default)

See reference [1] for more information on the properties of biased andunbiasedcorrelation estimates.

c = xcor r ( x, ' opt i on' ) specifies one of the above normali zation options for

the autocorrelation.

c = xcor r ( x, y, maxl ags) returns the cross-correlation sequence over the lagrange [ - maxl ags: maxl ags] . Output c has length 2*maxl ags+1.

c = xcor r ( x, maxl ags) returns the autocorrelation sequence over the lagrange [ - maxl ags: maxl ags] . Output c has length 2*maxl ags+1. I f x is an

N-by-P matrix, c is a matrix with 2*maxl ags+1 rows whoseP2 columns containthe autocorrelation sequences for all combinations of the columns of x.

c = xcorr ( x, y, maxl ags, ' opt i on' ) specifies both a maximumnumber of lagsand a scaling option for the cross-correlation.

c = xcorr ( x, maxl ags, ' opt i on' ) specifies both a maximum number of lagsand a scaling option for the autocorrelation.

cxy biased, m( )1N----cxy m( )=

cxy unbiased, m( )1

N m–-------------------cxy m( )=

Page 729: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 729/870

7-448

xcorr

[ c, l ags] = xcor r ( . . . ) returns a vector of the lag indices at which c wasestimated, with the range [ - maxl ags: maxl ags] . When maxl ags is not

specified, the range of l ags is [ - N+1: N- 1] .

I n all cases, the cross-correlation or autocorrelation computed byxcor r has thezeroth lag in themiddle of thesequence, at element or row maxl ags+1 (elementor row N if maxl ags is not specified).

Examples The second output, l ags, is useful for plotting the cross-correlation orautocorrelation. For example, the estimated autocorrelation of zero-meanGaussian white noise cww(m) can be displayed for -10 ≤ m ≤ 10 using

ww = r andn( 1000, 1) ;

[ c_ww, l ags] = xcorr ( ww, 10, ' coef f ' ) ;

st em( l ags, c_ww)

Swapping the x and y input arguments reverses (and conjugates) the outputcorrelation sequence. For row vectors, the resulting sequences are reversed leftto right; for column vectors, up and down. The following example illustratesthis property (mat 2st r is used for a compact display of complex numbers).

x = [ 1, 2i , 3] ; y = [ 4, 5, 6] ;

[ c 1, l ags] = xcor r ( x, y) ;

c1 = mat2str ( c1, 2) , l ags

c1 =

[ 6- i *8. 9e- 016 5+i *12 22+i *10 15+i *8 12+i *8. 9e- 016]l ags =

- 2 - 1 0 1 2c2 = conj ( f l i pl r ( xcor r ( y, x) ) ) ;

c2 = mat 2str ( c2, 2)

c2 =

[ 6- i *8. 9e- 016 5+i *12 22+i *10 15+i *8 12+i *8. 9e- 016]

For the case where input argument x is a matrix, the output columns arearranged so that extracting a row and rearranging it into a square arrayproduces the cross-correlation matrix corresponding to the lag of the chosenrow. For example, the cross-correlation at zero lag can be retrieved by

r andn( ' state' , 0)

X = randn( 2, 2) ;

Page 730: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 730/870

7-449

[ M, P] = si ze( X) ;

c = xcor r ( X) ;

xcorr

c0 = zeros (P) ; c0( : ) = c(M, : ) % Ext r act zero- l ag row

c0 =

2. 9613 - 0. 5334

- 0. 5334 0. 0985

You can calculate the matrix of correlation coefficients that the MAT L ABfunction cor r coef generates by substituting

c = xcov(X, ' coef ' )

in the last example. The function xcov subtracts the mean and then calls

xcorr .

Usef f t shi f t tomovethe second half of thesequence startingat thezeroth lagto the front of the sequence. f f t shi f t swaps the first and second halves of asequence.

Algorithm For more information on estimating covariance and correlation functions, see[1].

See Also

References [1] Orfanidis, S.J ., Optimum Signal Pr ocessing. An I ntroduction. 2nd Edition,Prentice-Hall, Englewood Cliffs, NJ , 1996.

conv Convolution and polynomial multiplication.

cor r coef Compute a correlation coefficient matrix.

cov Compute a covariance matrix.

xcorr2 Estimate the two-dimensional cross-correlation.xcov Estimate the cross-covari ance.

Page 731: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 731/870

7-450

xcorr2

7xcorr2Purpose Estimate the two-dimensional cross-correlation.

Syntax C = xcorr 2( A)

C = xcorr 2( A, B)

Description C = xcorr 2( A, B) returns the cross-correlation of matrices A and B with no

scaling. xcorr2 is the two-dimensional version of xcor r . I t has its maximum

value when the two matrices are aligned sothat they are shaped as similarlyas possible.

xcor r 2( A) is the autocorrelation matrix of input matrix A. I t is identical toxcor r 2( A, A) .

See Also conv2 Compute the two-dimensional convolution.

f i l t er 2 Filter two-dimensional data.

xcor r Estimate the cross-correlation function.

Page 732: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 732/870

7-451

xcov

7xcovPurpose Estimate the cross-covariance function (mean-removed cross-correlation).

Syntax v = xcov(x, y)

v = xcov(x)

v = xcov(x, ' opt i on' )

[ c, l ags] = xcov( x, y, maxl ags)

[ c, l ags] = xcov( x, maxl ags)

[ c, l ags] = xcov( x, y, maxl ags, ' opt i on' )

Description xcov estimates the cross-covariance sequence of random processes.Autocovariance is handled as a special case.

The true cross-covariance sequence is the cross-correlation of mean-removedsequences

where and are themean values of thetwo stationary random processes,and E·is the expected value operator. xcov estimates the sequence because,in practice, access is available to only a finite segment of the infinite-lengthrandom process.

v = xcov(x, y) returns the cross-covariance sequence in a length 2N-1 vector,

where x and y are length N vectors.

v = xcov(x) is the autocovariance sequence for the vector x. Where x is anN-by-P array, v = xcov(x ) returns an array with 2N-1 rows whoseP 2columnscontain the cross-covari ance sequences for all combinations of the columnsof x.

By default, xcov computes raw covariances with no normalization. For alength N vector

h h l i b ( )

φxy µ( ) E xn m+ µx–( ) yn µy–( )* =

µx µy

cxy m( )

x n m+( )1N---- xi

i 0=

N 1–

å–

è ø

yn* 1

N---- yi

*

i 0=

N 1–

å–

è ø

n 0=

N m– 1–

å m 0≥

cyx* m–( ) m 0<

=

Page 733: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 733/870

7-452

The output vector c has elements given by c( m) =cxy(m-N), m =1, ..., 2N-1.

xcov

The covariance function requires normalization to estimate the functionproperly.

v = xcov( x, ' opt i on' ) specifies a scaling option, where ' opt i on' is:

• ' bi ased' , for biased estimates of the cross-covariance function

• ' unbi ased' , for unbiased estimates of the cross-covariance function

•' coef f ' , to normalize the sequence so the auto-covariances at zero lag areidentically 1.0

• ' none' , to use the raw, unscaled cross-covariances (default)

See [1] for more information on the properties of biased and unbiasedcorrelation and covariance estimates.

[ c, l ags] = xcov( x, y, maxl ags) where x and y are length mvectors, returns

the cross-covariance sequence in a length 2*maxl ags+1 vector c. l ags is avector of the lag indices where c was estimated, that is, [ - maxl ags: maxl ags] .

[ c, l ags] = xcov( x, maxl ags) is the autocovariance sequence over the rangeof lags [ - maxl ags: maxl ags] .

[ c, l ags] = xcov( x, maxl ags) wherex isan m-by-p array, returns arrayc with2*maxl ags+1 rows whose P2 columns contain the cross-covariance sequences

for all combinations of the columns of x.

[ c , l ags] = xcov( x, y, maxl ags, ' opt i on' ) specifies a scaling option, where' opt i on' is the last input argument.

In all cases, xcov gives an output such that the zeroth lag of the covariancevector is in the middle of the sequence, at element or row maxl ag+1 or at m.

Examples The second output l ags is useful when plotting. For example, the estimated

autocovariance of uniform white noise cww(m) can bedisplayed for -10 ≤ m ≤ 10using

ww = r andn( 1000, 1) ; % Gener at e uni f or m noi se wi t h mean = 1/ 2.

[ cov_ww, l ags] = xcov( ww, 10, ' coef f ' ) ;

st em( l ags, cov_ww)

Page 734: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 734/870

7-453

xcov

Algorithm xcov computes the mean of its inputs, subtracts the mean, and then calls

xcorr . For more information on estimating covariance and correlationfunctions, see [1].

Diagnostics xcov does not check for any errors other than the correct number of input

arguments. I nstead, it relies on the error checking in xcorr .

See Also

References [1] Orfanidis, S.J ., Optimum Signal Pr ocessing. An I ntroduction. 2nd Edition,Prentice-Hall, Englewood Cliffs, NJ , 1996.

conv I mplement convolution and polynomialmultiplication.

cor r coef Compute the correlation coefficient matrix.

cov Compute the covariance matrix.

xcorr Estimate the cross-correlation function.

xcorr2 Estimate the two-dimensional cross-correlation.

Page 735: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 735/870

7-454

yulewalk

7yulewalkPurpose Recursive digital filter design.

Syntax [b, a] = yul ewal k(n, f , m)

Description yul ewal k designs recursive I I R digital filters using a least-squares fit to aspecified frequency response.

[b, a] = yul ewal k(n, f , m) returns row vectors b and a containing the n+1coefficients of the order n I I R fil ter whosefrequency-magnitude characteristicsapproximately match those given in vectors f and m:

• f is a vector of frequency points, specified in the range between 0 and 1,where 1 corresponds to half the sample frequency (the Nyquist frequency). The first point of f must be 0 and the last point 1, with all intermediatepoints in increasing order. Duplicate frequency points are allowed,

corresponding to steps in the frequency response.• mis a vector containing the desired magnitude response at the points

specified in f .

• f and mmust be the same length.

• pl ot ( f , m) displays the filter shape.

The output filter coefficients are ordered in descending powers of z.

When specifying the frequency response, avoid excessively sharp transitionsfrom passband to stopband. You may need to experiment with the slope of thetransition region to get the best fil ter design.

Example Design an 8th-order lowpass filter andoverplot thedesiredfrequency response

with the actual frequency response.f = [0 0. 6 0. 6 1] ;

m = [ 1 1 0 0] ;

[ b, a] = yul ewal k( 8, f , m) ;

[ h, w] = f reqz(b, a, 128) ;

pl ot ( f , m, w/ pi , abs (h) , ' - - ' )

l egend( ' I deal ' , ' yul ewal k Desi gned' )

B z( )A z( )----------- b 1( ) b 2( )z 1–

Lb n 1+( )z n–+ + +

a 1( ) a 2( )z 1–L a n 1+( )z n–+ + +

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

Page 736: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 736/870

7-455

g y g

t i t l e( ' Compari son of Frequency Response Magni t udes' )

yulewalk

Algorithm yul ewal k performs a least-squares fit in the time domain. I t computes thedenominator coefficients using modified Yule-Walker equations, withcorrelation coefficients computed by inverse Fourier transformation of thespecified frequency response. To compute the numerator, yul ewal k takes thefollowing steps:

1 Computes a numerator polynomial corresponding to an additivedecomposition of the power frequency response.

2 Evaluates the complete frequency responsecorresponding to the numeratorand denominator polynomials.

3 Uses a spectral factorization techniquetoobtain the impulseresponseof thefilter.

4 Obtains the numerator polynomial by a least-squares fit to this impulseresponse.

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

0.2

0.4

0.6

0.8

1

1.2

1.4Comparison of Frequency Response Magnitudes

Idealyulewalk Designed

Page 737: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 737/870

7-456

yulewalk

See Also

References [1] Friedlander, B., and B. Porat, “The Modified Yule-Walker Method of ARM A

Spectral Estimation,” I EEE Transactions on Aerospace Electronic Systems,AE S-20, No. 2 (March 1984), pp. 158-173.

but t er Butterworth analog and digital filter design.

cheby1 Chebyshev type I filter design (passband ripple).

cheby2 Chebyshev type I I filter design (stopband ripple).

el l i p Elliptic (Cauer) filter design.

f i r 2 Window-based finite impulse response filter design –arbitrary response.

f i r l s L east square linear-phase F I R filter design.

maxf l at Generalized digital Butterworth filter design.

r emez Parks-McClellan optimal FIR filter design.

Page 738: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 738/870

7-457

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 ' , ' scal e' )

sos = zp2sos( . . . )

Description zp2sos converts a discrete-timezero-pole-gain representation of a given digitalfilter to an equivalent second-order section representation.

Use [sos , g] = zp2sos(z , p, k) to obtain a matrix sos in second-order section

form with gain g equivalent to the discrete-time zero-pole-gain fi lterrepresented by input arguments z, p, and k. Vectors z and p contain the zerosand poles of the filter’s transfer function H(z), not necessarily in any particularorder.

where n and m are the lengths of z and p, respectively, and k is a scalar gain. The zeros and poles must be real or complex conjugate pairs. sos is an L -by-6matrix

whose rows contain the numerator and denominator coefficients bik and aik of the second-order sections of H(z).

The number L of rows of the matrix sos is the closest integer greater than or

equal to the maximum of n/2 and m/2.

H z( ) kz z1–( ) z z2–( )L z zn–( )

z p1–( ) z p2–( )L z pm–( )--------------------------------------------------------------------=

sos

b01 b11 b21 1 a11 a21

b02 b12 b22 1 a12 a22

b0L b1L b2L 1 a1L a2L

=

H z( ) g H k z( )

k 1=

L

∏ gb0k b1kz 1– b2kz 2–+ +

1 a1kz 1– a2kz 2–+ +----------------------------------------------------------

k 1=

L

∏= =

Page 739: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 739/870

7-458

zp2sos

[ sos, g] = zp2sos (z ,p, k, ' order ' ) specifies the order of the rows in sos,where ' order ' is:

• ' down' , toorder thesections sothe first row of sos contains the poles closestto the unit circle

• ' up' , to order thesections sothe first row of sos contains the poles farthestfrom the unit circle (default)

[ sos, g] = zp2sos (z ,p, k, ' order ' , ' scal e' ) specifies the desired scaling of the gain and the numerator coefficients of all second-order sections, where' scal e' is:

• ' none' , to apply no scaling (default)

• ' i nf ' , to apply infinity-norm scaling

• ' t wo' , to apply 2-norm scaling

Using infinity-norm scaling in conjunction with up-ordering minimizes theprobability of overflow in the realization. Using 2-norm scaling in conjunctionwith down-ordering minimizes the peak round-off noise.

sos = zp2sos( . . . ) embeds the overall system gain, g, in the first section,H1(z), so that

Example Find a second-order section form of a Butterworth lowpass filter.

[ z , p, k] = but t er (5, 0. 2) ;

sos = zp2sos(z , p, k) ;

H z( ) H k z( )

k 1=

L

∏=

Page 740: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 740/870

7-459

zp2sos

Algorithm zp2sos uses a four-step algorithm to determine the second-order section

representation for an input zero-pole-gain system:

1 I t groups the zeros and poles into complex conjugate pairs using thecpl xpai r function.

2 I t forms the second-order section by matching the pole and zero pairsaccording to the following rules:

a Match the poles closest to the unit circle with the zeros closest to thosepoles.

b Match the poles next closest to the unit circle with the zeros closest tothose poles.

c Continue until all of the poles and zeros are matched.

zp2sos groups real poles into sections with the real poles closest to them inabsolute value. The same rule holds for real zeros.

3 I t orders thesections accordingto theproximity of thepole pairs to theunitcircle. zp2sos normally orders the sections with poles closest to the unit

circle last in the cascade. You can tell zp2sos to order the sections in thereverse order by specifying the down flag.

4 zp2sos scales the sections by the norm specified in the ' scal e' argument.For arbitrary H(ω), the scaling is defined by

where p can be either ∞ or 2. See the references for details on the scaling. This scaling is an attempt to minimize overflow or peak round-off noise in

fixed point filter i mplementations.

H p1

2π------ H ω( ) p ωd

0

ò

1p---

=

Page 741: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 741/870

7-460

zp2sos

See Also

References [1] J ackson, L .B., Digital Fil ters and Signal Pr ocessing, 3rd ed., K luwerAcademic Publishers, Boston, 1996, Chapter 11.

[2] Mitra, S.K ., Digital Si gnal Processing: A Computer-B ased Approach,McGraw-Hill, New York, 1998, Chapter 9.

[3] Vaidyanathan, P.P., “Robust Digital Filter Structures,” Handbook for

Digital Signal Processing, S.K . Mitra and J .F. K aiser, ed., J ohn Wiley & Sons,New York, 1993, Chapter 7.

cpl xpai r Group complex numbers into complex conjugatepairs.

sos2zp Convert digital filter second-order sectionparameters to zero-pole-gain form.

ss2sos Convert digital filter state-space parameters tosecond-order sections form.

t f 2sosConvert digital fil ter transfer function parameters tosecond-order sections form.

zp2ss Convert zero-pole-gain filter parameters tostate-space form.

zp2t f Convert zero-pole-gain filter parameters to transferfunction form.

Page 742: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 742/870

7-461

zp2ss

7zp2ssPurpose Convert zero-pole-gain filter parameters to state-space form.

Syntax [ A, B, C, D] = zp2ss(z , p, k)

Description zp2ss converts a zero-pole-gain representation of a given system to anequivalent state-space representati on.

[ A, B, C, D] = zp2ss(z , p, k) finds a single input, multiple output, state-spacerepresentation

given a system in factored transfer function form.

Column vector p specifies the pole locations, and matrix z the zero locationswith as many columns as there are outputs. The gains for each numeratortransfer function are in vector k. The A, B, C, and Dmatrices are returned incontroller canonical form.

I nf values may be used as place holders in z if some columns have fewer zeros

than others.

Algorithm zp2ss, for single-input systems, groups complex pairs together into two-by-twoblocks down the diagonal of the A matrix. This requires the zeros and poles to

be real or complex conjugate pairs.

x· Ax B u+=

y Cx Du+=

H s( )

Z s( )

P s( )---------- k

s z1–( ) s z2–( )L s zn–( )

s p1–( ) s p2–( )L

s pn–( )------------------------------------------------------------------= =

Page 743: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 743/870

7-462

zp2ss

See Also sos2ss Convert digital filter second-order sectionparameters to state-space form.

ss2zp Convert state-space filter parameters tozero-pole-gain form.

t f 2ss Convert transfer function filter parameters tostate-space form.

zp2sos Convert digital filter zero-pole-gain parameters tosecond-order sections form.

zp2t f Convert zero-pole-gain filter parameters to transferfunction form.

Page 744: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 744/870

7-463

zp2tf

7zp2tf Purpose Convert zero-pole-gain filter parameters to transfer function form.

Syntax [ b, a] = zp2t f ( z , p, k)

Description zp2t f forms transfer function polynomials fromthe zeros, poles, and gains of asystem in factored form.

[ b, a] = zp2t f ( z , p, k) finds a rational transfer function

given a system in factored transfer function form

Column vector p specifies the pole locations, and matrix z specifies the zerolocations, with as many columns as there are outputs. The gains for eachnumerator transfer function are in vector k. The zeros and poles must be realor come in complex conjugate pairs. The polynomial denominator coefficientsare returned in row vector a and the polynomial numerator coefficients arereturned in matrix b, which has as many rows as there are columns of z.

I nf values can be used as place holders in z if some columns have fewer zerosthan others.

Algorithm The system is converted to transfer function form using pol y with p and thecolumns of z.

B s( )

A s( )-----------

b1s nb 1–( )L b nb 1–( )s bnb+ + +

a1s na 1–( )L a na 1–( )s ana+ + +

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

H s( )Z s( )

P s( )

---------- ks z1–( ) s z2–( )L s zm–( )

s p1–( ) s p2–( )L

s pn–( )

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

Page 745: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 745/870

7-464

zp2tf

See Also sos2t f Convert digital filter second-order sectionparameters to transfer function form.

ss2tf Convert state-space filter parameters to transferfunction form.

t f 2zp Convert transfer function filter parameters tozero-pole-gain form.

zp2sos Convert digital filter zero-pole-gain parameters tosecond-order sections form.

zp2ss Convert zero-pole-gain filter parameters tostate-space form.

Page 746: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 746/870

7-465

zplane

7zplanePurpose Zero-pole plot.

Syntax zpl ane( z, p)

zpl ane( b, a)

[ hz , hp, ht ] = zpl ane( z , p)

Description This function displays the poles and zeros of discrete-time systems.

zpl ane( z, p) plots thezerosspecified in column vector z and the polesspecifiedin column vector p in the current figure window. The symbol ' o' represents azero and the symbol ' x' represents a pole. The plot includes the unit circle forreference. I f z and p arearrays, zpl ane plots thepoles and zeros in thecolumnsof z and p in different colors.

You can override the automatic scaling of zpl ane using

axi s( [ xmi n xmax ymi n ymax] )

or

set ( gca, ' yl i m' , [ ymi n ymax])

or

set ( gca, ' xl i m' , [ xmi n xmax])

after calling zpl ane. This is useful in the case where one or a few of the zerosor poles have such a large magnitude that the others are grouped tightlyaround the origin and are hard to distinguish.

zpl ane( b, a) where b and a are row vectors, first uses roots to find the zerosand poles of the transfer function represented by numerator coefficients b anddenominator coefficients a.

[ hz , hp, ht ] = zpl ane( z , p) returns vectors of handles to the zero lines, hz,and the pole lines, hp. ht is a vector of handles to the axes/unit circle line and

to text objects, which are present when there are multiple zeros or poles. I f there are no zeros or no poles, hz or hp is the empty matrix [ ] .

Page 747: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 747/870

7-466

zplane

Examples Plot the poles and zeros of a 5th-order Butterworth lowpass digital filter with

cutoff frequency of 0.2.

[ z , p, k] = but t er (5, 0. 2) ;

zpl ane( z, p) ;

t i t l e( ' 5t h- Or der But t er wor t h Lowpass Di gi t al Fi l t er ' ) ;

To generate the same plot with a transfer function representation of the filter,

use the following commands.

[ b, a] = but t er ( 5, 0. 2) ; % Trans fer f unct i on

zpl ane( b, a)

See Also

−1 −0.5 0 0.5 1

−1

−0.8

−0.6

−0.4

−0.2

0

0.2

0.4

0.6

0.8

1

5

Real Part

I m a

g i n a r y P a r t

5th−Order Butterworth Lowpass Digital Filter

f r eqz Frequency response of digital filters.

Page 748: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 748/870

7-467

zplane

Page 749: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 749/870

7-468

8

Filter Design and Analysis Tool Reference

Page 750: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 750/870

8 Filter Design and Analysis Tool Reference

Filter Design and Analysis GUI Overview

Choose an analysis method for

analyzing your filter design.

Choose the type of filter

you want to design.

Choose the filter design

method you want to use

PressDesign Filterto

compute your filtercoefficients.

Select theWhat’s this?button and click on a region

of the GUI to access context-sensitive help.

Set quantization

parameters for the FilterDesign Toolbox.

Set filter specifications. These depend on

the type of filter you are designing, aswell as the design method you specify.

Specify a filter order orallowit to be estimated.

Zoomin/out.

Use theFiltermenu tochoose between importing

filter coefficients fromthe

MATLAB workspace anddesigning the filter in the

GUI.

Set windowspecificationsfor the FIRWindow

design.

Check this box to quantize

the current filter using theFilter Design Toolbox.

Page 751: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 751/870

8-2

Display Region

Display Region

The following are displayed in this region:

• The filter specifications. These are initially displayed when you open theGUI.

• The magnitude response plot

•The phase response plot

• The frequency response plots (both magnitude and phase)

• The group delay response plot

• The impulse response plot

• The step response plot

• The pole-zero plot

• The filter coefficients

The plot that is displayed depends on which of the following buttons you’veselected on the toolbar.

Page 752: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 752/870

8-3

8 Filter Design and Analysis Tool Reference

Display Region: Filter Specifications

The Filter Specifications plot is displayed when the Filter Specifications

option is selected in the Analysis menu, or when the corresponding toolbarbutton is selected.

The plot displays a schematic of the filter parameters (such as F pass and F stop)that can be specified in the Design Filter region. The axes use the unitscurrently selected in the Units menus of the F requency Specifications andMagnitude Specifications regions.

The plot does not reflect the actual values of the filter specifications.

Filter Specificationsbutton

Page 753: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 753/870

8-4

Display Region: Magnitude Response

Display Region: Magnitude Response

The Magnitude Response plot i s displayed when the Magnitude Response

option is selected in the Analysis menu, or when the corresponding toolbarbutton is selected.

The plot shows the actual magnituderesponse of the current filter. See f r eqz

and f r eqzpl ot for more information.

Magnitude Responsebutton

Page 754: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 754/870

8-5

8 Filter Design and Analysis Tool Reference

Display Region: Phase Response

The Phase Response plot i s displayed when the Phase Response option isselected in the Analysis menu, or when the corr esponding toolbar button isselected.

The plot shows the actual phase response of the current filter. See f r eqz andf r eqzpl ot for more information.

Phase Responsebutton

Page 755: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 755/870

8-6

Display Region: Magnitude and Phase Response

Display Region: Magnitude and Phase Response

The Magnitude and PhaseResponseplot is displayed when the Magnitude

and Phase option is selected in theAnalysis menu, or when the correspondingtoolbar button is selected.

The plot superposes the magnitude response and the phase response of thecurrent filter. See f r eqz and f r eqzpl ot for more information.

Magnitude and Phase Responsebutton

Page 756: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 756/870

8-7

8 Filter Design and Analysis Tool Reference

Display Region: Group Delay

The Group Delay plot is displayed when the Group Delay option is selected inthe Analysis menu, or when the corresponding toolbar button is selected.

The plot shows the group delay of the current filter. See gr pdel ay for moreinformation.

Group Delaybutton

Page 757: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 757/870

8-8

Display Region: Impulse Response

Display Region: Impulse Response

The I mpulse Response plot is displayed when the Impulse Responseoption isselected in the Analysis menu, or when the corresponding toolbar button isselected.

The plot shows the impulse response of the current filter. See i mpz for moreinformation.

Impulse Responsebutton

Page 758: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 758/870

8-9

8 Filter Design and Analysis Tool Reference

Display Region: Step Response

The Step Responseplot is displayed when theStep Response option is selectedin the Analysis menu, or when the corresponding toolbar button is selected.

The plot shows the step response of the current filter.

Step Responsebutton

Page 759: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 759/870

8-10

Display Region: Pole/ Zero Plot

Display Region: Pole/ Zero Plot

The Pole/Zero plot is displayed when the Pole/Zero Plot option is selected inthe Analysis menu, or when the corresponding toolbar button is selected.

The plot shows the pole and zero locations of the current filter on the z-plane.See zpl ane for more information.

Pole/ Zero Plotbutton

Page 760: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 760/870

8-11

8 Filter Design and Analysis Tool Reference

Display Region: Filter Coefficients

The Filter Coefficients viewer is displayed when View Filter C oefficients isselected in the Analysis menu, or when the corr esponding toolbar button isselected.

The text box lists the coefficients of the current fi lter, which depend on thefilter structure (e.g., direct form, lattice, etc.). Use the Convert structure

button to transform a filter from one structure to another, or use the I mportFilter Coefficients region to directly import a filter with the desired structure.

Filter Coefficientsbutton

Page 761: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 761/870

8-12

Filter Type Region

Filter Type Region

Choose a filter type from the five mutually exclusive radio buttons:

• Lowpass

• Highpass

• Bandpass

• Bandstop

• A menu listing other filter types:

- Differentiator (r emez , f i r l s)

- Hilbert Transformer (r emez , f i r l s)

- Multiband (f i r l s, r emez)

- Arbitrary Magnitude (f i r l s, r emez , f i r l s)

- Arbitrary Group Delay (i i rgrpdel ay) – available only when the Filter

Design Toolbox is installed The filter type you choose is reflected in the Display region, FrequencySpecifications region, and Magnitude Specifications region.

Lowpass FiltersWhen you select this option, a lowpass filter is displayed in theDisplay region,and the Frequency Specifications and Magnitude Specifications regions are

updated with the appropriate parameters.

Seebut t er , cheby1, cheby2, el l i p, r emez , f i r l s, or f i r 1 for more information.

Page 762: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 762/870

8-13

8 Filter Design and Analysis Tool Reference

Highpass FiltersWhen you select this option, a highpassfilter is displayed in theDisplay region,and the Frequency Specifications and Magnitude Specifications regions areupdated with the appropriate parameters.

Seebut t er , cheby1, cheby2, el l i p, r emez , f i r l s, or f i r 1 for more information.

Bandpass FiltersWhen you select this option, a bandpass filter is displayed in the Displayregion, andtheFrequencySpecifications and MagnitudeSpecifications regions

are updated with the appropriate parameters.

Seebut t er , cheby1, cheby2, el l i p, r emez , f i r l s, or f i r 1 for more information.

Page 763: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 763/870

8-14

Filter Type Region

Bandstop Filters You can specify the frequencies that determine the pass band and thestopband. When you select this option, a bandstop filter is displayed in theDisplay region, and the Frequency Specifications and MagnitudeSpecifications regions are updated with the appropriate parameters.

Seebut t er , cheby1, cheby2, el l i p, r emez , f i r l s, or f i r 1 for more information.

Differentiator FiltersA differentiator filter generates the derivative of the input signal. See

“Multiband F I R F ilter Design with T ransition Bands” and r emez for moreinformation.

Hilbert Transformer FiltersA Hilbert transformer is a filter that generates an approximation of thediscrete Hilbert transform of the input signal. See “Multiband FI R FilterDesign with Transition Bands” and r emez for more information.

Multiband FiltersA multiband filter has multiple passbands interleaved with multiplestopbands. See “Multiband FI R F ilter Design with Transition Bands”andr emez for more information.

Page 764: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 764/870

8-15

8 Filter Design and Analysis Tool Reference

Arbitrary Magnitude FiltersAn arbitrary magnitudefilter can be designed to have any desired magnituderesponse shape. See“Multiband FI R Filter Design with Transition Bands”andr emez for more information.

Arbitrary Group Delay FiltersAn arbitrary group delay filter is an allpass I I R filter which provides the bestapproximation to the specified relative group-delay response in the least-pthsense. This filter type is available only when the Filter Design Toolbox isinstalled. See i i rgrpdel ay in the Filter Design Toolbox documentation formore information.

Page 765: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 765/870

8-16

Design Method Region

8 17

Design Method Region

This region allows you to select a filter design method:

• II R methods

- Butterworth (but t er)

- Chebyshev Type I (cheby1)

-Chebyshev Type II (cheby2)

- Elliptic (el l i p)

- Constrained least Pth-norm

- Least Pth-norm

• FI R methods

- Equiripple (r emez)

-

Least-Squares (f i r l s)- Window (f i r 1)

The methods that you see listed depend on the current selection in the Filter Type region:

• The Pth-norm designs are only available for the Arbitrary Magnitude andArbitrary Group Delay filter types.

• The Window design is only available for the Lowpass, Highpass,

Bandpass, and Bandstop filter type.

Page 766: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 766/870

8-17

8 Filter Design and Analysis Tool Reference

8 18

Current Filter Information Region

This region displays important information about the current filter structurebeing used by the tool:

• Filter structure indicates which of the foll owing internal representations isbeing used for the current filter:

- Direct form I

- Direct form II

- Direct form I transposed

- Direct form II transposed

- State-space

- Lattice allpass

- Lattice MA min. phase

- Lattice MA max. phase

- Lattice ARMA

• Source indicates whether the current filter was designed using FDAT ool(Designed) or imported from another source (Imported). The term

“Quantized” appears here if the filter has been quantized using the FilterDesign Toolbox.

• Order reports the order of the current filter.

• Stable indicates whether the filter is asymptotically stable ( Yes) or unstable

(No). Filters that have poles on or outside the unit circle are consideredunstable.

• Sections reports the number of sections in the current filter.

The Convert structure button opens a dialog box that allows you to choose adifferent structure for the internal filter representation.

Page 767: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 767/870

8-18

Convert Structure Button

8-19

Convert Structure Button

This button opens a dialog box where you can specify a new structure torepresent the current filter. All filters can be converted to the followingrepresentations:

• Direct form I

• Direct form II

• Direct form I transposed• Direct form II transposed

• State-space

• Lattice ARMA

I n addition, the foll owing conversions are available for particular classes of filters:

• Mi nimum phase FI R filters can be converted to Lattice MA min. phase

• Maximum phase FI R filters can be converted to Lattice MA max. phase

• Allpass filters can be converted to Lattice allpass

See “Filter Structures” for more information about any of theserepresentations.

When selected, the Use second-order sections check box instructs the tool tostore the converted filter structure as a collection of second-order sections

rather than as a monolithic higher-order structure. The subordinate Scalemenu lets you select from the foll owing options:

• None (default)

• L-2(L 2 norm)

• L-infinity (L ∞ norm)

The ordering of the second-order sections is optimized for the selected scalingoption. (The t f 2sos function that performs theconversion is called with option' down' for L 2 norm scaling, and with option ' up' for L ∞ norm scaling.)

Page 768: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 768/870

8-19

8 Filter Design and Analysis Tool Reference

8-20

Quantization Region

Select Turn quantization on to quantize the current filter using the FilterDesign Toolbox.

Page 769: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 769/870

8 20

Frequency Specifications Region

8-21

Frequency Specifications Region

The Frequency Specifications region allows you to enter frequency parametersfor thefilter design. The options available vary with theselections in theFilter Type and Design Method regions:

• L owpass

- Butterworth

- Chebyshev Type I

- Chebyshev Type I I

- Elliptic

- Equiripple

- L east-Squares

- Window

• Highpass- Butterworth

- Chebyshev Type I

- Chebyshev Type I I

- Elliptic

- Equiripple

-

L east-Squares- Window

• Bandpass

- Butterworth

- Chebyshev Type I

- Chebyshev Type I I

- Elliptic

- Equiripple

- L east-Squares

- Window

• Bandstop

- Butterworth

Page 770: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 770/870

8

8 Filter Design and Analysis Tool Reference

8-22

- Chebyshev Type I

- Chebyshev Type I I

- Elliptic

- Equiripple

- L east-Squares

- Window

•Differentiator

• Hilbert Transformer

• Multiband

• Arbitrary Magnitude

• Arbitrary Group Delay – available only when the Filter Design Toolbox isinstalled

Page 771: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 771/870

Frequency Specifications Region: Lowpass Butterworth

8-23

Frequency Specifications Region: Lowpass Butterworth

Select the units for frequency specifications from the Units list:

• Hz (default)

• kHz

• MHz

• Normalized (0 to 1), where 1 corresponds to the Nyquist frequency

I f Specify order is selected in the F ilter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• Cutoff frequency (Fc or wc) – thefrequency at which themagnituderesponseis 3 dB below the passband gain

I f Minimum order is selected in the Filter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the passband (Fpass or wpass)

• Beginning of the stopband (Fstop or wstop)

Page 772: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 772/870

8 Filter Design and Analysis Tool Reference

8-24

Frequency Specifications Region:Lowpass Chebyshev Type I

Select the units for frequency specifications from the Units list:

• Hz (default)

• kHz

• MHz

• Normalized (0 to 1), where 1 corresponds to the Nyquist frequency

I f Specify order is selected in the Filter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the passband (Fpass or wpass)

I f Minimum order is selected in theFilter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the passband (Fpass or wpass)

• Beginning of the stopband (Fstop or wstop)

Page 773: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 773/870

Frequency Specifications Region: Lowpass Chebyshev Type II

8-25

Frequency Specifications Region:Lowpass Chebyshev Type II

Select the units for frequency specifications from the Units list:

• Hz (default)

• kHz

• MHz

• Normalized (0 to 1), where 1 corresponds to the Nyquist frequency

I f Specify order is selected in the F ilter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• Beginning of the stopband (Fstop or wstop)

I f Minimum order is selected in the Filter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the passband (Fpass or wpass)

• Beginning of the stopband (Fstop or wstop)

Page 774: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 774/870

8 Filter Design and Analysis Tool Reference

8-26

Frequency Specifications Region: Lowpass Elliptic

Select the units for frequency specifications from the Units list:

• Hz (default)

• kHz

• MHz

• Normalized (0 to 1), where 1 corresponds to the Nyquist frequency

I f Specify order is selected in the Filter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the passband (Fpass or wpass)

I f Minimum order is selected in theFilter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the passband (Fpass or wpass)

• Beginning of the stopband (Fstop or wstop)

Page 775: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 775/870

Frequency Specifications Region: Lowpass Equiripple

8-27

Frequency Specifications Region: Lowpass Equiripple

Select the units for frequency specifications from the Units list:

• Hz (default)

• kHz

• MHz

• Normalized (0 to 1), where 1 corresponds to the Nyquist frequency

I f Specify order is selected in the F ilter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the passband (Fpass or wpass)

• Beginning of the stopband (Fstop or wstop)

I f Minimum order is selected in the Filter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the passband (Fpass or wpass)

• Beginning of the stopband (Fstop or wstop)

Page 776: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 776/870

8 Filter Design and Analysis Tool Reference

8-28

Frequency Specifications Region: Lowpass Least-Squares

Select the units for frequency specifications from the Units list:

• Hz (default)

• kHz

• MHz

• Normalized (0 to 1), where 1 corresponds to the Nyquist frequency

Specify the following frequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the passband (Fpass or wpass)

• Beginning of the stopband (Fstop or wstop)

Page 777: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 777/870

Frequency Specifications Region: Lowpass Window

8-29

Frequency Specifications Region: Lowpass WindowSelect the units for frequency specifications from the Units list:

• Hz (default)

• kHz

• MHz

• Normalized (0 to 1), where 1 corresponds to the Nyquist frequency

I f Specify order is selected in the F ilter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• Cutoff frequency (Fc or wc) – thefrequency at which themagnituderesponseis 6 dB below the passband gain

I f Minimum order is selected in the Filter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the passband (Fpass or wpass)

• Beginning of the stopband (Fstop or wstop)

Page 778: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 778/870

8 Filter Design and Analysis Tool Reference

8-30

Frequency Specifications Region: Highpass ButterworthSelect the units for frequency specifications from the Units list:

• Hz (default)

• kHz

• MHz

• Normalized (0 to 1), where 1 corresponds to the Nyquist frequency

I f Specify order is selected in the Filter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• Cutoff frequency (Fc or wc) – the frequency at which themagnituderesponseis 3 dB below the passband gain

I f Minimum order is selected in theFilter Order region, specify the following

frequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the stopband (Fstop or wstop)

• Beginning of the passband (Fpass or wpass)

Page 779: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 779/870

Frequency Specifications Region: Highpass Chebyshev Type I

8-31

Frequency Specifications Region:Highpass Chebyshev Type I

Select the units for frequency specifications from the Units list:

• Hz (default)

• kHz

• MHz

• Normalized (0 to 1), where 1 corresponds to the Nyquist frequency

I f Specify order is selected in the F ilter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• Beginning of the passband (Fpass or wpass)

I f Minimum order is selected in the Filter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the stopband (Fstop or wstop)

• Beginning of the passband (Fpass or wpass)

Page 780: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 780/870

8 Filter Design and Analysis Tool Reference

8-32

Frequency Specifications Region:Highpass Chebyshev Type II

Select the units for frequency specifications from the Units list:

• Hz (default)

• kHz

• MHz

• Normalized (0 to 1), where 1 corresponds to the Nyquist frequency

I f Specify order is selected in the Filter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the stopband (Fstop or wstop)

I f Minimum order is selected in theFilter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the stopband (Fstop or wstop)

• Beginning of the passband (Fpass or wpass)

Page 781: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 781/870

Frequency Specifications Region: Highpass Elliptic

8-33

Frequency Specifications Region: Highpass EllipticSelect the units for frequency specifications from the Units list:

• Hz (default)

• kHz

• MHz

• Normalized (0 to 1), where 1 corresponds to the Nyquist frequency

I f Specify order is selected in the F ilter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• Beginning of the passband (Fpass or wpass)

I f Minimum order is selected in the Filter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the stopband (Fstop or wstop)

• Beginning of the passband (Fpass or wpass)

Page 782: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 782/870

8 Filter Design and Analysis Tool Reference

8-34

Frequency Specifications Region: Highpass EquirippleSelect the units for frequency specifications from the Units list:

• Hz (default)

• kHz

• MHz

• Normalized (0 to 1), where 1 corresponds to the Nyquist frequency

I f Specify order is selected in the Filter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the stopband (Fstop or wstop)

• Beginning of the passband (Fpass or wpass)

I f Minimum order is selected in theFilter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the stopband (Fstop or wstop)

• Beginning of the passband (Fpass or wpass)

Page 783: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 783/870

Frequency Specifications Region: Highpass Least-Squares

8-35

Frequency Specifications Region: Highpass Least-SquaresSelect the units for frequency specifications from the Units list:

• Hz (default)

• kHz

• MHz

• Normalized (0 to 1), where 1 corresponds to the Nyquist frequency

Specify the following frequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the stopband (Fstop or wstop)

• Beginning of the passband (Fpass or wpass)

Page 784: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 784/870

8 Filter Design and Analysis Tool Reference

8-36

Frequency Specifications Region: Highpass WindowSelect the units for frequency specifications from the Units list:

• Hz (default)

• kHz

• MHz

• Normalized (0 to 1), where 1 corresponds to the Nyquist frequency

I f Specify order is selected in the Filter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• Cutoff frequency (Fc or wc) – the frequency at which themagnituderesponseis 6 dB below the passband gain

I f Minimum order is selected in theFilter Order region, specify the following

frequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the stopband (Fstop or wstop)

• Beginning of the passband (Fpass or wpass)

Page 785: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 785/870

Frequency Specifications Region: Bandpass Butterworth

8-37

Frequency Specifications Region: Bandpass ButterworthSelect the units for frequency specifications from the Units list:

• Hz (default)

• kHz

• MHz

• Normalized (0 to 1), where 1 corresponds to the Nyquist frequency

I f Specify order is selected in the F ilter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• First cutoff frequency (Fc1or wc1) – the frequency preceding the passbandat which the magnituderesponse is 3 dB below the passband gain

• Second cutoff frequency (Fc2 or wc2) – the frequency following the passband

at which the magnituderesponse is 3 dB below the passband gain

I f Minimum order is selected in the Filter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the first stopband (Fstop1 or wstop1)

• Beginning of the passband (Fpass1 or wpass1)

•End of the passband (Fpass2 or wpass2)

• Beginning of the second stopband (Fstop2 or wstop2)

Page 786: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 786/870

8 Filter Design and Analysis Tool Reference

8-38

Frequency Specifications Region:Bandpass Chebyshev Type I

Select the units for frequency specifications from the Units list:

• Hz (default)

• kHz

• MHz

• Normalized (0 to 1), where 1 corresponds to the Nyquist frequency

I f Specify order is selected in the Filter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• Beginning of the passband (Fpass1 or wpass1)

• End of the passband (Fpass2 or wpass2)

I f Minimum order is selected in theFilter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the first stopband (Fstop1 or wstop1)

• Beginning of the passband (Fpass1 or wpass1)

• End of the passband (Fpass2 or wpass2)

• Beginning of the second stopband (Fstop2 or wstop2)

Page 787: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 787/870

Frequency Specifications Region: Bandpass Chebyshev Type II

8-39

Frequency Specifications Region:Bandpass Chebyshev Type II

Select the units for frequency specifications from the Units list:

• Hz (default)

• kHz

• MHz

• Normalized (0 to 1), where 1 corresponds to the Nyquist frequency

I f Specify order is selected in the F ilter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the first stopband (Fstop1 or wstop1)

• Beginning of the second stopband (Fstop2 or wstop2)

I f Minimum order is selected in the Filter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the first stopband (Fstop1 or wstop1)

• Beginning of the passband (Fpass1 or wpass1)

• End of the passband (Fpass2 or wpass2)

• Beginning of the second stopband (Fstop2 or wstop2)

Page 788: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 788/870

8 Filter Design and Analysis Tool Reference

8-40

Frequency Specifications Region: Bandpass EllipticSelect the units for frequency specifications from the Units list:

• Hz (default)

• kHz

• MHz

• Normalized (0 to 1), where 1 corresponds to the Nyquist frequency

I f Specify order is selected in the Filter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• Beginning of the passband (Fpass1 or wpass1)

• End of the passband (Fpass2 or wpass2)

I f Minimum order is selected in theFilter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the first stopband (Fstop1 or wstop1)

• Beginning of the passband (Fpass1 or wpass1)

• End of the passband (Fpass2 or wpass2)

• Beginning of the second stopband (Fstop2 or wstop2)

Page 789: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 789/870

Frequency Specifications Region: Bandpass Equiripple

8-41

Frequency Specifications Region: Bandpass EquirippleSelect the units for frequency specifications from the Units list:

• Hz (default)

• kHz

• MHz

• Normalized (0 to 1), where 1 corresponds to the Nyquist frequency

I f Specify order is selected in the F ilter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the first stopband (Fstop1 or wstop1)

• Beginning of the passband (Fpass1 or wpass1)

• End of the passband (Fpass2 or wpass2)

• Beginning of the second stopband (Fstop2 or wstop2)

I f Minimum order is selected in the Filter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the first stopband (Fstop1 or wstop1)

• Beginning of the passband (Fpass1 or wpass1)

• End of the passband (Fpass2 or wpass2)

• Beginning of the second stopband (Fstop2 or wstop2)

Page 790: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 790/870

8 Filter Design and Analysis Tool Reference

8-42

Frequency Specifications Region: Bandpass Least-SquaresSelect the units for frequency specifications from the Units list:

• Hz (default)

• kHz

• MHz

• Normalized (0 to 1), where 1 corresponds to the Nyquist frequency

Specify the following frequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the first stopband (Fstop1 or wstop1)

• Beginning of the passband (Fpass1 or wpass1)

• End of the passband (Fpass2 or wpass2)

• Beginning of the second stopband (Fstop2 or wstop2)

Page 791: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 791/870

Frequency Specifications Region: Bandpass Window

8-43

Frequency Specifications Region: Bandpass WindowSelect the units for frequency specifications from the Units list:

• Hz (default)

• kHz

• MHz

• Normalized (0 to 1), where 1 corresponds to the Nyquist frequency

I f Specify order is selected in the F ilter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• First cutoff frequency (Fc1or wc1) – the frequency preceding the passbandat which the magnituderesponse is 6 dB below the passband gain

• Second cutoff frequency (Fc2 or wc2) – the frequency following the passband

at which the magnituderesponse is 6 dB below the passband gainI f Minimum order is selected in the Filter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the first stopband (Fstop1 or wstop1)

• Beginning of the passband (Fpass1 or wpass1)

End of the passband (Fpass2 or wpass2)• Beginning of the second stopband (Fstop2 or wstop2)

Page 792: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 792/870

8 Filter Design and Analysis Tool Reference

8-44

Frequency Specifications Region: Bandstop ButterworthSelect the units for frequency specifications from the Units list:

• Hz (default)

• kHz

• MHz

• Normalized (0 to 1), where 1 corresponds to the Nyquist frequency

I f Specify order is selected in the Filter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• First cutoff frequency (Fc1or wc1) – thefrequency preceding thestopbandatwhich the magnitude response is 3 dB below the passband gain

• Second cutoff frequency (Fc2 or wc2) – thefrequency following the stopband

at which the magnitude response is 3 dB below the passband gainI f Minimum order is selected in theFilter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the first passband (Fpass1 or wpass1)

• Beginning of the stopband (Fstop1 or wstop1)

End of the stopband (Fstop2 or wstop2)• Beginning of the second passband (Fpass2 or wpass2)

Page 793: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 793/870

Frequency Specifications Region: Bandstop Chebyshev Type I

8-45

Frequency Specifications Region:Bandstop Chebyshev Type I

Select the units for frequency specifications from the Units list:

• Hz (default)

• kHz

• MHz

• Normalized (0 to 1), where 1 corresponds to the Nyquist frequency

I f Specify order is selected in the F ilter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the first passband (Fpass1 or wpass1)

• Beginning of the second passband (Fpass2 or wpass2)

I f Minimum order is selected in the Filter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the first passband (Fpass1 or wpass1)

• Beginning of the stopband (Fstop1 or wstop1)

• End of the stopband (Fstop2 or wstop2)

• Beginning of the second passband (Fpass2 or wpass2)

Page 794: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 794/870

8 Filter Design and Analysis Tool Reference

8-46

Frequency Specifications Region:Bandstop Chebyshev Type II

Select the units for frequency specifications from the Units list:

• Hz (default)

• kHz

• MHz

• Normalized (0 to 1), where 1 corresponds to the Nyquist frequency

I f Specify order is selected in the Filter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• Beginning of the stopband (Fstop1 or wstop1)

• End of the stopband (Fstop2 or wstop2)

I f Minimum order is selected in theFilter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the first passband (Fpass1 or wpass1)

• Beginning of the stopband (Fstop1 or wstop1)

• End of the stopband (Fstop2 or wstop2)

• Beginning of the second passband (Fpass2 or wpass2)

Page 795: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 795/870

Frequency Specifications Region: Bandstop Elliptic

8-47

Frequency Specifications Region: Bandstop EllipticSelect the units for frequency specifications from the Units list:

• Hz (default)

• kHz

• MHz

• Normalized (0 to 1), where 1 corresponds to the Nyquist frequency

I f Specify order is selected in the F ilter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the first passband (Fpass1 or wpass1)

• Beginning of the second passband (Fpass2 or wpass2)

I f Minimum order is selected in the Filter Order region, specify the following

frequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the first passband (Fpass1 or wpass1)

• Beginning of the stopband (Fstop1 or wstop1)

• End of the stopband (Fstop2 or wstop2)

• Beginning of the second passband (Fpass2 or wpass2)

Page 796: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 796/870

8 Filter Design and Analysis Tool Reference

8-48

Frequency Specifications Region: Bandstop EquirippleSelect the units for frequency specifications from the Units list:

• Hz (default)

• kHz

• MHz

• Normalized (0 to 1), where 1 corresponds to the Nyquist frequency

I f Specify order is selected in the Filter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the first passband (Fpass1 or wpass1)

• Beginning of the stopband (Fstop1 or wstop1)

• End of the stopband (Fstop2 or wstop2)

• Beginning of the second passband (Fpass2 or wpass2)

I f Minimum order is selected in theFilter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the first passband (Fpass1 or wpass1)

• Beginning of the stopband (Fstop1 or wstop1)

• End of the stopband (Fstop2 or wstop2)

• Beginning of the second passband (Fpass2 or wpass2)

Page 797: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 797/870

Frequency Specifications Region: Bandstop Least-Squares

8-49

Frequency Specifications Region: Bandstop Least-SquaresSelect the units for frequency specifications from the Units list:

• Hz (default)

• kHz

• MHz

• Normalized (0 to 1), where 1 corresponds to the Nyquist frequency

Specify the following frequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the first passband (Fpass1 or wpass1)

• Beginning of the stopband (Fstop1 or wstop1)

• End of the stopband (Fstop2 or wstop2)

• Beginning of the second passband (Fpass2 or wpass2)

Page 798: Dsp Toolbox

7/29/2019 Dsp Toolbox

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

8 Filter Design and Analysis Tool Reference

8-50

Frequency Specifications Region: Bandstop WindowSelect the units for frequency specifications from the Units list:

• Hz (default)

• kHz

• MHz

• Normalized (0 to 1), where 1 corresponds to the Nyquist frequency

I f Specify order is selected in the Filter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• First cutoff frequency (Fc1or wc1) – thefrequency preceding thestopbandatwhich the magnitude response is 6 dB below the passband gain

• Second cutoff frequency (Fc2 or wc2) – thefrequency following the stopbandat which the magnitude response is 6 dB below the passband gain

I f Minimum order is selected in theFilter Order region, specify the followingfrequencies in the text boxes:

• Sampling frequency (Fs) – required when Hz, kHz, or MHz is selected

• End of the first passband (Fpass1 or wpass1)

• Beginning of the stopband (Fstop1 or wstop1)

End of the stopband (Fstop2 or wstop2)• Beginning of the second passband (Fpass2 or wpass2)

Page 799: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 799/870

Magnitude Specifications Region

8-51

Magnitude Specifications Region The Magnitude Specifications region allows you to enter magnitudeparameters for the fil ter design. The options available vary with the selectionsin the Filter Type and Design Method regions:

• L owpass

- Butterworth

-Chebyshev Type I

- Chebyshev Type I I

- Elliptic

- Equiripple

- L east-Squares

- Window

• Highpass

- Butterworth

- Chebyshev Type I

- Chebyshev Type I I

- Elliptic

- Equiripple

- L east-Squares

- Window

• Bandpass

- Butterworth

- Chebyshev Type I

- Chebyshev Type I I

- Elliptic

-Equiripple

- L east-Squares

- Window

• Bandstop

- Butterworth

Page 800: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 800/870

8 Filter Design and Analysis Tool Reference

8-52

-

Chebyshev Type I- Chebyshev Type I I

- Elliptic

- Equiripple

- L east-Squares

- Window

• Differentiator

• Hilbert Transformer

• Multiband

• Arbitrary Magnitude

• Arbitrary Group Delay – available only when the Filter Design Toolbox isinstalled

Page 801: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 801/870

Magnitude Specifications Region: Lowpass Butterworth

8-53

Magnitude Specifications Region: Lowpass ButterworthI f Specify order is selected in the F ilter Order region, the attenuation at thecutoff frequency is fixed at 3 dB (half the passband power).

I f Minimum order is selected in the Filter Order region, select the units formagnitude response characteristics from the Units list:

• dB for magnitude response characteristics in decibels (default)

•Squared for squared magnitude response characteristics

Specify the following magnitude response characteristics in the text boxes:

• Passband ripple (Apass or Epass)

• Stopband attenuation (Astop or Estop)

Page 802: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 802/870

8 Filter Design and Analysis Tool Reference

8-54

Magnitude Specifications Region:Lowpass Chebyshev Type I

I f Specify order is selected in the Filter Order region, specify the passbandripple(Apass or Epass) in decibels.

I f Minimum order is selected in the Filter Order region, select the units formagnitude response characteristics from the Units list:

•dB for magnitude response characteristics in decibels (default)

• Squared for squared magnitude response characteri stics

Specify the following magnitude response characteristics in the text boxes:

• Passband ripple (Apass or Epass)

• Stopband attenuation (Astop or Estop)

Page 803: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 803/870

Magnitude Specifications Region: Lowpass Chebyshev Type II

8-55

Magnitude Specifications Region:Lowpass Chebyshev Type II

I f Specify order is selected in the Filter Order region, specify the stopbandattenuation (Astop or Estop) in decibels.

I f Minimum order is selected in the Filter Order region, select the units formagnitude response characteristics from the Units list:

•dB for magnitude response characteristics in decibels (default)

• Squared for squared magnitude response characteristics

Specify the following magnitude response characteristics in the text boxes:

• Passband ripple (Apass or Epass)

• Stopband attenuation (Astop or Estop)

Page 804: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 804/870

8 Filter Design and Analysis Tool Reference

8-56

Magnitude Specifications Region: Lowpass EllipticI f Specify order is selected in the Filter Order region, specify the followingmagnitude response characteristics (in dB) in the text boxes:

• Passband ripple (Apass or Epass)

• Stopband attenuation (Astop or Estop)

I f Minimum order is selected in the Filter Order region, select the units for

magnitude response characteristics from the Units list:

• dB for magnitude response characteristics in decibels (default)

• Squared for squared magnitude response characteri stics

Specify the following magnitude response characteristics in the text boxes:

• Passband ripple (Apass or Epass)

• Stopband attenuation (Astop or Estop)

Page 805: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 805/870

Magnitude Specifications Region: Lowpass Equiripple

8-57

Magnitude Specifications Region: Lowpass EquirippleI f Specify order is selected in the F ilter Order region, specify the followingrelative weights in the text boxes:

• Passband weighting (Wpass)

• Stopband weighting (Wstop)

I f Minimum order is selected in the Filter Order region, select the units for

magnitude response characteristics from the Units list:

• dB for magnitude response characteristics in decibels (default)

• Linear for li nearly scaled magnitude response characteristics

Specify the following magnitude response characteristics in the text boxes:

• Passband ripple (Apass or Dpass)

• Stopband attenuation (Astop or Dstop)

Page 806: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 806/870

8 Filter Design and Analysis Tool Reference

8-58

Magnitude Specifications Region: Lowpass Least-SquaresSpecify the following relative weights in the text boxes:

• Passband weighting (Wpass)

• Stopband weighting (Wstop)

Page 807: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 807/870

Magnitude Specifications Region: Lowpass Window

8-59

Magnitude Specifications Region: Lowpass WindowI f Specify order is selected in the F ilter Order region, the attenuation at thecutoff frequency is fixed at 6 dB (half the passband gain).

For theK aiser windowoption, if Minimum order is selected in theFi lter Orderregion, select the units for magnitude responsecharacteristics from the Units

list:

• dB for magnitude response characteristics in decibels (default)

• Linear for li nearly scaled magnitude response characteristics

Specify the following magnitude response characteristics in the text boxes:

• Passband ripple (Apass or Dpass)

• Stopband attenuation (Astop or Dstop)

Page 808: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 808/870

8 Filter Design and Analysis Tool Reference

8-60

Magnitude Specifications Region: Highpass ButterworthI f Specify order is selected in the Filter Order region, the attenuation at thecutoff frequency is fixed at 3 dB (half the passband power).

I f Minimum order is selected in the Filter Order region, select the units formagnitude response characteristics from the Units list:

• dB for magnitude response characteristics in decibels (default)

Squared for squared magnitude response characteri stics

Specify the following magnitude response characteristics in the text boxes:

• Passband ripple (Apass or Epass)

• Stopband attenuation (Astop or Estop)

Page 809: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 809/870

Magnitude Specifications Region: Highpass Chebyshev Type I

8-61

Magnitude Specifications Region:Highpass Chebyshev Type I

I f Specify order is selected in the Filter Order region, specify the passbandripple (Apass) in decibels.

I f Minimum order is selected in the Filter Order region, select the units formagnitude response characteristics from the Units list:

dB for magnitude response characteristics in decibels (default)• Squared for squared magnitude response characteristics

Specify the following magnitude response characteristics in the text boxes:

• Passband ripple (Apass or Epass)

• Stopband attenuation (Astop or Estop)

8

Page 810: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 810/870

8 Filter Design and Analysis Tool Reference

8-62

Magnitude Specifications Region:Highpass Chebyshev Type II

I f Specify order is selected in the Filter Order region, specify the stopbandattenuation (Astop) in decibels.

I f Minimum order is selected in the Filter Order region, select the units formagnitude response characteristics from the Units list:

dB for magnitude response characteristics in decibels (default)• Squared for squared magnitude response characteri stics

Specify the following magnitude response characteristics in the text boxes:

• Passband ripple (Apass or Epass)

• Stopband attenuation (Astop or Estop)

Page 811: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 811/870

Magnitude Specifications Region: Highpass Elliptic

8-63

Magnitude Specifications Region: Highpass EllipticI f Specify order is selected in the F ilter Order region, specify the followingmagnitude response characteristics (in dB) in the text boxes:

• Passband ripple (Apass or Epass)

• Stopband attenuation (Astop or Estop)

I f Minimum order is selected in the Filter Order region, select the units for

magnitude response characteristics from the Units list:

• dB for magnitude response characteristics in decibels (default)

• Squared for squared magnitude response characteristics

Specify the following magnitude response characteristics in the text boxes:

• Passband ripple (Apass or Epass)

• Stopband attenuation (Astop or Estop)

8 Filt D i d A l i T l R f

Page 812: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 812/870

8 Filter Design and Analysis Tool Reference

8-64

Magnitude Specifications Region: Highpass EquirippleI f Specify order is selected in the Filter Order region, specify the followingrelative weights in the text boxes:

• Stopband weighting (Wstop)

• Passband weighting (Wpass)

I f Minimum order is selected in the Filter Order region, select the units for

magnitude response characteristics from the Units list:

• dB for magnitude response characteristics in decibels (default)

• Linear for li nearly scaled magnitude response characteri stics

Specify the following magnitude response characteristics in the text boxes:

• Passband ripple (Apass or Dpass)

• Stopband attenuation (Astop or Dstop)

Page 813: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 813/870

Magnitude Specifications Region: Highpass Least-Squares

8-65

Magnitude Specifications Region: Highpass Least-SquaresSpecify the following relative weights in the text boxes:

• Stopband weighting (Wstop)

• Passband weighting (Wpass)

8 Filter Design and Analysis Tool Reference

Page 814: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 814/870

8 Filter Design and Analysis Tool Reference

8-66

Magnitude Specifications Region: Highpass WindowI f Specify order is selected in the Filter Order region, the attenuation at thecutoff frequency is fixed at 6 dB (half the passband gain).

I f Minimum order is selected in the Filter Order region, select the units formagnitude response characteristics from the Units list:

• dB for magnitude response characteristics in decibels (default)

Linear for li nearly scaled magnitude response characteri sticsSpecify the following magnitude response characteristics in the text boxes:

• Passband ripple (Apass or Dpass)

• Stopband attenuation (Astop or Dstop)

Magnitude Specifications Region: Bandpass Butterworth

Page 815: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 815/870

Magnitude Specifications Region: Bandpass Butterworth

8-67

Magnitude Specifications Region: Bandpass ButterworthI f Specify order is selected in the F ilter Order region, the attenuation at thecutoff frequencies is fixed at 3 dB (half the passband power).

I f Minimum order is selected in the Filter Order region, select the units formagnitude response characteristics from the Units list:

• dB for magnitude response characteristics in decibels (default)

Squared for squared magnitude response characteristicsSpecify the following magnitude response characteristics in the text boxes:

• Attenuation in the first stopband (Astop1or Estop1)

• Passband ripple (Apass or Epass)

• Attenuation in the second stopband (Astop2 or Estop2)

8 Filter Design and Analysis Tool Reference

Page 816: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 816/870

g y

8-68

Magnitude Specifications Region:Bandpass Chebyshev Type I

I f Specify order is selected in the Filter Order region, specify the passbandripple(Apass) in decibels.

I f Minimum order is selected in the Filter Order region, select the units formagnitude response characteristics from the Units list:

dB for magnitude response characteristics in decibels (default)• Squared for squared magnitude response characteri stics

Specify the following magnitude response characteristics in the text boxes:

• Attenuation in the first stopband (Astop1or Estop1)

• Passband ripple (Apass or Epass)

• Attenuation in the second stopband (Astop2 or Estop2)

Magnitude Specifications Region: Bandpass ChebyshevType II

Page 817: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 817/870

Magnitude Specifications Region: Bandpass Chebyshev Type II

8-69

Magnitude Specifications Region:Bandpass Chebyshev Type II

I f Specify order is selected in the Filter Order region, specify the stopbandattenuation (Astop) in decibels.

I f Minimum order is selected in the Filter Order region, select the units formagnitude response characteristics from the Units list:

• dBfor magnitude response characteristics in decibels (default)

• Squared for squared magnitude response characteristics

Specify the following magnitude response characteristics in the text boxes:

• Attenuation in the first stopband (Astop1or Estop1)

• Passband ripple (Apass or Epass)

• Attenuation in the second stopband (Astop2 or Estop2)

8 Filter Design and Analysis Tool Reference

Page 818: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 818/870

8-70

Magnitude Specifications Region: Bandpass EllipticI f Specify order is selected in the Filter Order region, specify the followingmagnitude response characteristics (in dB) in the text boxes:

• Stopband attenuation (Astop)

• Passband ripple (Apass)

I f Minimum order is selected in the Filter Order region, select the units for

magnitude response characteristics from the Units list:

• dB for magnitude response characteristics in decibels (default)

• Squared for squared magnitude response characteri stics

Specify the following magnitude response characteristics in the text boxes:

• Attenuation in the first stopband (Astop1or Estop1)

• Passband ripple (Apass or Epass)

• Attenuation in the second stopband (Astop2 or Estop2)

Magnitude Specifications Region: Bandpass Equiripple

Page 819: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 819/870

8-71

Magnitude Specifications Region: Bandpass EquirippleI f Specify order is selected in the F ilter Order region, specify the followingrelative weights in the text boxes:

• Weighting in the first stopband (Wstop1)

• Passband weighting (Wpass)

• Weighting in the second stopband (Wstop2)

I f Minimum order is selected in the Filter Order region, select the units formagnitude response characteristics from the Units list:

• dB for magnitude response characteristics in decibels (default)

• Linear for li nearly scaled magnitude response characteristics

Specify the following magnitude response characteristics in the text boxes:

• Attenuation in the first stopband (Astop1 or Dstop1)

• Passband ripple (Apass or Dpass)

• Attenuation in the second stopband (Astop2 or Dstop2)

8 Filter Design and Analysis Tool Reference

Page 820: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 820/870

8-72

Magnitude Specifications Region: Bandpass Least-SquaresSpecify the following relative weights in the text boxes:

• Weighting in the first stopband (Wstop1)

• Passband weighting (Wpass)

• Weighting in the second stopband (Wstop2)

Magnitude Specifications Region: Bandpass Window

Page 821: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 821/870

8-73

Magnitude Specifications Region: Bandpass Window

I f Specify order is selected in the F ilter Order region, the attenuation at thecutoff frequencies is fixed at 6 dB (half the passband gain).

I f Minimum order is selected in the Filter Order region, select the units formagnitude response characteristics from the Units list:

• dB for magnitude response characteristics in decibels (default)

• Linear for li nearly scaled magnitude response characteristics

Specify the following magnitude response characteristics in the text boxes:

• Attenuation in the first stopband (Astop1 or Dstop1)

• Passband ripple (Apass or Dpass)

• Attenuation in the second stopband (Astop2 or Dstop2)

8 Filter Design and Analysis Tool Reference

Page 822: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 822/870

8-74

Magnitude Specifications Region: Bandstop Butterworth

I f Specify order is selected in the Filter Order region, the attenuation at thecutoff frequencies is fixed at 3 dB (half the passband power).

I f Minimum order is selected in the Filter Order region, select the units formagnitude response characteristics from the Units list:

• dB for magnitude response characteristics in decibels (default)

• Squared for squared magnitude response characteri stics

Specify the following magnitude response characteristics in the text boxes:

• Ripple in the first passband (Apass1 or Epass1)

• Stopband attenuation (Astop or Estop)

• Ripple in the second passband (Apass2 or Epass2)

Magnitude Specifications Region: Bandstop Chebyshev Type I

Page 823: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 823/870

8-75

Magnitude Specifications Region:Bandstop Chebyshev Type I

I f Specify order is selected in the Filter Order region, specify the passbandripple (Apass) in decibels.

I f Minimum order is selected in the Filter Order region, select the units formagnitude response characteristics from the Units list:

• dB for magnitude response characteristics in decibels (default)

• Squared for squared magnitude response characteristics

Specify the following magnitude response characteristics in the text boxes:

• Ripple in the first passband (Apass1 or Epass1)

• Stopband attenuation (Astop or Estop)

• Ripple in the second passband (Apass2 or Epass2)

8 Filter Design and Analysis Tool Reference

Page 824: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 824/870

8-76

Magnitude Specifications Region:Bandstop Chebyshev Type II

I f Specify order is selected in the Filter Order region, specify the stopbandattenuation (Astop) in decibels.

I f Minimum order is selected in the Filter Order region, select the units formagnitude response characteristics from the Units list:

• dB for magnitude response characteristics in decibels (default)

• Squared for squared magnitude response characteri stics

Specify the following magnitude response characteristics in the text boxes:

• Ripple in the first passband (Apass1 or Epass1)

• Stopband attenuation (Astop or Estop)

• Ripple in the second passband (Apass2 or Epass2)

Magnitude Specifications Region: Bandstop Elliptic

Page 825: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 825/870

8-77

Magnitude Specifications Region: Bandstop Elliptic

I f Specify order is selected in the F ilter Order region, specify the followingmagnitude response characteristics (in dB) in the text boxes:

• Passband ripple (Apass or Epass)

• Stopband attenuation (Astop or Estop)

I f Minimum order is selected in the Filter Order region, select the units for

magnitude response characteristics from the Units list:• dB for magnitude response characteristics in decibels (default)

• Squared for squared magnitude response characteristics

Specify the following magnitude response characteristics in the text boxes:

• Ripple in the first passband (Apass1 or Epass1)

• Stopband attenuation (Astop or Estop)

• Ripple in the second passband (Apass2 or Epass2)

8 Filter Design and Analysis Tool Reference

Page 826: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 826/870

8-78

Magnitude Specifications Region: Bandstop Equiripple

I f Specify order is selected in the Filter Order region, specify the followingrelative weights in the text boxes:

• Weighting in the first passband (Wpass1)

• Stopband weighting (Wstop)

• Weighting in the second passband (Wpass2)

I f Minimum order is selected in the Filter Order region, select the units formagnitude response characteristics from the Units list:

• dB for magnitude response characteristics in decibels (default)

• Linear for li nearly scaled magnitude response characteri stics

Specify the following magnitude response characteristics in the text boxes:

• Ripple in the first passband (Apass1 or Dpass1)

• Stopband attenuation (Astop or Dstop)

• Ripple in the second passband (Apass2 or Dpass2)

Magnitude Specifications Region: Bandstop Least-Squares

Page 827: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 827/870

8-79

Magnitude Specifications Region: Bandstop Least-Squares

Specify the following relative weights in the text boxes:

• Weighting in the first passband (Wpass1)

• Stopband weighting (Wstop)

• Weighting in the second passband (Wpass2)

8 Filter Design and Analysis Tool Reference

Page 828: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 828/870

8-80

Magnitude Specifications Region: Bandstop Window

I f Specify order is selected in the Filter Order region, the attenuation at thecutoff frequencies is fixed at 6 dB (half the passband gain).

I f Minimum order is selected in the Filter Order region, select the units formagnitude response characteristics from the Units list:

• dB for magnitude response characteristics in decibels (default)

• Linear for li nearly scaled magnitude response characteri stics

Specify the following magnitude response characteristics in the text boxes:

• Ripple in the first passband (Apass1 or Dpass1)

• Stopband attenuation (Astop or Dstop)

• Ripple in the second passband (Apass2 or Dpass2)

Frequency and Magnitude Specifications Region: Differentiator

Page 829: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 829/870

8-81

Frequency and Magnitude Specifications Region:Differentiator

Select the units for frequency specifications from the Frequency units list:

• Hz

• kHz

• MHz

• Normalized (0 to 1), where 1 corresponds to the Nyquist frequency

For all units except Normalized, specify the sampling frequency, Fs.

Specify the following parameters in the text boxes:

• Freq. vector – A vector defining the frequency points at which the responsemagnitude is specifi ed, in ascending order. Must have an even length the

same as Mag. vector.

Mag. vector – A vector defining the response magnitudes at the specifiedfrequencies. Must have an even length the same as Freq. vector.

• Weight vector – A vector defining the relative weight that should be givento each frequency band. Must be half the length of Freq. vector.

Each odd-indexed frequency-amplitude pair defines the left endpoint of a linesegment representing the desired magnitude responsein that frequency band. The corresponding even-indexed frequency-amplitude pair defines the right

endpoint. Between the frequency bands specified by these end-points, theremay beundefined sections of the specified frequency response. Theseare called“don’t care” or “transition” regions, and the magnitude responsein theseareasis a by-product of the optimization in the other (specifi ed) frequency ranges.

TheWeight vector specifies theemphasis to be placed on minimizingtheerrorin certain frequency bands relative to others, one weight per band. I n mostcases, differentiators have only a single band, so the weight is a scalar valuethat does not affect the final filter.

See “Multiband FI R Fi lter Design with Transition Bands”and r emez for moreinformation.

8 Filter Design and Analysis Tool Reference

Page 830: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 830/870

8-82

Frequency and Magnitude Specifications Region:Hilbert Transformer

Select the units for frequency specifications from the Frequency units list:

• Hz

• kHz

• MHz

• Normalized (0 to 1), where 1 corresponds to the Nyquist frequency

For all units except Normalized, specify the sampling frequency, Fs.

Specify the following parameters in the text boxes:

• Freq. vector – A vector defining the frequency points at which the responsemagnitude is specified, in ascending order. Must have an even length the

same as Mag. vector.

Mag. vector – A vector defining the response magnitudes at the specifiedfrequencies. Must have an even length the same as Freq. vector.

• Weight vector – A vector defining the relative weight that should be givento each frequency band. Must be half the length of Freq. vector.

Each odd-indexed frequency-amplitude pair defines the left endpoint of a linesegment representing the desired magnitude responsein that frequency band. The corresponding even-indexed frequency-amplitude pair defines the rightendpoint. Between the frequency bands specified by these end-points, theremay beundefined sections of the specified frequency response. Theseare called“don’t care” or “transition”regions, and the magnitude responsein theseareasis a by-product of the optimization in the other (specified) frequency ranges.

The Weight vector specifiesthe emphasis tobeplaced on minimizing theerrorin certain frequency bands relative to others, one weight per band. I n mostcases, Hi lbert transformers have only a single band, so the weight is a scalarvalue that does not affect thefinal filter. However, theWeight vector is useful

when designing an antisymmetric multiband filter, such as a Hilberttransformer with stopbands.

See “Multiband FI R Filter Design with Transition Bands” and r emez for moreinformation.

Frequency and Magnitude Specifications Region: Multiband

Page 831: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 831/870

8-83

Frequency and Magnitude Specifications Region:Multiband

Select the units for frequency specifications from the Frequency units list:

• Hz

• kHz

• MHz

• Normalized (0 to 1), where 1 corresponds to the Nyquist frequency

For all units except Normalized, specify the sampling frequency, Fs.

Specify the following parameters in the text boxes:

• Freq. vector – A vector defining the frequency points at which the responsemagnitude is specifi ed, in ascending order. Must have an even length the

same as Mag. vector.

Mag. vector – A vector defining the response magnitudes at the specifiedfrequencies. Must have an even length the same as Freq. vector.

• Weight vector – A vector defining the relative weight that should be givento each frequency band. Must be half the length of Freq. vector.

Each frequency-magnitude pair specifies the junction of two adjacentfrequency bands. See “Multiband FI R F ilter Design with Transition Bands”and r emez for more information.

8 Filter Design and Analysis Tool Reference

Page 832: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 832/870

8-84

Frequency and Magnitude Specifications Region:Arbitrary Magnitude

Select the units for frequency specifications from the Frequency units list:

• Hz

• kHz

• MHz

• Normalized (0 to 1), where 1 corresponds to the Nyquist frequency

For all units except Normalized, specify the sampling frequency, Fs.

Specify the following parameters in the text boxes:

• Freq. vector – A vector defining the frequency points at which the responsemagnitude is specified, in ascending order. Must have an even length the

same as Mag. vector.

Mag. vector – A vector defining the response magnitudes at the specifiedfrequencies. Must have an even length the same as Freq. vector.

• Weight vector – A vector defining the relative weight that should be givento each frequency band. Must be half the length of Freq. vector.

Each frequency-magnitude pair specifies the junction of two adjacentfrequency bands. See r emez for more information.

Frequency and Magnitude Specifications Region: Arbitrary Group Delay

Page 833: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 833/870

8-85

Frequency and Magnitude Specifications Region:Arbitrary Group Delay

Select the units for frequency specifications from the Frequency units list:

• Hz

• kHz

• MHz

• Normalized (0 to 1), where 1 corresponds to the Nyquist frequency

For all units except Normalized, specify the sampling frequency, Fs.

Specify the following parameters in the text boxes:

• Freq. vector – A vector defining the frequency points at which the responsegroup delay is specified, in ascending order. Must have the same length asGrp. Delay vector.

• Freq. edges– A vector defining the band-edge frequencies on the boundarybetween “care”and “don’t care”regions, in ascending order. The Freq. edges

vector contains a subset of the points in the Freq. vector vector.

• Grp. Delay vector – A vector defining the response group delay in samplesat the specified frequencies. Must have the same length as Freq. vector.

• Weight vector – A vector defining the relative weight that should be givento each frequency-group delay pair. Must have the same length asFreq. vector.

• Max pole radius – A scalar in the range [0 1] specifying the maximumallowable magnitude for any pole.

The Arbitrary Group Delay filter type is available only when the FilterDesign Toolbox is installed. See i i rgrpdel ay in the Filter Design Toolboxdocumentation for more information.

8 Filter Design and Analysis Tool Reference

Page 834: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 834/870

8-86

Filter Order Region

Select a radio button to compute one of the following:

• Fil ter of the order you specify (Specify order)

• Mi nimum order filter (Minimum order). The computed filter has theminimum order estimated to meet the specifications.

For certain menu choices in the Design Method region, only one of the above

order options is available.For arbitrary magnitude I I R filters (Filter Type set to Arbitrary Magnitude

and Design Method set to II R), independently specify the following:

• Order of the transfer function numerator (Numerator order)

• Order of the transfer function denominator (Denominator order)

Window Specification Region

Page 835: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 835/870

8-87

Window Specification Region

This region allows you to specify the window type to be used when Window isselected from the FIR menu in the Design Method region. The options are:

• Chebyshev (chebwi n)

• Bartlett (bart l et t )

• Blackman (bl ackman)

• Boxcar (boxcar )

• Hamming (hammi ng)

• Hann (hann)

• Kaiser (kai ser )

• Triangular (t r i ang)

When Chebyshev or Kaiser are selected, the secondary Parameter fieldallows you to specify the Chebyshev stopband ripple magnitude (in dB) or the

K aiser β parameter, respectively. See chebwi n and kai ser for moreinformation.

8 Filter Design and Analysis Tool Reference

Page 836: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 836/870

8-88

Import Filter Tab

Select the Import Filter tab (or press Ctrl+I) to import filter coefficients fromthe MAT L AB workspace, or to enter the filter coefficients directly.

Import Filter Coefficients Region

Page 837: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 837/870

8-89

Import Filter Coefficients Region

This region allows you to import a filter by specifying the filter coefficients,either by entering them explicitly, or by referri ng to variables in theMATL ABworkspace. (Access this region by selecting Import Filter from the Filter

menu.)

Select the desired filter representation from the Filter Structure menu:

• Direct form I

• Direct form II

• Direct form I transposed

• Direct form II transposed

• Direct form II (Second-order sections)

• State-space

• Lattice allpass

•Lattice MA min. phase

• Lattice MA max. phase

• Lattice ARMA

• Quantized filter (Qfilt object) — availableonly when Filter Design Toolboxis installed

The structure that you choosedetermines thetypeof coefficients that you needto specify in the text fields to the right. Follow the links above to learn moreabout specifying the coefficients.

Select thefrequency units from amongthefollowingoptions in theUnits menu:

• Hz (default)

• kHz

• MHz

• Normalized (0 to 1)

For Hz, kHz, and MHz, specify the value of the sampling frequency in the Fs

field.

8 Filter Design and Analysis Tool Reference

Page 838: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 838/870

8-90

Import Filter Coefficients: Direct Form

Specify the Numerator and Denominator polynomial coefficients using anyvalid MATL AB variable or expression. See “Filter Structures” for moreinformation.

Press Clear to erase the coefficients.

Import Filter Coefficients: Direct Form II (Second-Order Sections)

Page 839: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 839/870

8-91

Import Filter Coefficients:

Direct Form II (Second-Order Sections)Specify the Gain and SOS Matrix using any valid MATL AB variable orexpression. See “Filter Structures” for more information.

Press Clear to erase the coefficients.

8 Filter Design and Analysis Tool Reference

Page 840: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 840/870

8-92

Import Filter Coefficients: State-Space

Specify the A, B, C, and D matrices using any valid MATL AB variable orexpression. See “Filter Structures” for more information.

Press Clear to erase the matrices.

Import Filter Coefficients: Lattice

Page 841: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 841/870

8-93

Import Filter Coefficients: Lattice

Specify the Lattice coeff and Ladder coeff coefficients using any validMATL AB variable or expression. See “Fil ter Structures”for more information.

Press Clear to erase the coefficients.

8 Filter Design and Analysis Tool Reference

Page 842: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 842/870

8-94

Import Filter Coefficients: Quantized Filter (Qfilt Object)

Specify a Qfilt object. See qf i l t in the F ilter Design Toolbox for moreinformation.

Press Clear to erase the data.

Design Filter Tab

Page 843: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 843/870

8-95

Design Filter Tab

Select the Design Filter tab (or press Ctrl+D) to design a filter by specifyingthe filter requirements.

8 Filter Design and Analysis Tool Reference

Page 844: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 844/870

8-96

Import Filter Button

Select this button to import filter coefficients while in the import mode.

Design Filter Button

Page 845: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 845/870

8-97

Design Filter Button

Select this button to design the filter that you specified in the GUI .

8 Filter Design and Analysis Tool Reference

Page 846: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 846/870

8-98

Index

A

Page 847: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 847/870

I-1

AA/D conversion 7-437

abs 7-16

ac2pol y 7-17

ac2r c 7-18

aliased sinc functions 1-13

command for 7-128

aliasing

impulse invariance 2-42

preventing 4-22reducing 4-39

all-pole filters. See IIR filters

all-zero filters. SeeFIR filters

am4-30

AM . Seeamplitude modulation

amdsb–sc 4-30, 7-264

amdsb– t c 4-30, 7-264

amplitude demodulation

double side-band, suppressed carrier 7-125

double side-band, transmitted carri er 7-125

single side-band 7-125

amplitude modulation 4-30

double side-band, suppressed carrier 7-264

double side-band, transmitted carri er 7-264

quadrature 4-31single side-band 7-264

amssb 4-31, 7-264

analog filters 2-39

bandpass 7-247

bandstop 7-250

Bessel 2-12, 2-39, 7-26, 7-27

bilinear transformation 2-43

Butterworth 2-9, 2-39, 7-48, 7-49, 7-50

Chebyshev 2-39

Chebyshev typeI 2-10, 7-62, 7-75

Chebyshev type I I 2-11, 7-81

converting to digital 2-42, 7-215

design 2-8

discretization 2-42

elliptic 2-39, 7-136

frequency response 1-27, 2-13, 7-185

highpass 7-252

impulse invariance 2-42

inverse 7-226

lowpass 7-254

order estimationButterworth 7-55

Chebyshev type I 7-64, 7-69

Chebyshev type I I 7-69

elliptic 7-144

plotting 2-13

representational models 1-42

Seealso IIR filters

analog frequency 29

analog signals. See signals

analytic signals 7-207

angl e 7-19

anti-symmetric filters 2-26

AR filters, stability check 7-316

AR models. See autoregressive (AR) models

arburg 4-12, 7-20arcov 4-12, 7-21

ARM A filters 1-16, 4-14, 4-16

Prony’s method 4-14

Steiglitz-McBride method 4-16

Seealso IIR filters

ar mcov 4-12, 7-22

ARX models 4-14

ar yul e 4-12, 7-23

ASCI I files, importing 1-14

autocorrelation 7-314, 7-448

autocorrelation sequences

converting from reflection coefficients 7-341

Index

estimation variance 3 4 bandstop filters 2 7 7 55 7 64 7 69 7 144

Page 848: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 848/870

I-2

estimation, variance 3-4

filter coefficients

converting to and from 7-17, 7-18, 7-314

filters, multiple channels 3-5

two-dimensional 7-451

autocovariance 7-452

multiple channels 3-5

autoregressive (AR) models 1-16

Burg method 7-20, 7-267, 7-271

covariance method 7-21, 7-273modified covariance method 7-22, 7-293,

7-297

Yule-Walker AR method 7-23, 7-335, 7-339

Seealso IIR filters

autoregressive moving average (ARM A) filters.

SeeARMA filters

averaging filters 1-15

axis labels 6-50

axis parameters

Filter Viewer 6-50

Spectrum Viewer 6-50

B

band edges, prewarping 2-44bandlimited interpolation 7-382

bandpass filters 7-55, 7-64, 7-69, 7-144

Bessel 7-27

Butterworth 7-49

Chebyshev type I 7-75, 7-77

Chebyshev type I I 7-80

design 2-7

elliptic 7-136example, Chebyshev type I 2-40

FIR 2-22, 7-167

impulse invariance 2-42

transformation from lowpass to 7-247

bandstop filters 2-7, 7-55, 7-64, 7-69, 7-144

Bessel 7-27

Butterworth 7-50

Chebyshev type I 7-76

Chebyshev type I I 7-80

elliptic 7-137

FIR 2-22, 7-166

transformation from lowpass to 7-250

bandwidth 2-41

bart l et t 4-3, 7-24example 4-3

t r i ang, comparison to 7-24

Bartlett windows 4-3

coefficients 7-24

Bessel filters 2-12, 2-39, 7-26

bandpass 7-27

bandstop 7-27

characteristics 2-12

highpass 7-27

limitations 7-29

lowpass 7-27

roots 7-26

bessel ap 2-6, 7-26

example 2-12

bessel f 2-6, 2-7, 7-27bias

correlation 3-4, 4-13

power spectral density 3-17, 3-18, 3-23

variancetrade-off 3-4

bi l i near 2-6, 2-42, 2-43, 7-31

bilinear transformations 2-43, 2-44, 7-31

output representation 7-32

prewarping 2-44, 7-31

bl ackman 4-3, 7-36

Blackman windows 4-5, 7-36

boxcar 4-3, 7-38

example 4-3

Index

boxcar windows Seerectangular windows inverse 4-24 4-26

Page 849: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 849/870

I-3

boxcar windows. Seerectangular windows

brackets, indicating closed interval 29

buffering 7-39

Burg method 3-8, 3-9, 3-33

example 3-34

Welch’s method, comparison 3-35

but t ap 2-6, 7-48

example 2-9

but t er 2-6, 2-7, 7-49

Butterworth filters 2-9, 2-39, 7-48bandpass 7-49

bandstop 7-50

characteristics 2-9

design 7-49

generalized 2-15

highpass 7-50

limitations 7-53

lowpass 7-49

order estimation 2-8, 7-54

but t or d 2-6, 7-54

Ccanonical forms 1-18, 7-423

carrier frequency 4-30, 7-264, 7-445carrier signals 4-30, 7-125

cascade, filters 1-38

Cauer filters. See elliptic filters

cceps 4-24, 4-26, 7-59

example 4-24

cel l 2sos 7-61

center frequency 2-41

central features 1-2cepstrum

analysis 4-24

applications 4-24

complex 4-24

inverse 4 24, 4 26

overview 4-24

real 4-24, 4-25, 7-346

reconstructing signals (minimum-phase) 4-26

cheb1ap 2-6, 7-62

example 2-10, 2-40

cheb1or d 2-6, 7-63

cheb2ap 2-6, 7-67

example 2-11

cheb2or d 2-6, 7-68chebwi n 4-3, 7-73, 7-98

cheby1 2-6, 2-7, 7-75

example 2-45

cheby2 2-6, 2-7, 7-80

Chebyshev error minimization 2-23, 7-348

Chebyshev type I filters 2-10, 2-39, 7-62, 7-75

bandpass 7-75, 7-77

bandstop 7-76

characteristics 2-10

design 7-75

highpass 7-76

lowpass 7-75

order estimation 2-8, 7-63

Chebyshev type I I filters 2-39, 7-80

bandpass 7-80bandstop 7-80

characteristics 2-11

highpass 7-80

limitations 7-79

lowpass 7-80

order estimation 2-8

Chebyshev windows 4-9, 7-73

frequency response 4-9

chi rp 1-10, 7-85

chirp signals 1-10

chirp z-transforms (CZT) 4-35, 7-116

discrete Fourier transforms, comparison 4-35

Index

frequency analysis, narrowband 7-116 autocorrelation sequences to and from reflection

Page 850: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 850/870

I-4

frequency analysis, narrowband 7 116

coding, PCM 7-437

coefficients

correlation 7-97

filter 1-16, 6-38, 7-17, 7-314, 7-316, 7-344

linear prediction 7-256

reflection 1-38, 7-18, 7-316, 7-341, 7-344

sequence 7-341

cohere 3-9, 3-29, 7-88

linearly dependent data 3-30coherence 3-29, 7-88

linearly dependent data 3-30

colors, SPTool 6-50

communications 4-11, 4-30, 7-264

Seealso modulation, demodulation, voltage

controlled oscil lation

communications simulation 7-125

compact disc standards 4-21

compaction 4-38

complex conjugate 7-102

complex envelope. SeeHilbert transforms

complex numbers, grouping by conjugate 7-102

confidence intervals

cross spectral density 3-27

power spectral density 3-27warnings 3-27

context-sensitive help 5-6, 6-17

continuous signals. Seesignals

continuous-time filters. Seeanalog filters

control systems 1-36

Control Systems Toolbox 1-36, 7-219, 7-411

conv 1-15, 1-21, 7-92

conv2 1-15, 7-93

conventions in our documentation (table) 30

conversions

autocorrelation sequences to and from filter

coefficients 7-17

autocorrelation sequences to and from reflection

coefficients 7-18

filter coefficients to autocorrelation sequences

7-314

filter coefficients to reflection coefficients 7-316,

7-344

functions (table) 1-43

reflection coefficients to autocorrelation

sequences 7-341

second-order section forms to state-space forms7-385

second-order section forms to transfer functions

7-387

second-order section forms to zero-pole-gain

forms 7-389

state-space forms to second-order section forms

7-403

state-space forms to zero-pole-gain forms 7-409

transfer functions to lattice forms 7-417

transfer functions to second-order section forms

7-418

transfer functions to state-space forms 7-422

zero-pole-gain forms to second-order section

forms 7-458

zero-pole-gain forms to state-space forms 7-462convmt x 1-41, 1-43, 7-95

convolution 7-92

cross-correlation 3-3

example 1-15

filtering 1-15, 7-161

matrices for 1-41, 1-43, 7-95

example 7-95

two-dimensional 7-93

cor r coef 7-97

correlation 3-2

bias 3-4, 4-13

coefficient matrices 7-97

Index

cross-correlation 7-447 D

Page 851: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 851/870

I-5

matrices

covariance method 7-98

modified covariance method 7-98

Seealso autocorrelation sequences,

cross-correlation sequences

correlation matrices 7-98

corr mt x 7-98

cosine windows 4-5

cov 7-101covariance 3-2

matrices 7-101

Seealso autocovariance, cross-covariance

covariance method 3-9, 3-36, 7-277

example 3-36

Seealso modified covariancemethod

cpl xpai r 7-102

cr emez 2-17, 7-103

cross spectral density 3-27, 7-111

confidenceintervals 3-27

Seealso power spectral density, spectral

estimation

cross-corr elation sequences 3-3

estimation 7-447

biased 3-4unbiased 3-4

filters, multiple channels 3-5

normalization 3-5

two-dimensional 7-451

cross-covariance 3-3, 7-452

multiple channels 3-5

cs d 3-9, 3-27, 7-111

cutoff frequency 2-39, 7-27

cz t 4-36, 7-116

CZT. Seechirp z-transforms

DD.C. component suppression 1-47

data

multichannel 1-5, 1-8

vectors 1-7

data compression 4-11

data matrices 1-5, 1-8

data vectors 1-5

dct 4-37, 7-119

example 4-38deci mat e 7-121

decimation 7-121

FI R filter for 7-223

decoding 7-434

deconv 4-34, 7-124

example 4-34

deconvolution 4-34, 7-124

default session file 6-50

delays

group 1-29

noninteger 2-27

phase 1-29

signals 2-27

demod 4-30, 4-31, 7-125

example 4-31demodulation 4-31, 7-125

amplitude, quadrature 7-126

example 4-31

methods 4-31, 7-125

phase 7-126

pulse time 7-126

pulse width 7-126

DFT. Seediscrete Fourier transforms

df t mt x 7-127

difference equations 1-33

differentiators 2-27, 7-179, 7-350

digital audio tape standards 4-21

Index

digital filters poles 1-31, 1-34

Page 852: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 852/870

I-6

anti-causal 1-21

Butterworth 7-49

cascade 1-38

Chebyshev type I 7-75

Chebyshev type I I 7-80

coefficients 1-16

convolution matrices 1-41

design 2-3

elliptic 7-136FIR 2-17

I I R, comparison to 2-17

fixed-point implementation 1-38

frequency data, identification from 7-230

frequency response 1-25

group delay 1-29, 7-200

II R 2-5

FI R filters, comparison to 2-5

implementation 1-15, 7-155, 7-158

convolution 1-15

FFT-based (F I R) 7-155

f i l t er 1-17

overlap-add method 1-23

impulse response 1-15, 1-24, 7-217

initial conditions 1-18li near models 1-33

models 1-33

names 1-16

order 1-16

state-space representation 1-35

order estimation

Butterworth 7-54, 7-63, 7-68

Chebyshev type I 7-63, 7-68

Chebyshev type I I 7-68

elliptic 7-143

equiripple F I R 7-356

phase delays 1-29, 7-200

second-order sections 1-38

specifications 2-8

startup transients 1-22

structures

lattice/ladder 1-38

transposed direct form I I 1-18

time-domain representation 1-17

transfer functions representation 1-16

transients 1-23two-dimensional 7-161

zero-phase 1-21, 7-162

zeros 1-31, 1-34

Seealso FI R filters, I IR filters

digital frequency 29

direct design 2-6

di r i c 7-128

Dirichlet functions 1-13

command for 7-128

discrete cosine transforms (DCT) 7-119

appli cations 4-37

energy compaction property 4-38

example 4-38

inverse 4-37, 7-211

signals, reconstructing 4-38discrete Fourier transforms (DFT) 1-3, 1-45, 2-27,

7-151

algorithms 1-46

appli cations 7-151

eigenvector equivalent 3-38

example 1-46

I I R filter implementation 1-23

inverse 1-45, 7-213

matrices 7-127

two-dimensional 1-47, 7-214

magnitude 1-46

matrices 7-127

Index

phase 1-46 example 2-11

Page 853: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 853/870

I-7

signal length dependencies 1-46

spectral analysis 3-6, 3-10

time-dependent 4-28

two-dimensional 1-47, 7-154

Seealso fast F ourier transforms (FF T), f f t

discrete prolate spheroidal sequences

See DPSS

discretization 7-215

bilinear transformations 2-43prewarping 2-44

impulse invariance 2-42

discretization, filters 2-42

disk, loading variables from 6-47

division, polynomials 7-124

DPSS

direct method 7-130

interpolation 7-129

dpss 7-129

dpss. mat 3-26

dpsscl ear 3-26, 7-132

dpssdi r 3-26, 7-133

dpssl oad 3-26, 7-134

dpsssave 3-26, 7-135

duty cycles 1-9

Eechoes, detection 4-24

edge effects 1-23

eigenanalysis 3-37

frequency estimation 3-37

eigenvector method 3-8, 3-36, 7-279root MUSI C 7-368

Seealso multiple signal classification method

el l i p 2-6, 2-7, 7-136

el l i pap 2-6, 7-142

el l i por d 2-6, 7-143, 7-148

elliptic filters 2-39, 7-136

bandpass 7-136

bandstop 7-137

characteristics 2-11

highpass 7-137

limitations 7-140

lowpass 7-136

order estimation 2-8, 7-143, 7-148encoding

PCM 7-437

uniform 7-437

eqt f l engt h 7-148

equiripple characteristics

Chebyshev type I filters (passband) 2-10

Chebyshev type I I filters (stopband) 2-11

Chebyshev windows 4-9

elliptic filters 2-11, 7-136, 7-142

Parks-McClellan design 7-348

equiripple filters 2-23

error minimization

desired and actual response, between 2-23

frequency bands, weighting 2-26

minimax 2-23estimation

cross spectral density 3-27

nonparametric

multiple signal classification method

(MU SIC) 3-8

multitaper method (MTM) 3-8

Welch’s method 3-8

parametric 3-8Burg method 7-20

covariancemethod 7-21

modified covariance method 7-22

Yule-Walker method 7-23

Index

spectral density 3-8, 3-10

t f f ti 3 28

implementation 1-18

i iti l diti t 1 18

Page 854: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 854/870

I-8

transfer functions 3-28

Seealso parametri c modeling

Ffast F ourier transforms (FF T) 1-23, 1-45

f f t 1-23

frequency response 1-25

radix-2 algorithm 7-153signal processing, role in 1-45

two-dimensional 7-154

f dat ool 5-1

context-sensitive help 5-6

help on 5-6, 6-17

opening 5-5

f f t 1-3, 1-23, 1-45, 7-151

example 1-46execution time1-46

number of samples 1-46

output 1-47, 7-157

radix-2 algorithm 7-153

FFT filtering 1-23

FFT. Seefast Fourier transforms

f f t 2 1-47, 7-154

output 1-47

f f t f i l t 1-20, 7-155

f i l t er , comparison to 7-155

f f t shi f t 1-47, 1-47, 7-157

filter

coefficients 1-16

median 4-29

order 1-16f i l t er 1-3, 1-17, 1-21, 7-158

f f t f i l t , comparison to 7-155

f i l t f i l t , comparison 1-22

final condition parameters 1-18

initial condition parameters 1-18

initial conditions 7-163

fil ter coefficients

reflection coefficients, conversions to 7-316,

7-344

filter design graphical user interface. Seef datool

filter design GUI 5-2

analysis buttons 5-13

analysis functions 5-13computing coefficients 5-12

context-sensitive help 5-6

design methods 5-8

design sessions

opening 5-21

saving 5-21

exporting filters 5-19

filter design specifi cation 5-9

filter order specification 5-11

filter type5-7

filters

architecture 5-14

implementation 5-14

realization 5-14

structure 5-14frequency response specification 5-9

group delay 5-13

help on 5-6

importing coefficients 5-16

importing filters 5-16

impulse response 5-13

magnitude response 5-13

magnitude response specs 5-10opening 5-5

phase delay 5-13

phase response 5-13

pole-zero plots 5-13

Index

saving coefficients 5-19

step response 5 13

anti-symmetric 2-26

averaging 1 15

Page 855: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 855/870

I-9

step response 5-13

Filter Designer 6-8, 7-397

FF T length 6-50

filter types 6-8

filters

editing 6-45

redesigning 6-37

saving 6-33

FI R filters 6-8F I R methods 6-8

grid lines 6-50

I I R methods 6-8

opening 6-9, 6-22

overview 6-8

plots

customizing 6-50

magnitude 6-37

Pole/Zero Editor 6-34

sample frequency 6-38

spectra, overlaying 6-9

zooming 6-50

filter parameters 6-50

Filter Viewer 6-11, 7-399

axis parameters 6-50filter parameters 6-50

measurements 6-51

opening 6-11

overview 6-11

preferences, til ing 6-50

printing 6-28

rulers 6-51

zooming 6-50f i l t er 2 7-161

filters 1-3

analog 2-9, 2-12, 7-26, 7-48, 7-62

anti-causal 1-21

averaging 1-15

bandpass

Butterworth 7-54

Chebyshev type I 7-63

Chebyshev type I I 7-68

elliptic 7-143

bandstop

Butterworth 7-54

Chebyshev type I 7-63Chebyshev type I I 7-68

elliptic 7-143

Butterworth 2-8, 7-49

generalized 2-15

Chebyshev 2-8

type I 7-75

type I I 7-80

coefficients 1-17, 1-33, 2-18, 6-38

converting to autocorrelation sequence

7-314

convolution 1-15

creating 2-8

design 6-8

Filter Designer 6-8

FIR 2-23generalized 2-6

discretization 2-42

elliptic 2-8, 7-136

equiripple 2-23

FIR 7-348

single band 2-21

frequency data, identification from 7-226

frequency domain 1-23frequency transformation functions 2-39, 2-40

highpass

Butterworth 7-54

Chebyshev type I 7-63

Index

Chebyshev type I I 7-68

elliptic 7 143

initial conditions 1-22

f i l t i c 1 19 7 163

Page 856: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 856/870

I-10

elliptic 7-143

implementation 1-23, 7-155, 7-158

initial conditions 1-18, 1-19

inverse 7-226, 7-230

lattice/ladder 1-38

li near phase2-17, 2-18

linear time-invariant digital 1-3

lowpass

Butterworth 7-54Chebyshev type I 7-63

Chebyshev type I I 7-68

elliptic 7-143

measurements 6-51

median 7-263

minimax 2-23

minimum phase 7-319

names 1-16

order 1-16, 2-8, 7-54, 7-63, 7-143, 7-148

order estimation 2-8

phase, modulation 4-26

prediction 4-13

quantized, state vectors 7-159

Savitzky-Golay 7-378, 7-380

Schur realizations 7-375second-order section forms 1-38, 1-44, 7-391

specifications 2-8

SPTool 6-43

transposed direct form I I structure 1-18

two-dimensional 7-161

types 2-18

zero-phase 1-21, 7-162

Seealso FI R filters, I I R filters, digital filters,analog filters

f i l t f i l t 1-20, 1-21, 2-5, 7-162

example 1-21

f i l t er , comparison 1-22

f i l t i c 1-19, 7-163

FI R filters 1-16, 2-17

decimation 7-223

differentiators 2-27, 7-179, 7-350

equiripple 2-17, 2-23, 2-24

example 6-18

Filter Designer 6-8

frequency domain 1-20

frequency response 7-169Hilbert transformers 2-26, 7-179, 7-350

I I R filters, comparison 2-17

implementation 1-18, 7-158

FF T-based 1-23, 7-155

overlap-add method 1-23, 7-155

interpolation 7-223

K aiser windows 4-7

lattice/ladder 1-38

least squares 2-17, 2-24, 7-178

constrained 2-17, 2-28

equiripple, comparison 2-24

li near phase 2-29

multiband 2-29, 2-30

weighted 2-31

linear phase 2-18, 2-23, 7-178, 7-348multiband 2-17, 2-22, 2-23

order estimation, r emez 7-356

overlap-add method 7-155

Parks-McClellan method 2-23, 7-348

raised cosine method 2-17

resampling 1-20

responses 2-32

complex filters 2-17, 7-103delays, reducing 2-35

nonlinear phase 2-17, 7-103

standard band 2-21

types 7-181, 7-353

Index

windowing method 2-17

windows 2-19 7-165

frequency analysis, time-dependent 7-392

frequency demodulation 7-126

Page 857: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 857/870

I-11

windows 2 19, 7 165

f i r 1 2-17, 2-21

f i r 2 2-17, 2-21

f i r c l s 2-17, 7-172

f i r cl s1 2-17, 7-175

f i r l s 2-17, 2-23, 7-178

differentiators 2-27

filter characteristics 7-181

r emez , comparison to 2-24weight vectors 2-26

f i r r cos 2-17, 7-183

fixed-point implementation, digital filters 1-38

f m4-31

F M. See frequency modulation

f open 1-14

Fourier transforms. See discrete Fourier

transforms, fast Fourier transformsf r ead 1-14

f r eqs 1-27, 7-185

f r eqspace 7-188

frequency 7-349

analog 29

angular 2-3

carrier 4-30, 7-264, 7-445center 2-41

cutoff 2-39

digital 29

estimation

eigenanalysis 3-37

eigenvector (EV) method 3-37

multiple signal classification (MU SI C)

method 3-37normalization 2-3

Nyquist 29, 2-3

prewarping 7-31

vectors 2-25, 7-169, 7-172, 7-455

frequency demodulation 7 126

frequency domain

duality with time-domain 1-23

filters 1-23

FI R filtering 1-20

transformation functions 2-39, 7-247, 7-250,

7-252, 7-254

example 2-41

lowpass to bandpass 7-247lowpass to bandstop 7-250

lowpass to highpass 7-252

frequencydomain based modeling. Seeparametric

modeling

frequency modulation 7-265

frequency response 1-25, 2-14, 7-169

Bessel filters 2-12

Butterworth filters 2-9Chebyshev type I filters 2-10

Chebyshev type I I filters 2-11

Chebyshev windows 4-9

elliptic filters 2-11

error minimization 2-23

evaluating 1-25

example 1-26inverse 7-226

K aiser window 4-6

li near phase 2-18

magnitude 1-27

monotonic 2-9

multiband 2-14

phase 1-27

unwrapping 1-28plotting 1-26, 7-193

samples, spacing 7-188

sampling frequency 1-25

frequency vectors 7-349

Index

f r eqz 1-25, 7-189

sampling frequencies 1-25

Butterworth 7-50

Chebyshev type I 7-76

Page 858: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 858/870

I-12

sa p g eque c es 5

sampling frequency 1-25

spacing 7-188

f r eqzpl ot 7-193

F rom Disk radio button 6-47

f scanf 1-14

Ggains, scalar 1-34

gauspul s 1-10, 1-11, 7-196, 7-198, 7-199

Gauss-Newton method 7-229, 7-232

generalized Butterworth filters 2-15

generalized cosine windows 4-5

generalized filters 2-6

Gibbs effect 2-20

reduced by window 4-3graphical user interface (GUI ) 1-4

Seealso interactive tools, SPTool

grid lines 6-50

group delay 1-29, 2-18, 7-200

example 1-30

passband 2-12

gr pdel ay 1-29, 7-200

GUI -based tools. See interactive tools

Hhammi ng 4-3, 7-203

Hamming windows 2-20, 3-18, 4-5, 7-203

hann 7-205

Hann windows 7-205Hanning windows 4-5, 7-205

hanni ng. Seehann

highpass filters 2-7, 7-55, 7-64, 7-69, 7-144

Bessel 7-27

C ebys e ype 6

Chebyshev type I I 7-80

elliptic 7-137

FIR 2-22, 7-167

lowpass, transformation from 7-252

hi l ber t 2-27, 4-39

example 4-39

Hilbert transformers 7-179, 7-350

Hilbert transforms 4-35, 4-39, 7-207analytic signals, of 2-27

example 4-39

instantaneous attributes 4-40

homomorphic systems 4-24

Hz 7-268, 7-274, 7-294, 7-336

Ii cceps 4-24, 4-26, 7-210

example 4-27

i dct 4-37, 7-211

ideal lowpass filters 2-19

Seealso lowpass filters

i f f t 1-45, 7-213

samples, specifying 1-47

i f f t 2 1-47, 1-47, 7-214

I I R filters 2-5, 2-6, 2-8, 2-9, 2-14

Bessel 2-12

Butterworth 2-8, 2-9

Butterworth, generalized 2-15

Chebyshev 2-8, 2-10, 2-11

Chebyshev type I 2-10

Chebyshev type I I 2-11design 2-7, 2-38

elliptic 2-8, 2-11

Filter Designer 6-8

filter types, comparison 2-9

Index

FI R filters, comparison to 2-5

frequency response 2-14

Filter Designer 6-8, 7-397

Filter Viewer 7-399

Page 859: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 859/870

I-13

q y p

implementation 7-158

frequency domain 1-23

zero-phase 1-21

lattice/ladder 1-38

L evinson-Durbin recursion 7-245

maximally flat 2-15

multiband 2-14

order estimation 2-8plotting responses 2-13

Prony’s method 7-320

specifications 2-8

Steiglitz-McBride iteration 7-412

Yule-Walker 2-14, 7-455

Seealso direct design

imageprocessing 1-47, 7-93

i mpi nvar 2-6, 2-42, 7-215I mport dialog box

F rom Disk radio button 6-47

Workspace Contents list 6-19

impulse invariance 2-42, 7-215

limitations 2-42

impulse response 1-24, 7-217

computing with f i l t er 1-24computing with i mpz 1-24

example 1-24

impulse invariance 2-42

lowpass filters, ideal 2-19

i mpz 7-217

example 1-24

indexing 1-16

initial conditions 1-18, 1-19, 1-22, 7-163instantaneous attributes 4-40

interactive tools 1-4, 6-3

example 6-18

F ilter Design and Analysis Tool 5-2

Signal Browser 7-397

Spectrum Viewer 6-14, 7-400

SPTool 7-396

i nterp 7-220

interpolation 7-220

bandlimited 7-382

FI R filters 7-223

interval notation 29i nt f i l t 7-223

inverse cepstrum, complex 4-26

inverse discrete cosine transforms 7-211

accuracy of signal reconstruction 4-39

inverse discrete Fourier transforms 1-45, 7-213

i f f t 1-45

matrices 7-127

two-dimensional 1-47, 7-214inverse filters 7-230, 7-320

analog 7-226

digital 7-230

inverse Fourier transforms, continuous. Sees i nc

inverse-sine parameters

reflection coefficients, transformations from

7-233reflection coefficients, transformations to

7-342

i nvf r eqs 2-6, 4-12, 4-18, 7-226

i nvf r eqz 2-6, 4-12, 4-18, 7-230

i s2rc 7-233

K kai ser 4-3, 7-234

example 4-6

K aiser window 3-20

K aiser windows 4-5, 7-234

Index

beta parameter 4-5, 7-234

example 4-6

li near system transformations. See conversions

l oad 1-14

Page 860: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 860/870

I-14

FI R filters 4-7

frequency response 4-6

kai ser or d 2-17, 7-236

Lladder filters. See lattice/ladder filters

L agrange interpolation filter 7-223

L aplace transforms 1-42

state-space forms 1-42

l ar2rc 7-241

l atc2t f 1-41, 1-43, 7-242

l at cf i l t 1-20, 1-41, 7-243

lattice/ladder filters 1-38, 1-39, 1-43

coefficients 1-39

l at cf i l t 1-41Schur algorithm 7-375

transfer functions, conversions from 7-417

least squares method, FI R filters 7-178, 7-181

l evi nson 4-12, 7-245, 7-365

parametric modeling 4-13

L evinson-Durbin recursion 4-13, 7-245, 7-365

line spectral frequencies

prediction polynomial coefficients,

transformation from 7-315

prediction polynomial coefficients,

transformation to 7-260

line style, SPT ool 6-50

linear models. See models

li near phase2-17, 2-18, 7-178

characteristics 2-18filters 7-348

linear prediction coefficients 7-256

linear prediction modeling 4-13

linear predictive coding 4-13

log area ration parameters

reflection coefficients, transformations from

7-241

reflection coefficients, transformations to 7-343

lowpass filters 2-7, 7-55, 7-64, 7-69, 7-144

Bessel 7-27

Butterworth 7-49

Chebyshev type I 7-75Chebyshev type I I 7-80

cutoff frequency, translation of 7-254

decimation 7-121

elliptic 7-136

FIR 2-22

ideal 2-19

impulse invariance 2-42

impulse response 2-19interpolation 7-220

l p2bp 2-6, 2-40, 7-247

example 2-41

l p2bs 2-6, 2-40, 7-250

l p2hp 2-6, 2-40, 7-252

l p2l p 2-6, 2-40, 7-254

l pc 2-6, 4-12, 7-256Seealso linear predictive coding, Prony’s

method

LPC. See linear prediction coefficients

l s f2pol y 7-260

M

magnitudeF ourier transforms 1-46

frequency response 1-27

plots 6-37

transfer functions 3-28

Index

vectors 2-25, 7-169, 7-172, 7-455

manufacturing 4-11

method flags 4-30

modulation 4-30, 7-264

Page 861: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 861/870

I-15

match frequency (for prewarping) 7-31MAT-files

dpss. mat 3-26

format, converting to 1-14

importing 1-14

SPTool 6-47

matrices

convolution 1-41, 7-95correlation coefficient 7-97

covariance 7-101

data 1-5, 1-8

discrete Fourier transforms 7-127

inverse discrete Fourier transforms 7-127

matrix forms. Seestate-space forms

maxf l at 2-6, 2-15, 7-261

maximally flat filters 2-15medf i l t 1 4-29, 7-263

median filters 4-29, 7-263

MEX-files 1-14

M-files 1-4

minimax method, FI R filters 2-23

Seealso Parks-McClellan method

minimum phase 7-319models 1-33

autoregressive 7-20, 7-21, 7-22, 7-23

Burg method 7-267, 7-271

covariancemethod 7-273

modified covariance method 7-293, 7-297

Yule-Walker AR method 7-335, 7-339

bilinear transformations 2-44

transformations, discrete/continuous 2-44modified covariance method 3-36

example 3-36

modul at e 4-30, 4-31, 7-264

example 4-31

amplitude 4-30Seealso amplitude modulation

example 4-31

frequency 4-31

phase 4-31

pulse time 4-31

pulse width 4-31

quadrature amplitude 4-31results of 4-31

signals 4-30, 7-264

moving average (MA) filters 1-16

Seealso FIR filters

MTM. Seemultitaper method

multiband filters

FIR 2-22

FI R, with transition bands 2-23IIR 2-14

multichannel data 1-8

multiple signal classification method (MU SI C)

3-8, 3-9, 3-36, 7-305, 7-311

correlation matrices 7-98

eigenvector method 7-279, 7-284

root music 7-371multiplication, polynomials 7-92

multiplicity, of zeros and poles 6-35

multirate filters 1-20

banks 1-20

multitaper method (MT M) 3-8, 3-9, 3-24

average power, conservation of 3-26

example 3-25

Welch’s method, comparison to 3-26MUSIC algorithm. See multiple signal

classification method

Index

Nnonrecursive filters. SeeFIR filters

Parks-McClellan method 2-23, 7-348

partial fraction expansion 1-36, 1-42, 1-43, 7-362

Page 862: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 862/870

I-16

normalization 3-4correlation 3-5, 7-447, 7-448

power spectral density 3-17, 3-18, 3-23

Nyquist frequency 29, 2-3, 7-136

Nyquist interval 7-136

Oorder

estimation 2-8, 7-356

Butterworth 7-54

Chebyshev type I 7-63

elliptic 7-143, 7-148

filters, of 1-16, 2-8

oscil lators, voltage controll ed 7-445

overlap-add methodFI R filter implementation 1-23

FI R filters 7-155

PPanner check box, Signal Browser 6-50

parametric modeling 4-11, 7-230

applications 4-11

frequency domain based 4-18

summary 2-6

techniques 4-11

time-domain based 4-13

Burg method 7-20

covariance method 7-21

linear predictive coding 4-13, 4-14modified covariance method 7-22

Steiglitz-McBride method 4-16

Yule-Walker method 7-23

parentheses, indicating open interval 29

determining with r esi due 1-42example 1-36

passband 7-54, 7-63, 7-68, 7-143

equiripple 2-10, 2-11

group delay 2-12

pburg 3-9, 3-34, 7-267

example 3-34

PCM 7-437pcov 3-9, 3-36, 7-273

example 3-36

pei g 3-36

pei g 7-279

period, finding in a sequence 7-376

periodic sinc functions 7-128

Seealso Dirichlet functions

per i odogr am7-287periodograms 3-10, 7-287, 7-291

phase

computing 7-19

delays 1-29, 2-18, 7-200

example 1-30

demodulation 7-126

distortioneliminating 1-20, 1-21

FI R filters 1-21

I I R filters 1-21

F ourier transforms 1-46

frequency response 1-27

modulation 4-31, 7-265

filters 4-26

transfer functions, of 3-28unwrapping 1-28, 7-440

plots

analog filters 2-13

cepstrum, complex 4-25

Index

coherence function 3-29

DFT 1-46

f 1 26

confidenceintervals 3-27

estimation

B th d 3 9 3 33 7 267

Page 863: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 863/870

I-17

frequency response 1-26functions for 7-322

group delay 1-30

magnitude 1-27, 6-37

phase 1-27

delays 1-30

strip plots 7-415

transfer functions 3-28zero-pole 1-31, 7-466

plotting functions 7-193

plug-ins 6-50

pm4-31

pmcov 3-9, 3-36, 7-293

example 3-36

p-model. Seeparametric modeling

pmt m3-9, 7-299example 3-25

pmusi c 3-9, 3-36, 7-305

Pole/Zero Editor 6-34

pole-zero filters. See IIR filters

pol y 1-34, 1-43

pol y2ac 7-314

pol y2l sf 7-315

pol y2r c 7-316

polynomials

division 4-34, 7-124

multiplication 7-92

roots 1-34, 1-43

scaling 7-319

stabil ity check 7-316

stabilization 7-318polyphase filtering techniques 1-20

pol ystab 7-318, 7-319

power spectral density 3-6

bias 3-17, 3-18, 3-23

Burg method 3-9, 3-33, 7-267covariancemethod 3-9, 3-36, 7-273

modified covariance method 3-9, 7-293

multitaper method 3-24, 7-299

MUSIC method 3-37, 7-305

root music 7-368, 7-371

Welch’s method 3-9, 3-20, 3-23

Yule-Walker AR method 3-9, 3-32, 7-335multitaper method 3-9

MUSI C method 3-9

normalization 3-17, 3-18, 3-23

plots 6-14

Spectrum Viewer 6-14

SPTool 6-45

units of 3-7

prediction filters 4-13prediction polynomials

line spectral frequencies, transformations from

7-260

line spectral frequencies, transformations to

7-315

Preferences menu item 6-50

prewarping 7-31

Print dialog box 6-28, 6-31

Print P review window

Signal Browser preferences 6-28

Spectrum Viewer 6-31

printing, Spectrum Viewer 6-51

prolate-spheroidal windows 4-5

prony 2-6, 4-12, 4-14, 7-320

Prony’s method 4-14, 7-320modeli ng 4-14

psdpl ot 7-322

pseudospectrum 7-311

eigenvector method 7-279, 7-284

Index

MUSI C algorithm 7-311

pt m4-31

pulse time demodulation 7 126

r c2pol y 7-344

r ceps 4-24, 4-26, 7-346

rebuffering 7 39

Page 864: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 864/870

I-18

pulse time demodulation 7-126pulse time modulation 4-31, 7-265

pulse train generator 7-324

pulse trains

generating 1-11

pul st r an 1-11

pulse width demodulation 7-126

pulse width modulation 4-31, 7-265pul st r an 1-11, 7-324

pwel ch 3-9, 3-20, 7-328

pwm4-31

pyul ear 3-9, 3-32, 7-335

example 3-33, 3-34

Qqam4-31

quadrature amplitude demodulation 7-126

quadrature amplitude modulation 4-31, 7-265

quantization 7-434, 7-437

PCM 7-437

quantized filters 7-159

second-order sections

coefficients in a cell array 7-384

coefficients in a matrix 7-61

Rradar applications 4-28

raised cosine filters 7-183

r andn 27random number, generation 27

rangenotation 29

r c2i s 7-342

rc2l ar 7-343

rebuffering 7-39rectangular windows 2-19, 4-3, 7-38

r ectpul s 7-347

recursive filters. See IIR filters

references 1-48, 3-39, 4-41

reflection coefficients 1-38, 1-39

converting to autocorrelation sequence 7-341

filter coefficients, conversions from 7-316,7-344

inverse sine parameters, transformation from

7-342

inverse sine parameters, transformation to

7-233

log area ratio parameters, transformation from

7-343

log area ratio parameters, transformation to7-241

Schur algorithm 7-375

r emez 2-17, 2-23, 7-348

differentiators 2-27

filter characteristics 7-353

f i r l s, comparison to 2-24

Hilbert transformers 2-26

order estimation 7-356

weight vectors 2-26

Remez exchange algorithm 2-23, 7-348

r emezor d 2-17, 7-356

r esampl e 7-359

resampling 4-21, 7-359

FI R filters 1-20

Seealso decimation, interpolationr esi due 1-42, 1-43, 1-43

residue forms. See partial fraction expansion

r esi duez 1-43, 7-362

r l evi nson 7-365

Index

root MUSI C 7-371

eigenvector method 7-368

r oot ei g 7 368

SPTool 6-44

state-space forms, conversions from 7-403

state space forms conversions to 7 385

Page 865: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 865/870

I-19

r oot ei g 7-368r oot musi c 7-371

roots 1-34, 1-43

polynomials 1-34

rulers

positioning 6-51

Signal Browser 6-50

Spectrum Viewer 6-50

Ssampling frequency

changing

noninteger resampling factors 4-21, 7-359

with upf i r dn 1-20

decreasing by integer factor 7-121FI R filters 1-20

f r eqz 1-27

increasing 7-220

irregularly spaced data 4-23

Nyquist interval 7-136

range 1-27

spacing 1-27

saving data

Spectrum Viewer 6-42

Savitzky-Golay filters 7-378, 7-380

sawt oot h 1-9, 7-368, 7-374

sawtooth wave 1-9

scaling 7-318

schur 7-375

Schur algorithm 7-375schurrc 7-375

second-order section forms 1-38, 1-43

filters 7-391

matrices 1-38

state-space forms, conversions to 7-385transfer functions, conversions from 7-387,

7-418

zero-pole-gain forms, conversions from 7-458

zero-pole-gain forms, conversions to 7-389

second-order sections

coefficients in cell arrays 7-384

coefficients in matrices 7-61seqper i od 7-376

sgol ay 7-378, 7-380

sgol ayf i l t 7-380

Signal Browser 6-6, 7-397

axis labels 6-50

markers, preferences 6-50

opening 6-6

overview 6-6Panner, preferences 6-50

Print Preview window 6-28

printing 6-6, 6-26, 6-28, 6-51

signals, measuring 6-51

zooming, preferences 6-50

Signal Processing Toolbox 1-3

signals 2-27

adding noise 1-7

analytic 4-39, 7-207

aperiodic 1-10

appli cations 4-39

array 6-6

buffering 7-39

carrier 4-30, 7-125

chirp 1-10continuous (analog) 1-3

differentiators 2-27

di r i c 1-13

discrete (digital) 1-3

Index

generating 1-8

linear swept-frequency cosine. See chirp

measurements 6-51

specifications, filters 2-8

spectra. Seespectrum

spectral analysis 3-6

Page 866: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 866/870

I-20

measurements 6-51modulation 4-30, 7-264

multichannel 3-5

periodic 1-9

plotting 1-7

properties 4-39

pul st r an 1-11

rebuffering 7-39reconstruction

DCT coefficients, from 4-38

minimum phase4-26, 7-346

representing 1-5

multichannel 1-5

single channel 1-5

sawtooth 1-9, 7-374

example 1-9s i nc 1-12

sinusoidal 1-7, 1-10

pulse, Gaussian-modulated 1-10

square wave 1-9, 7-402

triangle 7-374

s i nc 1-12, 7-382

bandlimited interpolation example 7-382

sinc functions 1-12, 7-382

basic example 1-12

Slepian sequences. Seediscrete prolate

spheroidal sequences

sonar applications 4-28

sos2cel l 7-384

sos2ss 1-43, 7-385

sos2t f 1-43, 7-387sos2zp 1-43, 7-389

specgr am4-28, 7-392

example 4-28, 7-445

specification li nes. See Filter Designer

spectral analysis 3-6cross spectral density 3-27

power spectrum 3-6

Spectrum Viewer 6-14

Seealso spectral estimation

spectral density 3-6

measurements 6-51

plotting functions 7-322Spectrum Viewer 6-14

units of 3-7

Seealso power spectral density, cross spectral

density

spectral density plots 6-14

spectral estimation 3-10

Burg method 3-9, 3-33, 7-267, 7-268

covariancemethod 7-273, 7-277eigenvector method 7-279, 7-280, 7-284

modified covariance method 3-9, 7-293

multitaper method 3-9, 7-299

MUSIC algorithm 7-305, 7-311

MUSIC method 3-9, 7-306

nonparametric

multiple signal classification method

(MU SIC) 3-8

multitaper method (MTM) 3-8

Welch’s method 3-8

parametric

Burg method 7-20

covariancemethod 7-21

modified covariance method 7-22

Yule-Walker method 7-23periodograms 7-291

root MUSIC 7-368, 7-371

Welch’s method 3-8, 3-9, 3-20, 3-23, 3-27, 7-91,

7-113, 7-328, 7-332

Index

Yule-Walker AR method 2-14, 3-8, 3-9, 3-32,

3-33, 7-335, 7-336

spectrogram 4-28, 7-392

parameters 6-38

specifications 6-39

filters, saving 6-33

Page 867: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 867/870

I-21

spectrogram 4 28, 7 392example 4-28, 7-445

Spectrum Viewer 6-14, 7-400

activating 6-14

axis parameters 6-50

markers, preferences 6-50

measurements 6-51

opening 6-14

overview 6-14

Pr int Preview 6-31

printing 6-14, 6-28, 6-51

rulers 6-51

spectra structures 6-42

spectral density plots 6-14

windows 6-15

zooming 6-50speech processing 4-11, 4-22

spl i ne 4-23

SPTool 6-3, 7-396

colors, customizing 6-50

context-sensitive help 6-17

customizing 6-50

data

entering 1-14

objects 6-48

selecting 6-48

data structures 6-4

editing 6-49

example 6-18

exporting data 1-14, 6-32

filter design 6-22filtering 6-24

filters 6-43

coefficients 6-38

importing 6-21, 6-43

filters, saving 6 33help on 6-17

I mport dialog 6-19

importing 1-14, 6-19, 6-21, 6-43

items, selecting 6-48

line style, customizing 6-50

MA T-files 6-47

MATLAB workspace 6-4

multiselection of items 6-48

operation 6-4

Pole/Zero Editor 6-34

preferences 6-50

Preferences menu item 6-50

Print dialog box 6-28, 6-31

printing 6-28

filters 6-28spectra 6-28

right-click edit menu 6-49

rulers 6-51

sample frequency 6-38

saving 6-32

second-order section forms 6-44

Signal Browser 6-26

signals

analysis 6-26

measurements 6-51

playing 6-27

sound 6-27

spectra

analyzing 6-29

importing 6-21spectral densities

importing 6-43, 6-45

plots 6-45

Spectrum Viewer 6-29

Index

state-space forms 6-44

transfer functions

exporting 6-38

structures

lattice/ladder 1-38

transposed direct form I I 7-159

Page 868: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 868/870

I-22

p gspecifying 6-44

workspace 6-4

zero-pole-gain forms 6-44

spt ool 7-396

square 1-9, 7-402

square wave 1-9

ss2sos 1-43, 7-403

ss2tf 1-43, 7-407

ss2zp 1-43, 7-409

stabil ity check, polynomials 7-316

stabilization 7-319

standards, digital audio tape 4-21

startup transients, reducing 1-22, 7-162

state vectors 7-159

state-space forms 1-35, 1-42, 1-43scalar 1-35

second-order section forms, conversions from

7-385

second-order section forms, conversions to

7-403

SPTool 6-44

transfer functions, conversions to 7-422

zero-pole-gain forms, conversions from 7-462

zero-pole-gain forms, convertions to 7-409

statistical operations 3-3

Seealso autocorrelation sequences,

cross-correlation sequences,

cross-covariance

Steiglitz-McBride method 4-16, 7-412

st mcb 2-6, 4-12, 4-16, 7-412stopband 7-54, 7-63, 7-68, 7-143

equiripple 2-11

strip plots 7-415

s t r i ps 7-415

pstructures, digital filters

lattice/ladder 1-38

transposed direct form I I 1-18

swept-frequency cosine generator. See chirp

system identification 4-14

system models. Seemodels

Ttapers, PSD estimates 3-24

taps 2-18

t f 2l at c 1-39, 1-43, 7-417

t f2ss 1-43, 7-422

t f2zp 1-43, 7-409, 7-424

t f e 3-9, 3-28, 7-427til ing preferences 6-50

time series attributes 4-40

time-domain based modeling. Seeparametric

modeling

toolboxes

Control Systems Toolbox 1-36, 7-219, 7-411

I mage Processing Toolbox 7-120, 7-211, 7-263

Signal Processing Toolbox 1-3

Symbolic Math Toolbox 7-26

System I dentification Toolbox 7-430

transfer functions 1-16, 1-33, 1-36, 1-43

coefficients 1-16, 6-38

estimation 7-427

using Welch’s method 3-28

factoring 1-34lattice forms, conversions to 7-417

second-order section forms, conversions from

7-387

Index

second-order section forms, conversions to

7-418

SPTool 6-44

uniform encoding 7-437

unit circle 7-319

unit impulse function 1-8

Page 869: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 869/870

I-23

state-space forms, conversions to 7-422

zero-pole-gain forms 1-34

transformations

bilinear 2-43, 7-31

discrete/continuous 2-44

frequency 2-39, 7-247, 7-250, 7-252, 7-254

models, between 1-43

transforms 4-35

chirp z-transforms (CZT) 4-35, 7-116

discrete cosine 7-119

discrete Fourier 1-45, 7-151

Hilbert 4-39, 7-207

inverse discrete cosine 4-37, 7-211

inverse discrete Fourier 7-213

transients, filters 1-23transition band 2-23

transposed direct form I I 7-159

initial conditions 7-163

t r i ang 4-3, 7-431

bart l et t , comparison to 7-24

example 4-3

triangular windows 7-431

t r i pul s 7-433

two-dimensional operations

discrete Fourier transforms 1-47, 7-154

inverse discrete Fourier transforms 1-47,

7-214

Seealso filters, two-dimensional

two-dimensional signal processing 1-47

Uudecode 7-434

uencode 7-437

punit ramp function 1-8

unit sample, multichannel representation 1-8

unit step function 1-8

units of power spectral density (PSD) 3-7

unwr ap 1-28, 7-440

upf i rdn 1-20, 4-22, 7-441

Vvari ance, correlation sequenceestimate 3-4

vco 4-30, 4-32, 7-445

vectors

data 1-5, 1-7

frequency 2-25, 7-169, 7-172, 7-349, 7-455

indexing 29, 1-16magnitude 2-25, 7-169, 7-172, 7-455

weighting 7-179

voltage controlled oscil lators 4-32, 7-445

Wwaveforms. Seesignals

Welch’s method 3-9, 3-20bias 3-23

Burg method, comparison to 3-35

MTM method, comparison to 3-26

normalization 3-23

power spectral density estimation 3-8, 3-23,

3-27, 7-91, 7-113, 7-332

system identification, nonparametric 3-28 Yule-Walker AR method, comparison to 3-33

white noise 1-7

windows

Bartlett 4-3, 7-24

Index

Blackman 4-5, 7-36

boxcar 2-19

Chebyshev 4-9, 7-73i li d 4 5

example 3-33, 3-34

Welch’s method, comparison to 3-33

Yule-Walker equations 2-14

Page 870: Dsp Toolbox

7/29/2019 Dsp Toolbox

http://slidepdf.com/reader/full/dsp-toolbox 870/870

I-24

cosine, generalized 4-5

filters 2-19

FI R filters 2-19

bandpass 7-165

bandstop 7-166

highpass 7-166

lowpass 7-165

multiband filters 2-22

single band design 2-21

f i r 1 2-22

generalized cosine 4-5

Hamming 2-20, 3-18, 4-5, 7-203

Hann 7-205

Hanning 4-5, 7-205

K aiser 3-20, 4-5, 7-234peri odograms 3-12, 3-18

prolate-spheroidal 4-5

rectangular 2-19, 7-38

shapes 4-3

triangular 7-431

Workspace Contents list 6-19

Xxcorr 3-3, 7-447

parametric modeling 4-13

xcorr2 7-451

xcov 3-3, 7-452

Yyul ewal k 2-6, 2-14, 7-455

example 2-14

Yule-Walker AR method 3-8, 3-9, 3-32, 7-455

Zzero frequency component, centering 1-47

zero-order hold. See averaging filters

zero-phase filtering 7-162

zero-pole analysis 7-466

zero-pole plots 1-31, 7-466

zero-pole-gain forms 1-34, 1-42, 1-43

example 1-31

second-order section forms, conversions from

7-389

second-order section forms, conversions to

7-458

SPTool 6-44state-space forms, conversions from 7-409

state-space forms, conversions to 7-462

zeros and poles

multiplicity of 6-35

transfer functions 1-34

zooming 6-50

zp2sos 1-43, 7-458

zp2ss 1-43, 7-462

zp2t f 1-43, 7-464

zpl ane 1-31, 7-466

z-transforms 1-16, 1-33

chirp z-transforms (CZT) 4-35, 7-116

discreteF ourier transforms 1-45, 7-151