100% found this document useful (1 vote)
229 views

Dsp System Toolbox Users Guide Mathworks pdf download

The DSP System Toolbox User's Guide provides comprehensive instructions and tutorials for utilizing the DSP System Toolbox in MATLAB, including signal processing techniques and filter design. It covers various topics such as lowpass filter design, multirate filtering, and signal visualization. The document also includes contact information for MathWorks and a revision history of the guide.

Uploaded by

mauckrollotu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
229 views

Dsp System Toolbox Users Guide Mathworks pdf download

The DSP System Toolbox User's Guide provides comprehensive instructions and tutorials for utilizing the DSP System Toolbox in MATLAB, including signal processing techniques and filter design. It covers various topics such as lowpass filter design, multirate filtering, and signal visualization. The document also includes contact information for MathWorks and a revision history of the guide.

Uploaded by

mauckrollotu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 91

Dsp System Toolbox Users Guide Mathworks

download

https://ebookbell.com/product/dsp-system-toolbox-users-guide-
mathworks-49478976

Explore and download more ebooks at ebookbell.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

Matlab Dsp System Toolbox Users Guide Coll

https://ebookbell.com/product/matlab-dsp-system-toolbox-users-guide-
coll-7035454

Matlab Dsp System Toolbox Reference Unknown

https://ebookbell.com/product/matlab-dsp-system-toolbox-reference-
unknown-49478978

Dsp System Design Complexity Reduced Iir Filter Implementation For


Practical Applications Artur Krukowski Izzet Kale

https://ebookbell.com/product/dsp-system-design-complexity-reduced-
iir-filter-implementation-for-practical-applications-artur-krukowski-
izzet-kale-4110350

Highspeed Dsp And Analog System Design Thanh T Tran

https://ebookbell.com/product/highspeed-dsp-and-analog-system-design-
thanh-t-tran-50903824
Highspeed Dsp And Analog System Design 1st Edition Thanh T Tran Auth

https://ebookbell.com/product/highspeed-dsp-and-analog-system-
design-1st-edition-thanh-t-tran-auth-2022442

Communication System Design Using Dsp Algorithms With Laboratory


Experiments For The Tms320c6701 And Tms320c6711 1st Edition Steven A
Tretter Auth

https://ebookbell.com/product/communication-system-design-using-dsp-
algorithms-with-laboratory-experiments-for-the-tms320c6701-and-
tms320c6711-1st-edition-steven-a-tretter-auth-4188870

Communication System Design Using Dsp Algorithms With Laboratory


Experiments For The Tms320c6713 Dsk Information Technology
Transmission Processing And Storage 1st Edition Steven A Tretter

https://ebookbell.com/product/communication-system-design-using-dsp-
algorithms-with-laboratory-experiments-for-the-tms320c6713-dsk-
information-technology-transmission-processing-and-storage-1st-
edition-steven-a-tretter-1293582

Managing Power Electronics Vlsi Dsp Driven Computer Systems

https://ebookbell.com/product/managing-power-electronics-vlsi-dsp-
driven-computer-systems-1279794

Managing Power Electronics Vlsl And Dspdriven Computer Systems N


Rossetti

https://ebookbell.com/product/managing-power-electronics-vlsl-and-
dspdriven-computer-systems-n-rossetti-4092230
DSP System Toolbox™
User's Guide

R2023a
How to Contact MathWorks

Latest news: www.mathworks.com

Sales and services: www.mathworks.com/sales_and_services

User community: www.mathworks.com/matlabcentral

Technical support: www.mathworks.com/support/contact_us

Phone: 508-647-7000

The MathWorks, Inc.


1 Apple Hill Drive
Natick, MA 01760-2098
DSP System Toolbox™ User's Guide
© COPYRIGHT 2011–2023 by The MathWorks, Inc.
The software described in this document is furnished under a license agreement. The software may be used or copied
only under the terms of the license agreement. No part of this manual may be photocopied or reproduced in any form
without prior written consent from The MathWorks, Inc.
FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation by, for, or through
the federal government of the United States. By accepting delivery of the Program or Documentation, the government
hereby agrees that this software or documentation qualifies as commercial computer software or commercial computer
software documentation as such terms are used or defined in FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014.
Accordingly, the terms and conditions of this Agreement and only those rights specified in this Agreement, shall pertain
to and govern the use, modification, reproduction, release, performance, display, and disclosure of the Program and
Documentation by the federal government (or other entity acquiring for or through the federal government) and shall
supersede any conflicting contractual terms or conditions. If this License fails to meet the government's needs or is
inconsistent in any respect with federal procurement law, the government agrees to return the Program and
Documentation, unused, to The MathWorks, Inc.
Trademarks
MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See
www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand names may be
trademarks or registered trademarks of their respective holders.
Patents
MathWorks products are protected by one or more U.S. patents. Please see www.mathworks.com/patents for
more information.
Revision History
April 2011 First printing Revised for Version 8.0 (R2011a)
September 2011 Online only Revised for Version 8.1 (R2011b)
March 2012 Online only Revised for Version 8.2 (R2012a)
September 2012 Online only Revised for Version 8.3 (R2012b)
March 2013 Online only Revised for Version 8.4 (R2013a)
September 2013 Online only Revised for Version 8.5 (R2013b)
March 2014 Online only Revised for Version 8.6 (R2014a)
October 2014 Online only Revised for Version 8.7 (R2014b)
March 2015 Online only Revised for Version 9.0 (R2015a)
September 2015 Online only Revised for Version 9.1 (R2015b)
March 2016 Online only Revised for Version 9.2 (R2016a)
September 2016 Online only Revised for Version 9.3 (R2016b)
March 2017 Online only Revised for Version 9.4 (R2017a)
September 2017 Online only Revised for Version 9.5 (R2017b)
March 2018 Online only Revised for Version 9.6 (R2018a)
September 2018 Online only Revised for Version 9.7 (R2018b)
March 2019 Online only Revised for Version 9.8 (R2019a)
September 2019 Online only Revised for Version 9.9 (R2019b)
March 2020 Online only Revised for Version 9.10 (R2020a)
September 2020 Online only Revised for Version 9.11 (R2020b)
March 2021 Online only Revised for Version 9.12 (R2021a)
September 2021 Online only Revised for Version 9.13 (R2021b)
March 2022 Online only Revised for Version 9.14 (R2022a)
September 2022 Online only Revised for Version 9.15 (R2022b)
March 2023 Online only Revised for Version 9.16 (R2023a)
Contents

DSP Tutorials
1
Introduction to Streaming Signal Processing in MATLAB . . . . . . . . . . . . . 1-2

Filter Frames of a Noisy Sine Wave Signal in MATLAB . . . . . . . . . . . . . . . 1-6

Filter Frames of a Noisy Sine Wave Signal in Simulink . . . . . . . . . . . . . . . 1-8


Open Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-8
Inspect Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-8
Compare Original and Filtered Signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9

Lowpass Filter Design in MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-11

Lowpass IIR Filter Design in Simulink . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-19


filterBuilder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-19
Butterworth Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-20
Chebyshev Type I Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-24
Chebyshev Type II Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-25
Elliptic Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-27
Minimum-Order Designs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-29
Lowpass Filter Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-32
Variable Bandwidth IIR Filter Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-33

Multirate Filtering in MATLAB and Simulink . . . . . . . . . . . . . . . . . . . . . . 1-35


Implement FIR Decimator in MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . 1-35
Implement an FIR Decimator in Simulink . . . . . . . . . . . . . . . . . . . . . . . . 1-38
Sample Rate Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-41

Tunable Lowpass Filtering of Noisy Input in Simulink . . . . . . . . . . . . . . 1-45

Signal Processing Algorithm Acceleration in MATLAB . . . . . . . . . . . . . . 1-51


FIR Filter Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-51
Accelerate the FIR Filter Using codegen . . . . . . . . . . . . . . . . . . . . . . . . . 1-52
Accelerate the FIR Filter Using dspunfold . . . . . . . . . . . . . . . . . . . . . . . . 1-53
Kalman Filter Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-54
Accelerate the Kalman Filter Using codegen . . . . . . . . . . . . . . . . . . . . . . 1-56
Accelerate the Kalman Filter Using dspunfold . . . . . . . . . . . . . . . . . . . . 1-57

Multithreaded MEX File Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-59

Fixed-Point Filter Design in MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-66

Visualizing Multiple Signals Using Logic Analyzer . . . . . . . . . . . . . . . . . 1-72


Model Programmable FIR Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-72
Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-72
Use the Logic Analyzer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-73

v
Modify the Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-74

Signal Visualization and Measurements in MATLAB . . . . . . . . . . . . . . . . 1-80

Input, Output, and Display


2
Discrete-Time Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Time and Frequency Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Recommended Settings for Discrete-Time Simulations . . . . . . . . . . . . . . . 2-3
Simulink Tasking Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4
Other Settings for Discrete-Time Simulations . . . . . . . . . . . . . . . . . . . . . . 2-5
Cross-Rate Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5

Continuous-Time Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8


Continuous-Time Source Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8
Continuous-Time Nonsource Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8

Create Signals for Sample-Based Processing . . . . . . . . . . . . . . . . . . . . . . . 2-9


Multichannel Signals for Sample-Based Processing . . . . . . . . . . . . . . . . . . 2-9
Create Signals Using Constant Block . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10
Create Signals Using Signal From Workspace Block . . . . . . . . . . . . . . . . 2-11
Combine Signals Using Matrix Concatenate Block . . . . . . . . . . . . . . . . . 2-12

Create Signals for Frame-Based Processing . . . . . . . . . . . . . . . . . . . . . . . 2-15


Multichannel Signals for Frame-Based Processing . . . . . . . . . . . . . . . . . 2-15
Create Signals Using Sine Wave Block . . . . . . . . . . . . . . . . . . . . . . . . . . 2-16
Create Signals Using Signal From Workspace Block . . . . . . . . . . . . . . . . 2-18
Combine Signals Using Matrix Concatenate Block . . . . . . . . . . . . . . . . . 2-19

Deconstruct Multichannel Signals for Sample-Based Processing . . . . . . 2-21


Split Multichannel Signals into Individual Signals . . . . . . . . . . . . . . . . . . 2-21
Split Multichannel Signals into Several Multichannel Signals . . . . . . . . . 2-23

Deconstruct Multichannel Signals for Frame-Based Processing . . . . . . 2-27


Split Multichannel Signals into Individual Signals . . . . . . . . . . . . . . . . . . 2-27
Reorder Channels in Multichannel Signals . . . . . . . . . . . . . . . . . . . . . . . 2-30

Import and Export Signals for Sample-Based Processing . . . . . . . . . . . . 2-34


Import Vector Signals for Sample-Based Processing . . . . . . . . . . . . . . . . 2-34
Import Matrix Signals for Sample-Based Processing . . . . . . . . . . . . . . . . 2-36
Export Signals for Sample-Based Processing . . . . . . . . . . . . . . . . . . . . . . 2-38

Import and Export Signals for Frame-Based Processing . . . . . . . . . . . . . 2-43


Import Signals for Frame-Based Processing . . . . . . . . . . . . . . . . . . . . . . 2-43
Export Signals for Frame-Based Processing . . . . . . . . . . . . . . . . . . . . . . 2-45

vi Contents
Data and Signal Management
3
Sample- and Frame-Based Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2
Sample Rate and Frame Rate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2
Generating Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3
Sample-Based Processing and Frame-Based Processing . . . . . . . . . . . . . . 3-4

Compare Speed Performance in Frame-Based Processing Mode Using


Simulink Profiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-7

Inspect Sample and Frame Rates in Simulink . . . . . . . . . . . . . . . . . . . . . 3-12


Inspect Signal Rates Using Color Coding . . . . . . . . . . . . . . . . . . . . . . . . 3-12
Use Model Data Editor or Probe to Inspect Signals . . . . . . . . . . . . . . . . . 3-19

Convert Sample and Frame Rates in Simulink Using Rate Conversion


Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-20
Rate Conversion Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-20
Rate Conversion by Frame-Rate Adjustment . . . . . . . . . . . . . . . . . . . . . . 3-21
Rate Conversion by Frame-Size Adjustment . . . . . . . . . . . . . . . . . . . . . . 3-24

Convert Sample and Frame Rates in Simulink Using Frame Rebuffering


Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-27
Frame Rebuffering Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-27
Buffer Signals by Preserving Sample Period . . . . . . . . . . . . . . . . . . . . . . 3-28
Buffer Signals by Altering the Sample Period . . . . . . . . . . . . . . . . . . . . . 3-30

Buffering and Frame-Based Processing . . . . . . . . . . . . . . . . . . . . . . . . . . 3-33


Buffer Input into Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-33
Buffer Signals into Frames with Overlap . . . . . . . . . . . . . . . . . . . . . . . . . 3-35
Buffer Frame Inputs into Other Frame Inputs . . . . . . . . . . . . . . . . . . . . . 3-37
Buffer Delay and Initial Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-38
Unbuffer Frame Signals into Sample Signals . . . . . . . . . . . . . . . . . . . . . 3-39

Delay and Latency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-43


Computational Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-43
Algorithmic Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-44
Zero Algorithmic Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-44
Basic Algorithmic Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-46
Excess Algorithmic Delay (Tasking Latency) . . . . . . . . . . . . . . . . . . . . . . 3-48
Predict Tasking Latency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-49

Variable-Size Signal Support DSP System Objects . . . . . . . . . . . . . . . . . . 3-54


Variable-Size Signal Support Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-54
DSP System Toolbox System Objects That Support Variable-Size Signals
..................................................... 3-54

DSP System Toolbox Featured Examples


4
Wavelet Denoising . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3

vii
LPC Analysis and Synthesis of Speech . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-7

Streaming Signal Statistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-12

High Resolution Spectral Analysis in MATLAB . . . . . . . . . . . . . . . . . . . . . 4-16

High Resolution Spectral Analysis in Simulink . . . . . . . . . . . . . . . . . . . . 4-32

Zoom FFT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-38

Outlier Removal Techniques with ECG Signals . . . . . . . . . . . . . . . . . . . . . 4-48

Sigma-Delta A/D Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-52

GSM Digital Down Converter in Simulink . . . . . . . . . . . . . . . . . . . . . . . . . 4-56

Overlap-Add/Save . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-62

Designing Lowpass FIR Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-67

Classic IIR Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-83

Efficient Narrow Transition-Band FIR Filter Design . . . . . . . . . . . . . . . . 4-91

Multistage Rate Conversion using FIR Rate Converter . . . . . . . . . . . . . . 4-98

IIR Filter Design Given a Prescribed Group Delay . . . . . . . . . . . . . . . . . 4-107

FIR Nyquist (L-th band) Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-116

FIR Halfband Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-123

Arbitrary Magnitude Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-142

Design of Peaking and Notching Filters . . . . . . . . . . . . . . . . . . . . . . . . . 4-155

Fractional Delay Filters Using Farrow Structures . . . . . . . . . . . . . . . . . 4-165

Least Pth-Norm Optimal FIR Filter Design . . . . . . . . . . . . . . . . . . . . . . . 4-173

Least Pth-Norm Optimal IIR Filter Design . . . . . . . . . . . . . . . . . . . . . . . 4-182

Multistage Rate Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-190

Complex Bandpass Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-204

Design of Fractional Delay FIR Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-210

Time Delay and Scaling in Multirate DSP Filters . . . . . . . . . . . . . . . . . . 4-225

Design of Decimators and Interpolators . . . . . . . . . . . . . . . . . . . . . . . . . 4-242

IIR Halfband Stages in Multistage Filter Design . . . . . . . . . . . . . . . . . . 4-260

viii Contents
Efficient Sample Rate Conversion Between Arbitrary Factors . . . . . . . 4-266

Reconstruction Through Two-Channel Filter Banks . . . . . . . . . . . . . . . 4-272

Adaptive Line Enhancer (ALE) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-279

Apply Adaptive Noise Canceling to Fetal Electrocardiography . . . . . . . 4-287

Adaptive Noise Cancellation Using RLS Adaptive Filtering . . . . . . . . . . 4-291

System Identification Using RLS Adaptive Filtering . . . . . . . . . . . . . . . 4-296

Acoustic Noise Cancellation (LMS) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-303

Adaptive Filter Convergence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-305

Noise Canceler (RLS) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-309

Time-Delay Channel Estimation Through Adaptive Filtering . . . . . . . . 4-312

Time Scope Measurements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-315

Spectrum Analyzer Measurements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-324

Generate a Multithreaded MEX File from a MATLAB Function Using


Unfolding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-332

Generate Standalone Executable and Interact with it Using UDP . . . . 4-341

Code Generation for Parametric Audio Equalizer . . . . . . . . . . . . . . . . . . 4-344

Generate DSP Applications with MATLAB Compiler . . . . . . . . . . . . . . . 4-353

Optimized Fixed-Point FIR Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-358

Floating-Point to Fixed-Point Conversion of IIR Filters . . . . . . . . . . . . . 4-366

GSM Digital Down Converter in MATLAB . . . . . . . . . . . . . . . . . . . . . . . . 4-384

Cochlear Implant Speech Processor . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-393

Three-Channel Wavelet Transmultiplexer . . . . . . . . . . . . . . . . . . . . . . . . 4-398

Arbitrary Magnitude and Phase Filter Design . . . . . . . . . . . . . . . . . . . . 4-405

G.729 Voice Activity Detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-422

IF Subsampling with Complex Multirate Filters . . . . . . . . . . . . . . . . . . . 4-426

Design and Analysis of a Digital Down Converter . . . . . . . . . . . . . . . . . 4-436

Comparison of LDM, CVSD, and ADPCM . . . . . . . . . . . . . . . . . . . . . . . . . 4-445

ix
Digital Up and Down Conversion for Family Radio Service in MATLAB
........................................................ 4-451

Digital Up and Down Conversion for Family Radio Service in Simulink


........................................................ 4-463

Parametric Audio Equalizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-466

Envelope Detection in MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-470

Envelope Detection in Simulink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-475

DTMF Generator and Receiver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-478

WWV Digital Receiver - Synchronization and Detection . . . . . . . . . . . . 4-481

Real-Time ECG QRS Detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-488

Internet Low Bitrate Codec (iLBC) for VoIP . . . . . . . . . . . . . . . . . . . . . . 4-494

Filter Analysis, Design, and Implementation


5
Design a Filter in Fdesign — Process Overview . . . . . . . . . . . . . . . . . . . . . 5-2
Process Flow Diagram and Filter Design Methodology . . . . . . . . . . . . . . . 5-2

Use Filter Designer with DSP System Toolbox Software . . . . . . . . . . . . . . 5-9


Design Advanced Filters in Filter Designer . . . . . . . . . . . . . . . . . . . . . . . . 5-9
Access the Quantization Features of Filter Designer . . . . . . . . . . . . . . . . 5-11
Quantize Filters in Filter Designer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-13
Analyze Filters with a Noise-Based Method . . . . . . . . . . . . . . . . . . . . . . . 5-18
Scale Second-Order Section Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-22
Reorder the Sections of Second-Order Section Filters . . . . . . . . . . . . . . . 5-25
View SOS Filter Sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-28
Import and Export Quantized Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-32
Generate MATLAB Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-35
Import XILINX Coefficient (.COE) Files . . . . . . . . . . . . . . . . . . . . . . . . . . 5-36
Transform Filters Using Filter Designer . . . . . . . . . . . . . . . . . . . . . . . . . 5-36
Design Multirate Filters in Filter Designer . . . . . . . . . . . . . . . . . . . . . . . 5-42
Realize Filters as Simulink Subsystem Blocks . . . . . . . . . . . . . . . . . . . . . 5-50

Digital Frequency Transformations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-53


Details and Methodology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-53
Frequency Transformations for Real Filters . . . . . . . . . . . . . . . . . . . . . . 5-58
Frequency Transformations for Complex Filters . . . . . . . . . . . . . . . . . . . 5-67

Using Digital Filter Design Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-76


Overview of the Digital Filter Design Block . . . . . . . . . . . . . . . . . . . . . . . 5-76
Select a Filter Design Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-77
Create a Lowpass Filter in Simulink . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-78
Create a Highpass Filter in Simulink . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-78
Filter High-Frequency Noise in Simulink . . . . . . . . . . . . . . . . . . . . . . . . 5-79

x Contents
Using Filter Realization Wizard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-84
Overview of the Filter Realization Wizard . . . . . . . . . . . . . . . . . . . . . . . . 5-84
Design and Implement a Fixed-Point Filter in Simulink . . . . . . . . . . . . . . 5-84
Set the Filter Structure and Number of Filter Sections . . . . . . . . . . . . . . 5-91
Optimize the Filter Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-91

Digital Filter Implementations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-94


Using Digital Filter Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-94
Implement a Lowpass Filter in Simulink . . . . . . . . . . . . . . . . . . . . . . . . . 5-94
Implement a Highpass Filter in Simulink . . . . . . . . . . . . . . . . . . . . . . . . 5-95
Filter High-Frequency Noise in Simulink . . . . . . . . . . . . . . . . . . . . . . . . 5-96
Specify Static Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-99
Specify Time-Varying Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-100
Specify the SOS Matrix (Biquadratic Filter Coefficients) . . . . . . . . . . . . 5-100

Removing High-Frequency Noise from an ECG Signal . . . . . . . . . . . . . . 5-102

Minimax FIR Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-105

Adaptive Filters
6
Overview of Adaptive Filters and Applications . . . . . . . . . . . . . . . . . . . . . . 6-2
Adaptive Filters in DSP System Toolbox . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2
Choosing an Adaptive Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4
Mean Squared Error Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-5
Common Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-5

System Identification of FIR Filter Using LMS Algorithm . . . . . . . . . . . . . 6-9

System Identification of FIR Filter Using Normalized LMS Algorithm . . 6-16

Compare Convergence Performance Between LMS Algorithm and


Normalized LMS Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-19

Noise Cancellation Using Sign-Data LMS Algorithm . . . . . . . . . . . . . . . . 6-21

Compare RLS and LMS Adaptive Filter Algorithms . . . . . . . . . . . . . . . . . 6-25

Inverse System Identification Using RLS Algorithm . . . . . . . . . . . . . . . . 6-28

Signal Enhancement Using LMS and NLMS Algorithms . . . . . . . . . . . . . 6-33

Noise Cancellation in Simulink Using Normalized LMS Adaptive Filter


......................................................... 6-42
Create an Acoustic Environment in Simulink . . . . . . . . . . . . . . . . . . . . . . 6-42
LMS Filter Configuration for Adaptive Noise Cancellation . . . . . . . . . . . 6-43
Modify Adaptive Filter Parameters During Model Simulation . . . . . . . . . 6-47

xi
Multirate and Multistage Filters
7
Overview of Multirate Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2
Decimation and Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2
Decimators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-3
Interpolators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-4
Sample Rate Converters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-6

Overview of Multistage Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-11


Multistage Decimator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-11
Multistage Interpolator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-12
Determine the number of stages and rate conversion factor for each stage
..................................................... 7-12

Overview of Filter Banks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-14


Analysis Filter Bank (Channelizer) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-14
Synthesis Filter Bank (Channel synthesizer) . . . . . . . . . . . . . . . . . . . . . . 7-15
Two-Channel (Halfband) Filter Bank . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-16

Two-Channel Filter Bank Using Halfband Decimators and Halfband


Interpolators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-19

Channelize and Synthesize Sine Wave in MATLAB . . . . . . . . . . . . . . . . . . 7-26

Multilevel Filter Banks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-28


Dyadic Analysis Filter Banks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-28
Dyadic Synthesis Filter Banks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-30

Dataflow
8
Dataflow Domain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2
Specifying Dataflow Domains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2
Simulation of Dataflow Domains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2
Dataflow Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-3
Unsupported Simulink Software Features in Dataflow Domains . . . . . . . . 8-6

Model Multirate Signal Processing Systems Using Dataflow . . . . . . . . . . . 8-8

Multicore Simulation and Code Generation of Dataflow Domains . . . . . 8-10


Simulation of Dataflow Domains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-10
Code Generation of Dataflow Domains . . . . . . . . . . . . . . . . . . . . . . . . . . 8-10
Types of Parallelism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-10
Improve Simulation Throughput with Multicore Simulation . . . . . . . . . . 8-12
Generate Multicore Code from a Dataflow Subsystem . . . . . . . . . . . . . . . 8-12

Multicore Execution using Dataflow Domain . . . . . . . . . . . . . . . . . . . . . . 8-15

Multicore Code Generation for Dataflow Domain . . . . . . . . . . . . . . . . . . . 8-20

xii Contents
Multicore Execution of Interpolated FIR Filter using Dataflow domain
......................................................... 8-27

Perform Multicore Analysis for Dataflow . . . . . . . . . . . . . . . . . . . . . . . . . . 8-33


Select the Cost Calculation Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-34
Manually Change Block Costs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-37
Specify Analysis Constraints and Run Analysis . . . . . . . . . . . . . . . . . . . . 8-37
Review Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-37

Multicore Analysis Using a Dataflow Domain . . . . . . . . . . . . . . . . . . . . . . 8-43

Simulink Block Examples in Multirate and Multistage Filters


9
FIR Decimation Using Single-Rate Processing . . . . . . . . . . . . . . . . . . . . . . 9-2

FIR Decimation Using Multirate Frame-Based Processing . . . . . . . . . . . . 9-3

Polyphase Implementation of FIR Decimation Block . . . . . . . . . . . . . . . . . 9-4

Two-Stage Multirate Narrow Lowpass Filter . . . . . . . . . . . . . . . . . . . . . . . . 9-6

FIR Interpolation Using Single-Rate Processing . . . . . . . . . . . . . . . . . . . . 9-8

FIR Interpolation Using Multirate Frame-Based Processing . . . . . . . . . . . 9-9

Polyphase Implementation of FIR Interpolation Block . . . . . . . . . . . . . . 9-10

Simulink Block Examples in Scopes and Data Logging


Category
10
Obtain Measurements Data Programmatically for spectrumAnalyzer
object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-2

Obtain Measurements Data Programmatically for Spectrum Analyzer


Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-5

DSP System Toolbox Simulink block Examples in Signal Input


and Output Category
11
Write and Read Binary Files in Simulink . . . . . . . . . . . . . . . . . . . . . . . . . 11-2

Write and Read Matrix Data from Binary Files in Simulink . . . . . . . . . . 11-6

xiii
Write and Read Fixed-Point Data from Binary Files in Simulink . . . . . . 11-8

Write and Read Character Data from Binary Files in Simulink . . . . . . . 11-10

Change the Endianness of the Data in Simulink . . . . . . . . . . . . . . . . . . 11-12

Data Transmission Using UDP in Simulink . . . . . . . . . . . . . . . . . . . . . . . 11-14

Byte Transmission Using UDP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-17

Transmit Complex Data over UDP Network . . . . . . . . . . . . . . . . . . . . . . . 11-18

Write and Read Binary Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-22

Write and Read Matrix Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-27

Write and Read Fixed-Point Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-29

Write and Read Character Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-31

Simulink Block Examples in Signal Generation and


Operations Category
12
Delay Signal Using Multitap Fractional Delay . . . . . . . . . . . . . . . . . . . . . 12-3

Bidirectional Linear Sweep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-8

Unidirectional Linear Sweep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-11

When Sweep Time Is Greater than Target Time . . . . . . . . . . . . . . . . . . . 12-13

Sweep with Negative Frequencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-16

Aliased Sweep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-19

Generate Discrete Impulse with Three Channels . . . . . . . . . . . . . . . . . . 12-22

Generate Five-Phase Output from the Multiphase Clock Block . . . . . . 12-23

Count Down Through Range of Numbers . . . . . . . . . . . . . . . . . . . . . . . . 12-25

Import Two-Channel Signal From Workspace . . . . . . . . . . . . . . . . . . . . . 12-27

Import 3-D Array From Workspace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-29

Generate Sample-Based Sine Waves . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-31

Generate Frame-Based Sine Waves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-32

Design an NCO Source Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-33

xiv Contents
Generate Constant Ramp Signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-37

Averaged Power Spectrum of Pink Noise . . . . . . . . . . . . . . . . . . . . . . . . . 12-38

Sample and Hold a Signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-40

Generate and Apply Hamming Window . . . . . . . . . . . . . . . . . . . . . . . . . . 12-43

Convert Sample Rate of Speech Signal . . . . . . . . . . . . . . . . . . . . . . . . . . 12-46

Unwrap Signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-49

Convolution of Two Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-51

Select Rows or Columns from Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . 12-53

Convert 2-D Matrix to 1-D Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-54

Pad or Truncate Matrix with Constant Values . . . . . . . . . . . . . . . . . . . . . 12-55

Extract the Phase of Sine Wave . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-57

Queues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-59

Use DC Blocker to Remove DC Component of Signal . . . . . . . . . . . . . . . 12-61

DC Blocker with Fixed Point Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-66

Truncate Data Vector Using Offset Block . . . . . . . . . . . . . . . . . . . . . . . . 12-72

Repeat Signal In Single-Rate Frame-Based Processing Mode . . . . . . . 12-74

Repeat Signal In Multirate Frame-Based Processing Mode . . . . . . . . . 12-75

Sample Rate Conversion of Audio Signal . . . . . . . . . . . . . . . . . . . . . . . . 12-76

Detect Number of Zero Crossings in Signal . . . . . . . . . . . . . . . . . . . . . . 12-77

Upsample Signal In Single-Rate Frame-Based Processing Mode . . . . . 12-78

Upsample Signal In Multirate Frame-Based Processing Mode . . . . . . . 12-79

Find Peak Values in a Signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-80

Effect of Overflow Mode on Peak Finder Output . . . . . . . . . . . . . . . . . . . 12-81

Simulink Block Examples in DSP System Toolbox


13
Why Does Reading Data from the dsp.AsyncBuffer Object Give a
Dimension Mismatch Error in MATLAB Function Block? . . . . . . . . . . 13-2

xv
Why Does the dsp.AsyncBuffer Object Error When You Call read Before
write? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-9

Buffering Input with Overlap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-11

Detect Threshold Crossings Using Event Count Comparator Block . . . 13-14

Simulink Block Examples in Deep Learning Domain in DSP


System Toolbox
14
Detect Air Compressor Sounds in Simulink Using Wavelet Scattering
......................................................... 14-2

Simulink Block Examples in DSP System Toolbox


15
Synthesize and Channelize Audio in Simulink . . . . . . . . . . . . . . . . . . . . . 15-2

Filter input with Butterworth Filter in Simulink . . . . . . . . . . . . . . . . . . 15-13

SSB Modulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-14

Wavelet Reconstruction and Noise Reduction . . . . . . . . . . . . . . . . . . . . 15-17

Filter Noisy Signal Using Fourth-Order Section (FOS) Filter in Simulink


........................................................ 15-19

Adapt Multiple Filters Using LMS Update block . . . . . . . . . . . . . . . . . . 15-23

Model Adaptive Linear Combiner using LMS Update Block . . . . . . . . . 15-30

Simulink Block Examples in DSP System Toolbox


16
Compute the Maximum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-2

Compute the Running Maximum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-4

Compute the Minimum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-6

Compute the Running Minimum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-8

Compute the Standard Deviation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-10

xvi Contents
Compute the Running Standard Deviation . . . . . . . . . . . . . . . . . . . . . . . 16-12

Compute the Variance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-14

Compute the Mean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-15

Compute the Running Mean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-17

Compute the Histogram of Real and Complex Data . . . . . . . . . . . . . . . . 16-19

Compute Difference of a Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-24

Compute Maximum Column Sum of Matrix . . . . . . . . . . . . . . . . . . . . . . 16-25

LDL Factorization of 3-by-3 Hermitian Positive Definite Matrix . . . . . . 16-26

Compute Power Measurements of Voltage Signal in Simulink . . . . . . . 16-28

Compute CCDF Measurements of Voltage Signal in Simulink . . . . . . . 16-31

Compute Matrix Exponential . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-33

Compute Moving RMS of Noisy Step Signal . . . . . . . . . . . . . . . . . . . . . . 16-34

Compute RMS of Noisy Step Signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-37

Solve Matrix Equation Using Backward Substitution . . . . . . . . . . . . . . 16-39

Solve Matrix Equation Using Forward Substitution . . . . . . . . . . . . . . . . 16-41

Find Inverse of Matrix Using the LU Inverse Block . . . . . . . . . . . . . . . . 16-43

Solve Matrix Equation Using LU Solver . . . . . . . . . . . . . . . . . . . . . . . . . . 16-44

Solve Matrix Equation Using Singular Value Decomposition . . . . . . . . 16-45

Solve Matrix Equation Using Cholesky Solver . . . . . . . . . . . . . . . . . . . . 16-46

Factorize Matrix Using LU Factorization Block . . . . . . . . . . . . . . . . . . . 16-47

Compute Moving Average of Noisy Step Signal . . . . . . . . . . . . . . . . . . . 16-49

Compute Moving Standard Deviation of Noisy Square Wave Signal . . . 16-52

Compute Moving Variance of Noisy Square Wave Signal . . . . . . . . . . . . 16-55

Factor Arbitrary Matrix Using QR Factorization Block . . . . . . . . . . . . . 16-58

Compute Polynomial Coefficients Using Least Squares Polynomial Fit


Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-60

Extract Upper and Lower Triangles from Matrix . . . . . . . . . . . . . . . . . . 16-61

xvii
Simulink Block Examples in Transforms and Spectral Analysis
Category
17
Analyze a Subband of Input Frequencies Using Zoom FFT . . . . . . . . . . . 17-2

Group Delay Estimation in Simulink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-4

High Resolution Filter-Bank-Based Power Spectrum Estimation . . . . . . 17-7

Estimate Data Series Using Forward Linear Predictor . . . . . . . . . . . . . . 17-11

Continuous-Time Transfer Function Estimation . . . . . . . . . . . . . . . . . . . 17-13

Speech Enhancement with Gain in Frequency Domain . . . . . . . . . . . . . 17-15

Compute Periodogram of Signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-16

Compute Mean Using Sliding Window . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-18

Estimate Power Spectral Density of Chirp . . . . . . . . . . . . . . . . . . . . . . . 17-19

Transforms, Estimation, and Spectral Analysis


18
Transform Time-Domain Data into Frequency Domain . . . . . . . . . . . . . . 18-2

Transform Frequency-Domain Data into Time Domain . . . . . . . . . . . . . . 18-5

Linear and Bit-Reversed Output Order . . . . . . . . . . . . . . . . . . . . . . . . . . . 18-7


FFT and IFFT Blocks Data Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18-7
Find the Bit-Reversed Order of Your Frequency Indices . . . . . . . . . . . . . 18-7

Calculate Channel Latencies Required for Wavelet Reconstruction . . . . 18-9


Analyze Your Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18-9
Calculate the Group Delay of Your Filters . . . . . . . . . . . . . . . . . . . . . . . 18-10
Reconstruct the Filter Bank System . . . . . . . . . . . . . . . . . . . . . . . . . . . 18-11
Equalize the Delay on Each Filter Path . . . . . . . . . . . . . . . . . . . . . . . . . 18-12
Update and Run the Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18-13
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18-14

Estimate the Power Spectrum in MATLAB . . . . . . . . . . . . . . . . . . . . . . . 18-15


Estimate the Power Spectrum Using spectrumAnalyzer . . . . . . . . . . . . 18-15
Convert the Power Between Units . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18-23
Estimate the Power Spectrum Using dsp.SpectrumEstimator . . . . . . . . 18-25

Estimate the Power Spectrum in Simulink . . . . . . . . . . . . . . . . . . . . . . . 18-29


Estimate the Power Spectrum Using the Spectrum Analyzer . . . . . . . . . 18-29
Estimate Power Spectrum Using the Spectrum Estimator Block . . . . . . 18-36

xviii Contents
Estimate the Transfer Function of an Unknown System . . . . . . . . . . . . 18-40
Estimate the Transfer Function in MATLAB . . . . . . . . . . . . . . . . . . . . . 18-40
Estimate the Transfer Function in Simulink . . . . . . . . . . . . . . . . . . . . . 18-44

View the Spectrogram Using Spectrum Analyzer . . . . . . . . . . . . . . . . . . 18-48

Spectral Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18-53


Filter Bank . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18-53
Welch’s Algorithm of Averaging Modified Periodograms . . . . . . . . . . . . 18-53

Streaming Power Spectrum Estimation Using Welch's Method . . . . . . 18-55

Fixed-Point Design
19
Fixed-Point Signal Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-2
Fixed-Point Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-2
Benefits of Fixed-Point Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-2
Benefits of Fixed-Point Design with System Toolboxes Software . . . . . . . 19-2

Fixed-Point Concepts and Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-4


Fixed-Point Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-4
Scaling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-5
Precision and Range . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-6

Arithmetic Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-8


Modulo Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-8
Two's Complement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-8
Addition and Subtraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-9
Multiplication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-10
Casts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-12

System Objects in DSP System Toolbox that Support Fixed-Point Design


........................................................ 19-15
Get Information About Fixed-Point System Objects . . . . . . . . . . . . . . . . 19-15
Set System Object Fixed-Point Properties . . . . . . . . . . . . . . . . . . . . . . . 19-17
Full Precision for Fixed-Point System Objects . . . . . . . . . . . . . . . . . . . . 19-18

Simulink Blocks in DSP System Toolbox that Support Fixed-Point Design


........................................................ 19-19

System Objects Supported by Fixed-Point Converter App . . . . . . . . . . . 19-20

Convert dsp.FIRFilter Object to Fixed-Point Using the Fixed-Point


Converter App . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-21
Create DSP Filter Function and Test Bench . . . . . . . . . . . . . . . . . . . . . 19-21
Convert the Function to Fixed-Point . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-22

Specify Fixed-Point Attributes for Blocks . . . . . . . . . . . . . . . . . . . . . . . . 19-28


Fixed-Point Block Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-28
Specify System-Level Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-30
Inherit via Internal Rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-30

xix
Specify Data Types for Fixed-Point Blocks . . . . . . . . . . . . . . . . . . . . . . . 19-38

Quantizers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-44
Scalar Quantizers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-44
Vector Quantizers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-47

Create an FIR Filter Using Integer Coefficients . . . . . . . . . . . . . . . . . . . 19-52


Define the Filter Coefficients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-52
Build the FIR Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-52
Set the Filter Parameters to Work with Integers . . . . . . . . . . . . . . . . . . 19-53
Create a Test Signal for the Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-54
Filter the Test Signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-54
Truncate the Output WordLength . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-56
Scale the Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-58
Configure Filter Parameters to Work with Integers Using the set2int Method
.................................................... 19-61

Fixed-Point Precision Rules for Avoiding Overflow in FIR Filters . . . . . 19-64


Output Limits for FIR Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-64
Fixed-Point Precision Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-66
Polyphase Interpolators and Decimators . . . . . . . . . . . . . . . . . . . . . . . . 19-67

Encode Data Using Uniform Encoder . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-69

Decode Integer Data Using Uniform Decoder Block . . . . . . . . . . . . . . . 19-71

C Code Generation
20
Functions and System Objects in DSP System Toolbox that Support C
Code Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-2

Simulink Blocks in DSP System Toolbox that Support C Code Generation


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

Understanding C Code Generation in DSP System Toolbox . . . . . . . . . . . 20-6


Generate C and C++ code from MATLAB code . . . . . . . . . . . . . . . . . . . . 20-6
Generate C and C++ Code from a Simulink Model . . . . . . . . . . . . . . . . . 20-6
Shared Library Dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-7
Generate C Code for ARM Cortex-M and ARM Cortex-A Processors . . . . 20-8
Generate Code for Mobile Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-8

Generate C Code from MATLAB Code . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-10


Set Up the Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-10
Break Out the Computational Part of the Algorithm into a MATLAB Function
.................................................... 20-10
Make Code Suitable for Code Generation . . . . . . . . . . . . . . . . . . . . . . . 20-11
Compare the MEX Function with the Simulation . . . . . . . . . . . . . . . . . . 20-13
Generate a Standalone Executable . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-13
Read and Verify the Binary File Data . . . . . . . . . . . . . . . . . . . . . . . . . . 20-15
Relocate Code to Another Development Environment . . . . . . . . . . . . . . 20-16

xx Contents
Relocate Code Generated from MATLAB Code to Another Development
Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-17
Package the Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-17
Prebuilt Dynamic Library Files (.dll) . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-17

Generate C Code from Simulink Model . . . . . . . . . . . . . . . . . . . . . . . . . . 20-19


Open the Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-19
Configure Model for Code Generation . . . . . . . . . . . . . . . . . . . . . . . . . . 20-19
Simulate the Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-20
Generate Code from the Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-21
Build and Run the Generated Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-22

Relocate Code Generated from a Simulink Model to Another Development


Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-24
Package the Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-24
Prebuilt Dynamic Library Files (.dll) . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-26

How To Run a Generated Executable Outside MATLAB . . . . . . . . . . . . . 20-27

Use Generated Code to Accelerate an Application Deployed with MATLAB


Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-30

How Is dspunfold Different from parfor? . . . . . . . . . . . . . . . . . . . . . . . . 20-41


DSP Algorithms Involve States . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-41
dspunfold Introduces Latency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-41
parfor Requires Significant Restructuring in Code . . . . . . . . . . . . . . . . 20-41
parfor Used with dspunfold . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-41

Workflow for Generating a Multithreaded MEX File using dspunfold . 20-43


Workflow Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-43

Why Does the Analyzer Choose the Wrong State Length? . . . . . . . . . . . 20-47
Reason for Verification Failure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-48
Recommendation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-48

Why Does the Analyzer Choose a Zero State Length? . . . . . . . . . . . . . . 20-49


Recommendation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-49

Array Plot with Android Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-50

System objects in DSP System Toolbox that Support SIMD Code


Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-55

Generate High Performance SIMD Code on Intel from MATLAB


Algorithms in DSP System Toolbox . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-57

Simulink Blocks in DSP System Toolbox that Support SIMD Code


Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-59

Generate High Performance SIMD Code on Intel from Simulink Blocks in


DSP System Toolbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-64
Compare the Performance of SIMD Code with Generated Plain C Code
.................................................... 20-65

In-Place Memory Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-67

xxi
HDL Code Generation
21
Find Blocks That Support HDL Code Generation . . . . . . . . . . . . . . . . . . . 21-2
Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-2
System Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-3

HDL Filter Architectures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-4


Fully Parallel Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-4
Serial Architectures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-5
Frame-Based Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-6

Subsystem Optimizations for Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-9


Sharing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-9
Streaming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-9
Pipelining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-9
Area Reduction of Multichannel Filter Subsystem . . . . . . . . . . . . . . . . . 21-10
Area Reduction of Filter Subsystem . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-15

Multichannel FIR Filter for FPGA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-19

Programmable FIR Filter for FPGA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-22

Implement Digital Downconverter for FPGA . . . . . . . . . . . . . . . . . . . . . . 21-27

Implement Digital Upconverter for FPGA . . . . . . . . . . . . . . . . . . . . . . . . 21-45

Links to Category Pages


22
Signal Management Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-2

Sinks Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-3

Math Functions Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-4

Filtering Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-5

Designing Lowpass FIR Filters


23
Lowpass FIR Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23-2

Controlling Design Specifications in Lowpass FIR Design . . . . . . . . . . . . 23-7

Designing Filters with Non-Equiripple Stopband . . . . . . . . . . . . . . . . . . 23-12

Minimizing Lowpass FIR Filter Length . . . . . . . . . . . . . . . . . . . . . . . . . . 23-16

xxii Contents
Filter Designer: A Filter Design and Analysis App
24
Using Filter Designer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24-2
Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24-2
Choosing a Response Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24-4
Choosing a Filter Design Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24-5
Setting the Filter Design Specifications . . . . . . . . . . . . . . . . . . . . . . . . . 24-5
Computing the Filter Coefficients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24-8
Analyzing the Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24-8
Editing the Filter Using the Pole/Zero Editor . . . . . . . . . . . . . . . . . . . . 24-12
Converting the Filter Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24-15
Exporting a Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24-17
Generating a C Header File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24-20
Generating MATLAB Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24-21
Managing Filters in the Current Session . . . . . . . . . . . . . . . . . . . . . . . . 24-22
Saving and Opening Filter Design Sessions . . . . . . . . . . . . . . . . . . . . . 24-23

Importing a Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24-25


Import Filter Panel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24-25
Filter Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24-25

Designing a Filter in the Filter Builder GUI


25
Filter Builder Design Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-2
Introduction to Filter Builder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-2
Design a Filter Using Filter Builder . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-2
Select a Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-2
Select a Specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-4
Select an Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-5
Customize the Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-6
Analyze the Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-7
Realize or Apply the Filter to Input Data . . . . . . . . . . . . . . . . . . . . . . . . . 25-7

Visualize Data and Signals


26
Display Time-Domain Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-2
Open the Time Scope Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-2
Configure the Time Scope Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-3
Use the Simulation Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-6
Modify the Time Scope Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-7
Inspect Your Data (Scaling the Axes and Zooming) . . . . . . . . . . . . . . . . . 26-8
Manage Multiple Time Scopes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-10
Display Complex-Valued Input Signal . . . . . . . . . . . . . . . . . . . . . . . . . . 26-12
Display Input Signal of Changing Size . . . . . . . . . . . . . . . . . . . . . . . . . 26-12
Display Simulink Enumeration Input Signal . . . . . . . . . . . . . . . . . . . . . 26-12

xxiii
Display Frequency-Domain Data in Spectrum Analyzer . . . . . . . . . . . . . 26-18

Visualize Central Limit Theorem in Array Plot . . . . . . . . . . . . . . . . . . . . 26-21

Configure Spectrum Analyzer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-24


Signal Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-24
Analyzer Tab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-29
Estimation Tab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-30
Measurements Tab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-30
Spectrum Tab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-31
Spectrogram Tab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-31
Spectral Mask Tab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-31
Channel Measurements Tab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-32

Configure Array Plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-33


Signal Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-33
Multiple Signal Names and Colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-35
Configure Plot Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-35
Use Array Plot Measurements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-36
Share or Save the Array Plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-38
Scale Axes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-39
Set Additional Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-39
Find the Array Plot Block in Your Model . . . . . . . . . . . . . . . . . . . . . . . . 26-39

Configure Filter Visualizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-40


Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-40
Multiple Filter Names and Colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-42
Configure Plot Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-43
Use Filter Visualizer Measurements . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-43
Share or Save the Filter Visualizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-46
Scale Axes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-46
Set Additional Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-46

Configure Time Scope Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-47


Signal Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-47
Display Multiple Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-49
Time Scope Measurement Panels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-51
Style Dialog Box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-75
Axes Scaling Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-75
Sources — Streaming Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-76

Configure Time Scope MATLAB Object . . . . . . . . . . . . . . . . . . . . . . . . . . 26-77


Signal Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-77
Multiple Signal Names and Colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-78
Configure Scope Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-79
Use timescope Measurements and Triggers . . . . . . . . . . . . . . . . . . . . . 26-79
Share or Save the Time Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-96
Scale Axes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-97

Common Scope Block Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-98


Connect Multiple Signals to a Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-98
Save Simulation Data Using Scope Block . . . . . . . . . . . . . . . . . . . . . . 26-100
Pause Display While Running . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-102
Copy Scope Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-102
Plot an Array of Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-104

xxiv Contents
Scopes in Referenced Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-105
Scopes Within an Enabled Subsystem . . . . . . . . . . . . . . . . . . . . . . . . . 26-109
Modify x-axis of Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-110
Show Signal Units on a Scope Display . . . . . . . . . . . . . . . . . . . . . . . . 26-113
Select Number of Displays and Layout . . . . . . . . . . . . . . . . . . . . . . . . 26-115
Dock and Undock Scope Window to MATLAB Desktop . . . . . . . . . . . . 26-116

Display Frequency Input on Spectrum Analyzer . . . . . . . . . . . . . . . . . . 26-117

Use Peak Finder to Find Heart Rate from ECG Input . . . . . . . . . . . . . 26-119

Configure Array Plot From the Command-Line . . . . . . . . . . . . . . . . . . . 26-123

Waterfall Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-125


Scope Trigger Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-125
Scope Transform Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-127
Exporting Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-127
Capturing Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-127
Linking Scopes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-128
Selecting Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-129
Zooming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-130
Rotating the Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-130
Scaling the Axes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-130
Saving Scope Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-130

Logic Analyzer
27
Inspect and Measure Transitions Using the Logic Analyzer . . . . . . . . . . 27-2
Open a Simulink Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27-2
Open the Logic Analyzer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27-2
Configure Global Settings and Visual Layout . . . . . . . . . . . . . . . . . . . . . . 27-3
Set Stepping Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27-4
Run Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27-5
Configure Individual Wave Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27-5
Inspect and Measure Transitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27-5
Step Through Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27-7
Save Logic Analyzer Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27-7

Configure Logic Analyzer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27-8

Statistics and Linear Algebra


28
What Are Moving Statistics? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28-2

Sliding Window Method and Exponential Weighting Method . . . . . . . . . 28-5


Sliding Window Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28-5
Exponential Weighting Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28-7

xxv
Measure Statistics of Streaming Signals . . . . . . . . . . . . . . . . . . . . . . . . . 28-14
Compute Moving Average Using Only MATLAB Functions . . . . . . . . . . 28-14
Compute Moving Average Using System Objects . . . . . . . . . . . . . . . . . 28-15

How Is a Moving Average Filter Different from an FIR Filter? . . . . . . . 28-17


Frequency Response of Moving Average Filter and FIR Filter . . . . . . . . 28-17

Energy Detection in the Time Domain . . . . . . . . . . . . . . . . . . . . . . . . . . . 28-21


Detect Signal Energy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28-21

Remove High-Frequency Noise from Gyroscope Data . . . . . . . . . . . . . . 28-24

Linear Algebra and Least Squares . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28-26


Linear Algebra Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28-26
Linear System Solvers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28-26
Matrix Factorizations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28-27
Matrix Inverses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28-29

Bibliography
29
References — Advanced Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29-2

References — Frequency Transformations . . . . . . . . . . . . . . . . . . . . . . . . 29-3

Audio I/O User Guide


30
Run Audio I/O Features Outside MATLAB and Simulink . . . . . . . . . . . . . 30-2

Block Example Repository


31
Decrease Underrun . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31-2

xxvi Contents
1

DSP Tutorials

• “Introduction to Streaming Signal Processing in MATLAB” on page 1-2


• “Filter Frames of a Noisy Sine Wave Signal in MATLAB” on page 1-6
• “Filter Frames of a Noisy Sine Wave Signal in Simulink” on page 1-8
• “Lowpass Filter Design in MATLAB” on page 1-11
• “Lowpass IIR Filter Design in Simulink” on page 1-19
• “Multirate Filtering in MATLAB and Simulink” on page 1-35
• “Tunable Lowpass Filtering of Noisy Input in Simulink” on page 1-45
• “Signal Processing Algorithm Acceleration in MATLAB” on page 1-51
• “Multithreaded MEX File Generation” on page 1-59
• “Fixed-Point Filter Design in MATLAB” on page 1-66
• “Visualizing Multiple Signals Using Logic Analyzer” on page 1-72
• “Signal Visualization and Measurements in MATLAB” on page 1-80
1 DSP Tutorials

Introduction to Streaming Signal Processing in MATLAB

Use System objects to process streaming signals in MATLAB®. The signals are read in and processed
frame by frame (or block by block) in each processing loop. You can control the size of each frame.

In this example, frames of 1024 samples are filtered using a notch-peak filter in each processing loop.
The input is a sine wave signal that is streamed frame by frame from a dsp.SineWave object. The
filter is a notch-peak filter created using a dsp.NotchPeakFilter object. To ensure smooth
processing as each frame is filtered, the System objects maintain the state of the filter from one
frame to the next automatically.

Initialize Streaming Components

Initialize the sine wave source to generate the sine wave, the notch-peak filter to filter the sine wave,
and the spectrum analyzer to show the filtered signal. The input sine wave has two frequencies: one
at 100 Hz, and the other at 1000 Hz. Create two dsp.SineWave objects, one to generate the 100 Hz
sine wave, and the other to generate the 1000 Hz sine wave.

Fs = 2500;
Sineobject1 = dsp.SineWave('SamplesPerFrame',1024,...
'SampleRate',Fs,'Frequency',100);
Sineobject2 = dsp.SineWave('SamplesPerFrame',1024,...
'SampleRate',Fs,'Frequency',1000);

SA = spectrumAnalyzer('SampleRate',Fs,...
'Method','welch',...
'AveragingMethod','exponential',...
'ForgettingFactor',0.1,...
'PlotAsTwoSidedSpectrum',false,...
'ChannelNames',{'SinewaveInput','NotchOutput'},'ShowLegend',true);

Create Notch-Peak Filter

Create a second-order IIR notch-peak filter to filter the sine wave signal. The filter has a notch at 750
Hz and a Q-factor of 35. A higher Q-factor results in a narrower 3-dB bandwidth of the notch. If you
tune the filter parameters during streaming, you can see the effect immediately in the spectrum
analyzer output.

Wo = 750;
Q = 35;
BW = Wo/Q;
NotchFilter = dsp.NotchPeakFilter('Bandwidth',BW,...
'CenterFrequency',Wo, 'SampleRate',Fs);
fvtool(NotchFilter);

1-2
Introduction to Streaming Signal Processing in MATLAB

Stream In and Process Signal

Construct a for-loop to run for 3000 iterations. In each iteration, stream in 1024 samples (one frame)
of the sinewave and apply a notch filter on each frame of the input signal. To generate the input
signal, add the two sine waves. The resultant signal is a sine wave with two frequencies: one at 100
Hz and the other at 1000 Hz. The notch of the filter is tuned to a frequency of 100, 500, 750, or 1000
Hz, based on the value of VecIndex. The filter bandwidth changes accordingly. When the filter
parameters change during streaming, the output in the spectrum analyzer gets updated accordingly.

FreqVec = [100 500 750 1000];


VecIndex = 1;
VecElem = FreqVec(VecIndex);
for Iter = 1:3000
Sinewave1 = Sineobject1();
Sinewave2 = Sineobject2();
Input = Sinewave1 + Sinewave2;
if (mod(Iter,350)==0)
if VecIndex < 4
VecIndex = VecIndex+1;
else
VecIndex = 1;
end
VecElem = FreqVec(VecIndex);
end
NotchFilter.CenterFrequency = VecElem;
NotchFilter.Bandwidth = NotchFilter.CenterFrequency/Q;
Output = NotchFilter(Input);

1-3
1 DSP Tutorials

SA(Input,Output);
end

fvtool(NotchFilter)

1-4
Introduction to Streaming Signal Processing in MATLAB

At the end of the processing loop, the CenterFrequency is at 100 Hz. In the filter output, the 100
Hz frequency is completely nulled out by the notch filter, while the frequency at 1000 Hz is
unaffected.

See Also
“Filter Frames of a Noisy Sine Wave Signal in MATLAB” on page 1-6 | “Filter Frames of a Noisy
Sine Wave Signal in Simulink” on page 1-8 | “Lowpass IIR Filter Design in Simulink” on page 1-19
| “Multirate Filtering in MATLAB and Simulink” on page 1-35

1-5
1 DSP Tutorials

Filter Frames of a Noisy Sine Wave Signal in MATLAB

This example shows how to lowpass filter a noisy signal in MATLAB® and visualize the original and
filtered signals using a spectrum analyzer. For a Simulink® version of this example, see “Filter
Frames of a Noisy Sine Wave Signal in Simulink” on page 1-8.

Specify Signal Source

The input signal is the sum of two sine waves with frequencies of 1 kHz and 10 kHz. The sampling
frequency is 44.1 kHz.

Sine1 = dsp.SineWave('Frequency',1e3,'SampleRate',44.1e3);
Sine2 = dsp.SineWave('Frequency',10e3,'SampleRate',44.1e3);

Create Lowpass Filter

The lowpass FIR filter, dsp.LowpassFilter, designs a minimum-order FIR lowpass filter using the
generalized Remez FIR filter design algorithm. Set the passband frequency to 5000 Hz and the
stopband frequency to 8000 Hz. The passband ripple is 0.1 dB and the stopband attenuation is 80 dB.

FIRLowPass = dsp.LowpassFilter('PassbandFrequency',5000,...
'StopbandFrequency',8000);

Create Spectrum Analyzer

Set up the spectrum analyzer to compare the power spectra of the original and filtered signals. The
spectrum units are dBm.

SpecAna = spectrumAnalyzer('PlotAsTwoSidedSpectrum',false,...
'SampleRate',Sine1.SampleRate,...
'ShowLegend',true, ...
'YLimits',[-145,45]);

SpecAna.ChannelNames = {'Original noisy signal',...


'Lowpass filtered signal'};

Specify Samples per Frame

This example uses frame-based processing, where data is processed one frame at a time. Each frame
of data contains sequential samples from an independent channel. Frame-based processing is
advantageous for many signal processing applications because you can process multiple samples at
once. By buffering your data into frames and processing multisample frames of data, you can improve
the computational time of your signal processing algorithms. Set the number of samples per frame to
4000.

Sine1.SamplesPerFrame = 4000;
Sine2.SamplesPerFrame = 4000;

Filter the Noisy Sine Wave Signal

Add zero-mean white Gaussian noise with a standard deviation of 0.1 to the sum of sine waves. Filter
the result using the FIR filter. While running the simulation, the spectrum analyzer shows that
frequencies above 8000 Hz in the source signal are attenuated. The resulting signal maintains the
peak at 1 kHz because it falls in the passband of the lowpass filter.

1-6
Filter Frames of a Noisy Sine Wave Signal in MATLAB

for i = 1 : 1000
x = Sine1()+Sine2()+0.1.*randn(Sine1.SamplesPerFrame,1);
y = FIRLowPass(x);
SpecAna(x,y);
end
release(SpecAna)

See Also
“Lowpass Filter Design in MATLAB” on page 1-11 | “Filter Frames of a Noisy Sine Wave Signal in
Simulink” on page 1-8 | “Introduction to Streaming Signal Processing in MATLAB” on page 1-2 |
“Multirate Filtering in MATLAB and Simulink” on page 1-35

1-7
1 DSP Tutorials

Filter Frames of a Noisy Sine Wave Signal in Simulink


This example shows how to lowpass filter a noisy signal in Simulink® and visualize the original and
filtered signals with a spectrum analyzer. For a MATLAB® version of this example, see “Filter Frames
of a Noisy Sine Wave Signal in MATLAB” on page 1-6.

Open Model
To create a new blank model and open the library browser:

1 On the MATLAB Home tab, click Simulink, and choose the Basic Filter model template.
2 Click Create Model to create a basic filter model opens with settings suitable for use with DSP
System Toolbox. To access the library browser, in the Simulation tab, click Library Browser on
the model toolstrip.

The new model using the template settings and contents appears in the Simulink Editor. The model is
only in memory until you save it.

Inspect Model
Input Signal

Three source blocks comprise the input signal. The input signal consists of the sum of two sine waves
and white Gaussian noise with mean 0 and variance 0.05. The frequencies of the sine waves are 1
kHz and 15 kHz. The sampling frequency is 44.1 kHz.

1-8
Filter Frames of a Noisy Sine Wave Signal in Simulink

Lowpass Filter

The lowpass filter is modeled using a Lowpass Filter block. The example uses a generalized Remez
FIR filter design algorithm. The filter has a passband frequency of 8000 Hz, a stopband frequency of
10,000 Hz, a passband ripple of 0.1 dB, and a stopband attenuation of 80 dB.

The Lowpass Filter block uses frame-based processing to process data one frame at a time. Each
frame of data contains sequential samples from an independent channel. Frame-based processing is
advantageous for many signal processing applications because you can process multiple samples at
once. By buffering your data into frames and processing multisample frames of data, you can improve
the computational time of your signal processing algorithms.

Compare Original and Filtered Signal


Use a Spectrum Analyzer to compare the power spectra of the original and filtered signals. The
spectrum units are in dBm.

To run the simulation, in the model, click Run. To stop the simulation, in the Spectrum Analyzer
block, click Stop. Alternatively, you can execute the following code to run the simulation for 200
frames of data.

set_param(model,'StopTime','256/44100 * 400')
sim(model);

Frequencies above 10 kHz in the source signal are attenuated. The resulting signal maintains the
peak at 1 kHz because it falls in the passband of the lowpass filter.

See Also
Lowpass Filter | Sine Wave | Random Source | Spectrum Analyzer

1-9
1 DSP Tutorials

Related Examples
• “Filter Frames of a Noisy Sine Wave Signal in MATLAB” on page 1-6

1-10
Lowpass Filter Design in MATLAB

Lowpass Filter Design in MATLAB

This example shows how to design lowpass filters. The example highlights some of the most
commonly used command-line tools in the DSP System Toolbox™. Alternatively, you can use the Filter
Builder app to implement all the designs presented here. For more design options, see “Designing
Lowpass FIR Filters” on page 4-67.

Introduction

When designing a lowpass filter, the first choice you make is whether to design an FIR or IIR filter.
You generally choose FIR filters when a linear phase response is important. FIR filters also tend to be
preferred for fixed-point implementations because they are typically more robust to quantization
effects. FIR filters are also used in many high-speed implementations such as FPGAs or ASICs
because they are suitable for pipelining. IIR filters (in particular biquad filters) are used in
applications (such as audio signal processing) where phase linearity is not a concern. IIR filters are
generally computationally more efficient in the sense that they can meet the design specifications
with fewer coefficients than FIR filters. IIR filters also tend to have a shorter transient response and a
smaller group delay. However, the use of minimum-phase and multirate designs can result in FIR
filters comparable to IIR filters in terms of group delay and computational efficiency.

FIR Lowpass Designs - Specifying the Filter Order

There are many practical situations in which you must specify the filter order. One such case is if you
are targeting hardware which has constrained the filter order to a specific number. Another common
scenario is when you have computed the available computational budget (MIPS) for your
implementation and this affords you a limited filter order. FIR design functions in the Signal
Processing Toolbox (including fir1, firpm, and firls) are all capable of designing lowpass filters
with a specified order. In the DSP System Toolbox, the preferred function for lowpass FIR filter design
with a specified order is firceqrip. This function designs optimal equiripple lowpass/highpass FIR
filters with specified passband/stopband ripple values and with a specified passband-edge frequency.
The stopband-edge frequency is determined as a result of the design.

Design a lowpass FIR filter for data sampled at 48 kHz. The passband-edge frequency is 8 kHz. The
passband ripple is 0.01 dB and the stopband attenuation is 80 dB. Constrain the filter order to 120.

N = 120;
Fs = 48e3;
Fp = 8e3;
Ap = 0.01;
Ast = 80;

Obtain the maximum deviation for the passband and stopband ripples in linear units.

Rp = (10^(Ap/20) - 1)/(10^(Ap/20) + 1);


Rst = 10^(-Ast/20);

Design the filter using firceqrip and view the magnitude frequency response.

NUM = firceqrip(N,Fp/(Fs/2),[Rp Rst],'passedge');


fvtool(NUM,'Fs',Fs)

1-11
1 DSP Tutorials

The resulting stopband-edge frequency is about 9.64 kHz.

Minimum-Order Designs

Another design function for optimal equiripple filters is firgr. firgr can design a filter that meets
passband/stopband ripple constraints as well as a specified transition width with the smallest possible
filter order. For example, if the stopband-edge frequency is specified as 10 kHz, the resulting filter
has an order of 100 rather than the 120th-order filter designed with firceqrip. The smaller filter
order results from the larger transition band.

Specify the stopband-edge frequency of 10 kHz. Obtain a minimum-order FIR filter with a passband
ripple of 0.01 dB and 80 dB of stopband attenuation.

Fst = 10e3;
NumMin = firgr('minorder',[0 Fp/(Fs/2) Fst/(Fs/2) 1],...
[1 1 0 0],[Rp,Rst]);

Plot the magnitude frequency responses for the minimum-order FIR filter obtained with firgr and
the 120th-order filter designed with firceqrip. The minimum-order design results in a filter with
order 100. The transition region of the 120th-order filter is, as expected, narrower than that of the
filter with order 100.

hvft = fvtool(NUM,1,NumMin,1,'Fs',Fs);
legend(hvft,'N = 120','N = 100')

1-12
Lowpass Filter Design in MATLAB

Filtering Data

To apply the filter to data, you can use the filter command or you can use dsp.FIRFilter.
dsp.FIRFilter has the advantage of managing state when executed in a loop. dsp.FIRFilter
also has fixed-point capabilities and supports C code generation, HDL code generation, and optimized
code generation for ARM® Cortex® M and ARM Cortex A.

Filter 10 seconds of white noise with zero mean and unit standard deviation in frames of 256 samples
with the 120th-order FIR lowpass filter. View the result on a spectrum analyzer.

LP_FIR = dsp.FIRFilter('Numerator',NUM);
SA_FIR = spectrumAnalyzer('SampleRate',Fs);
tic
while toc < 10
x = randn(256,1);
y = LP_FIR(x);
step(SA_FIR,y);
end
release(SA_FIR)

1-13
1 DSP Tutorials

Using dsp.LowpassFilter

dsp.LowpassFilter is an alternative to using firceqrip and firgr in conjunction with


dsp.FIRFilter. Basically, dsp.LowpassFilter condenses the two step process into one.
dsp.LowpassFilter provides the same advantages that dsp.FIRFilter provides in terms of
fixed-point support, C code generation support, HDL code generation support, and ARM Cortex code
generation support.

Design a lowpass FIR filter for data sampled at 48 kHz. The passband-edge frequency is 8 kHz. The
passband ripple is 0.01 dB and the stopband attenuation is 80 dB. Constrain the filter order to 120.
Create a dsp.FIRFilter based on your specifications.

LP_FIR = dsp.LowpassFilter('SampleRate',Fs,...
'DesignForMinimumOrder',false,'FilterOrder',N,...
'PassbandFrequency',Fp,...
'PassbandRipple',Ap,'StopbandAttenuation',Ast);

The coefficients in LP_FIR are identical to the coefficients in NUM.

NUM_LP = tf(LP_FIR);

You can use LP_FIR to filter data directly, as shown in the preceding example. You can also analyze
the filter using FVTool or measure the response using measure.

fvtool(LP_FIR,'Fs',Fs);

1-14
Lowpass Filter Design in MATLAB

measure(LP_FIR)

ans =
Sample Rate : 48 kHz
Passband Edge : 8 kHz
3-dB Point : 8.5843 kHz
6-dB Point : 8.7553 kHz
Stopband Edge : 9.64 kHz
Passband Ripple : 0.01 dB
Stopband Atten. : 79.9981 dB
Transition Width : 1.64 kHz

Minimum-Order Designs with dsp.LowpassFilter

You can use dsp.LowpassFilter to design minimum-order filters and use measure to verify that
the design meets the prescribed specifications. The order of the filter is again 100.
LP_FIR_minOrd = dsp.LowpassFilter('SampleRate',Fs,...
'DesignForMinimumOrder',true,...
'PassbandFrequency',Fp,...
'StopbandFrequency',Fst,...
'PassbandRipple',Ap,...
'StopbandAttenuation',Ast);
measure(LP_FIR_minOrd)

ans =
Sample Rate : 48 kHz

1-15
1 DSP Tutorials

Passband Edge : 8 kHz


3-dB Point : 8.7136 kHz
6-dB Point : 8.922 kHz
Stopband Edge : 10 kHz
Passband Ripple : 0.0098641 dB
Stopband Atten. : 80.122 dB
Transition Width : 2 kHz

Nlp = order(LP_FIR_minOrd)

Nlp = 100

Designing IIR Filters

Elliptic filters are the IIR counterpart to optimal equiripple FIR filters. Accordingly, you can use the
same specifications to design elliptic filters. The filter order you obtain for an IIR filter is much
smaller than the order of the corresponding FIR filter.

Design an elliptic filter with the same sampling frequency, cutoff frequency, passband-ripple
constraint, and stopband attenuation as the 120th-order FIR filter. Reduce the filter order for the
elliptic filter to 10.

N = 10;
LP_IIR = dsp.LowpassFilter('SampleRate',Fs,...
'FilterType','IIR',...
'DesignForMinimumOrder',false,...
'FilterOrder',N,...
'PassbandFrequency',Fp,...
'PassbandRipple',Ap,...
'StopbandAttenuation',Ast);

Compare the FIR and IIR designs. Compute the cost of the two implementations.

hfvt = fvtool(LP_FIR,LP_IIR,'Fs',Fs);
legend(hfvt,'FIR Equiripple, N = 120',...
'IIR Elliptic, N = 10');

1-16
Lowpass Filter Design in MATLAB

cost_FIR = cost(LP_FIR)

cost_FIR = struct with fields:


NumCoefficients: 121
NumStates: 120
MultiplicationsPerInputSample: 121
AdditionsPerInputSample: 120

cost_IIR = cost(LP_IIR)

cost_IIR = struct with fields:


NumCoefficients: 25
NumStates: 20
MultiplicationsPerInputSample: 25
AdditionsPerInputSample: 20

The FIR and IIR filters have similar magnitude responses. The cost of the IIR filter is about 1/6 the
cost of the FIR filter.

Running the IIR Filters

The IIR filter is designed as a biquad filter. To apply the filter to data, use the same commands as in
the FIR case.

Filter 10 seconds of white Gaussian noise with zero mean and unit standard deviation in frames of
256 samples with the 10th-order IIR lowpass filter. View the result on a spectrum analyzer.

1-17
1 DSP Tutorials

SA_IIR = spectrumAnalyzer('SampleRate',Fs);
tic
while toc < 10
x = randn(256,1);
y = LP_IIR(x);
SA_IIR(y);
end
release(SA_IIR)

Variable Bandwidth FIR and IIR Filters

You can also design filters that allow you to change the cutoff frequency at run-time.
dsp.VariableBandwidthFIRFilter and dsp.VariableBandwidthIIRFilter can be used for
such cases.

See Also

Related Examples
• “Filter Frames of a Noisy Sine Wave Signal in MATLAB” on page 1-6
• “Lowpass IIR Filter Design in Simulink” on page 1-19
• “Tunable Lowpass Filtering of Noisy Input in Simulink” on page 1-45
• “Multirate Filtering in MATLAB and Simulink” on page 1-35

1-18
Lowpass IIR Filter Design in Simulink

Lowpass IIR Filter Design in Simulink


In this section...
“filterBuilder” on page 1-19
“Butterworth Filter” on page 1-20
“Chebyshev Type I Filter” on page 1-24
“Chebyshev Type II Filter” on page 1-25
“Elliptic Filter” on page 1-27
“Minimum-Order Designs” on page 1-29
“Lowpass Filter Block” on page 1-32
“Variable Bandwidth IIR Filter Block” on page 1-33

This example shows how to design classic lowpass IIR filters in Simulink.

The example first presents filter design using filterBuilder. The critical parameter in this design
is the cutoff frequency, the frequency at which filter power decays to half (-3 dB) the nominal
passband value. The example shows how to replace a Butterworth design with either a Chebyshev or
elliptic filter of the same order and obtain a steeper roll-off at the expense of some ripple in the
passband and/or stopband of the filter. The example also explores minimum-order designs.

The example then shows how to design and use lowpass filters in Simulink using the interface
available from the Lowpass Filter block.

Finally, the example showcases the Variable Bandwidth IIR Filter, which enables you to change the
filter cutoff frequency at run time.

filterBuilder
filterBuilder starts user interface for building filters. filterBuilder uses a specification-
centered approach to find the best algorithm for the desired response. It also enables you to create a
Simulink block from the specified design.

To start designing IIR lowpass filter blocks using filterBuilder, execute the command
filterBuilder('lp'). A Lowpass Design dialog box opens.

1-19
1 DSP Tutorials

Butterworth Filter

Design an eighth order Butterworth lowpass filter with a cutoff frequency of 5 kHz, assuming a
sample rate of 44.1 KHz.

Set the Impulse response to IIR, the Order mode to Specify, and the Order to 8. To specify the
cutoff frequency, set Frequency constraints to Half power (3 dB) frequency. To specify the
frequencies in Hz, set Frequency units to Hz, Input sample rate to 44100, and Half power (3 dB)
frequency to 5000. Set the Design method to Butterworth.

1-20
Lowpass IIR Filter Design in Simulink

Click Apply. To visualize the filter's frequency response, click View Filter Response. The filter is
maximally flat. There is no ripple in the passband or in the stopband. The filter response is within the
specification mask (the red dotted line).

1-21
1 DSP Tutorials

Generate a block from this design and use it in a model.

Open the ex_iir_design model. In Filter Builder, on the Code Generation tab, click Generate
Model. In the Export to Simulink window, specify the Block name as Butter and Destination as
Current. You can also choose to build the block using basic elements such as delays and gains, or
use one of the DSP System Toolbox filter blocks. This example uses the filter block.

1-22
Lowpass IIR Filter Design in Simulink

Click Realize model to generate the Simulink block. You can now connect the block input and output
ports to the source and sink blocks in the ex_iir_design model.

In the model, a noisy sine wave sampled at 44.1 kHz passes through the filter. The sine wave is
corrupted by Gaussian noise with zero mean and a variance of 10e-5. Run the model. The view in the
Spectrum Analyzer shows the original and filtered signals.

1-23
1 DSP Tutorials

Chebyshev Type I Filter


Now design a Chebyshev Type I filter. A Chebyshev type I design allows you to control the passband.
There are still no ripples in the stopband. Larger ripples enable a steeper roll-off. In this model, the
peak-to-peak ripple is specified as 0.5 dB.

In the Main tab of Filter Builder, set the

1 Magnitude Constraints to Passband ripple.


2 Passband ripple to 0.5.
3 Design method to Chebyshev type I.

Click Apply and then click View Filter Response.

Zooming in on the passband, you can see that the ripples are contained in the range [-0.5, 0] dB.

1-24
Random documents with unrelated
content Scribd suggests to you:
the dance of dubious propriety until such time as he should have made up
his imperial mind as to its character. For three months its fate trembled in
the balance. Then he decided that it should be and continue to be; and he
issued a formal proclamation to that effect—the first formal proclamation of
his reign. It was an opportunity for the re-introduction of ancient and
ancestral methods which the young Emperor could not lose. The edict had
gone forth in haste by word of mouth and by notice in the daily papers; but
he resolved that the proclamation should go by special envoy to all the
principalities that composed his powerful empire. Accordingly, an officer of
high rank, specially despatched from the court, read his Imperial Majesty’s
proclamation in every principality of the nation; and thereafter it was
legitimate and proper to dance the third figure of the new Lord
Chamberlain’s cotillion on all occasions of lordly festivities, and all the
elderly ladies accepted the situation with a cheerful submissiveness, and set
about using it for scandal-mongering purposes with promptitude and
alacrity.
*
* *
Early one Midsummer morning a strange fishing-smack was sighted
from the Ausserland wharves far out at sea, beating up against an obstinate
wind, and coming from the direction of the mainland. This in itself was
enough to cause general comment and to stir the whole village with a thrill
of interest; for strange vessels rarely came that way, except under stress of
storm; and though the sea was running unusually high there had been no
storm in many days. Besides, why should a vessel obviously unfitted for
that sort of sailing, beat up against a wind that would take her to the
mainland in half the time? Yet there she was, making for the island in long,
laborious tacks. Everybody stopped work to look at her; but work was
suspended and utterly thrown aside when she hoisted a pennant that,
according to the nautical code, signified that she had on board an Envoy
from his Imperial Majesty.
The whole town was astir in a moment. The shops and schools closed.
The village band began to practice as it had never practiced before. The
burgesses and other officials donned their garments of state. A committee
was promptly appointed to prepare a public banquet worthy of the
Emperor’s messenger. The children were sent collecting flowers, and were
instructed how to strew them in his path. The bell-ringers gathered and
arranged an elaborate

programme of chimes. The citizens got into their Sunday clothes, which
were most wonderful clothes in their way; and the town-crier, who played
the trumpet, got his instrument out and polished it up until it shone like
gold. But the man who felt most of the burden of responsibility upon his
shoulders was the Head Burgess. He got into his robes of office as quickly
as his wife and his three daughters could array him, and then he hastened to
the Rathhaus, or Town Hall, and there consulted the archives to find out
from the records of his predecessors what it became him to do when his
Majesty’s Envoy should announce his errand. He must make a speech, that
was clear, for the honor of the Island. But what speech should he make? He
could not compose one on the instant—in fact, he could not compose one at
all. What had his forerunners done on like occasions? He looked over the
record and found that three King’s Envoys had landed on the Island: one in
1699, to announce that the Island had been ceded by one kingdom to
another; another in 1764, to inform the people that the great-grandmother of
the hereditary Prince was dead; and another in 1848, to proclaim that the
Islanders’ right of exemption from conscription was suspended. In not one
of these cases, it should be remarked, did the message of King, Prince or
Emperor, change the face of affairs on the Island in the smallest degree. The
herring market remaining stable, the Ausserlanders cared no whit to whom
they paid taxes; as to the death of the Prince’s great-grandmother, they
simply remarked that it was a pity to die at the early age of eighty-seven;
and when they were told that they would have to get up a draft and be
conscripted into the army or navy, they just went fishing, and there the
matter dropped. One is not an Ausserlander for nothing.
But the Head Burgess found that the same speech had been used on all
three occasions. It was short, and he had little difficulty in committing it to
memory, for it took the ship of his Majesty’s Envoy six good hours to get
into port. This was the speech:
“Noble and Honorable, Well and High-Born Sir, the people of
Ausserland desire through their representative, the Head Burgess, to affirm
their unwavering loyalty to the most illustrious and high-born personage
who condescends to assume the government of a loyal and independent
populace, and to express the hope that Divine Providence may endow him
with such power and capacity as properly befit a so-situated ruler.”
So heartily did the whole population throw itself into the work of
preparing to receive the distinguished visitor, that everything had been in
readiness a full hour, when, in the early afternoon, the fishing-smack finally
made her landing. During this long hour, the whole town watched the
struggles of the little boat with the baffling wind and waves. Everybody was
in a state of delighted expectancy. An Emperor’s Envoy does not call on one
every day, and his coming offered an excuse for merry-making such as the
prosperous and easy-going people of Ausserland were only too willing to
seize.
So, when the boat made fast to the wharf, the signal guns boomed, and
the people cheered again and again, and threw their caps in the air when the
King’s Envoy appeared from the cabin and returned the salute of the Head
Burgess.
And, indeed, the King’s Envoy was a most satisfactory and gratifying
spectacle of grandeur. He was so grand and so gorgeous generally that he
might have been taken for the hereditary Prince, himself, had it not been
well known that the color of the hereditary Prince’s nose was unchangeable
—being what the ladies call a fast red—whereas, this gentleman’s face was
as white as the Head Burgess’s frilled shirtfront. But his clothes! So
splendid a uniform was never seen before. Some of it was of cobalt blue
and some of it of Prussian blue, and some of it of white; and, all over, in
every possible place, it was decorated with a gold lace and gold buttons and
silken frogs and tassels, and every other device of beauty that ingenuity
could suggest, with complete disregard of cost.
And then His Serene Highness, Herr Graf Maximilian von Bummelberg,
of Schloss Bummelfels in the Schwarzwald, stepped on the wharf and
graciously introduced himself to the representative of the people, who
grasped him warmly by the hand with a cordiality untempered by awe; and
the people shouted again as they saw the two great men together; and not
one suspected the anguish hidden by that martial outside. For, of course, as
such things will happen, the Envoy selected to carry the Emperor’s
proclamation to this marine principality was a man who had never been to
sea in his life, and who never would have made a sailor if he had been kept
at sea until he was pickled. And for eighteen hours the unfortunate
messenger of good tidings had been tossed about in the dark, close,
malodorous little cabin of a fishing-smack on the breast of a chopping sea,
beating up against a strong head wind. And, oh! had he not been sick? Sick,
sick, sick, and then again sick—so sick, indeed, that he had had to hide his
gorgeous clothes under a sailor’s dirty tarpaulin. This made him feel sicker
yet; but, though in the course of the trip he lost his respect for mankind,
including himself, for royalty, for religion, for life and for death, he still
retained a vital spark of respect for his beautiful clothes. He stood
motionless upon the wharf and returned the compliments of the Head
Burgess in a husky voice that sounded in his own ears strange and far off.
The Herr Graf Maximilian von Bummelberg, of Schloss Bummelfels in the
Schwarzwald, Envoy of his Imperial Majesty, was waiting for the ground to
steady itself, for it was behaving as it had never behaved before, to his
knowledge. It rolled and it heaved, it flew up and it nearly hit him in the
face, then it slipped away from under him and rocked back again sidewise.
Never having been on an island before, the King’s Envoy might have
thought that the land was really afloat if he had not seen that the wine in the
silver cup which the Burgess was presenting to him was swinging around
like everything else without spilling a drop.
Things began to settle a little after the Envoy had drunk the wine, and
when he had found that there was actually a carriage to take him to the
Town Hall, he brightened up wonderfully. He was much pleased to see also
that the Town Hall was solidly built of brick, and that it was to a stone
balcony that he was led to read his proclamation to the people. Grasping the
balustrade firmly with one hand, he read to the surging crowd before him—
he had heard of surging crowds before, but now he saw one that really did
surge—the message of his Imperial Master. The proclamation was
exceedingly brief, except for the recital of the titles of the Emperor. The
body of the document ran as follows:
“I announce to my faithful, loyal and devoted subjects of the honorable
principality of Ausserland, that hereafter, by my favor and pleasure, the use
of the Third Figure in the Cotillion is graciously granted to them without
further restriction. Done, under my hand and seal, this first day of July, in
the year of our Lord eighteen hundred and ninety-two.”
That was all. The people listened attentively and cheered
enthusiastically. Then the Envoy handed the proclamation and his
credentials to the Head Burgess, with a bow and a flourish, and signified his
intention of returning at once by the way he had come. Nor could any
entreaties prevail upon him even to stay to

the banquet already spread. He told the Burgesses, with many compliments
and assurances of his lofty esteem, that he had another principality to notify
before six o’clock the next morning, and that the business of his Imperial
Master admitted of not so much as a moment’s delay. The truth of the
matter, however, he kept to himself. For one thing, he could not have gazed
upon food without disastrous results. For another, he was experiencing an
emotion which in any other than a military breast would have been fear. He
had but one wish in the world, and that was to get back to the mainland, the
breeze being in his favor going back and promising a quicker passage.
Indeed it was with difficulty that he repressed a mad desire to ask the Head
Burgess whether the island ever fetched loose and floated further out, or
sank to the bottom. However, he maintained his dignity to the last; and, a
half an hour later, as the people watched the fishing-smack with the
Imperial ensign sail forth upon the dancing sea, bearing the Herr Graf
Maximilian von Bummelberg, of Schloss Bummelfels in the Schwarzwald,
they all agreed that, for a short visit, he made a very satisfactory King’s
Envoy.
But they could banquet very well without assistance from Envoys or
anybody, and they sat them down in the great hall of the Rathhaus, and they
fell upon the smoked herring and the fresh herring, and the pickled herring,
and the smoked goose-breast and the potato salad, and all the rest of the
good things, and they drank great tankards of home-made beer, and great
flagons of imported Rhenish wine; and, after that, they smoked long pipes
and chatted contentedly, mainly about the herring-market.
They had reached this stage in the proceedings before it occurred to any
one in the company to broach the comparatively uninteresting subject of the
Imperial proclamation, and then somebody said in a casual way that he did
not think he had quite caught the sense of it. Soon it appeared that no one
else had. The Head Burgess was puzzled. “I have just copied it into the
Town Archives,” he said; “but, upon my soul, I never thought of
considering the sense of it.” So the document was taken from the ponderous
safe of the Rathhaus and passed around among the goodly company, each
one of whom read it slowly through and smoked solemnly over it. The Head
Burgess was appealed to for the meaning of the word “cotillion.” He had to
confess that he did not exactly know. He believed, however, that it was a
custom-house word, and had reference to the gauging of proof spirits. Then
the Doctor was asked his opinion. He said, somewhat uneasily, that he
thought it was one of the new chemicals recently derived from coal tar; but,
with all due respect to his Imperial Majesty, he took no stock in such new-
fangled nonsense, and castor-oil would be good enough for his patients
while he lived. The School-Master would know, some one suggested; but
the School-Master had gone home early, being in expectation of an addition
to his family. The Dominie took a hand in the discussion, and calling
attention to the word figure, opined that it belonged to some branch of
astronomy hitherto under the ban of the universities on account of its
tendency to unsettle the minds of young men and promote the growth of
infidelity. He lamented the atheistical tendency of modern times, and shook
his head gravely as he said he hoped that the young Emperor would not be
led astray.

Many suggestions were made; so many, indeed, that, it being plainly


impossible to arrive at a consensus of opinion, the subject was dropped;
and, wrapped in great clouds of tobacco smoke, the conversation made its
way back to the herring fisheries.
But, later in the night, as the Head Burgess and the Doctor strolled
slowly homeward, smoking their pipes in the calm moonlight, the question
came up again, and they were earnestly discussing it in deep, sonorous
tones when they came in front of the house of the School-Master, and saw
by a light in the window of his study that he was still waiting the pleasure
of Mrs. School-Master. They rapped with their pipes on the door-post,
giving the signal that had often called their old friend forth to late card-
parties at the tavern, and in a couple of minutes—for no one hurries in
Ausserland—he appeared at the door in his old green dressing-gown and
with his long-stemmed pipe in his mouth.
Now, the School-Master was not only a man of profound learning, but a
man of rapid mental processes. He had heard from his open window the
discussion as his two friends slowly came down the street; and, in point of
fact, his professional instinct had led him to note the mystic word when it
dropped from the Envoy’s lips. This it was, rather than domestic
expectations, that had kept him awake so late. And in the time that elapsed
between the arrival of his friends and his appearance at the door, he had
prepared himself to meet the situation.
He listened solemnly to the question with the tolerant interest of a man
of science, and he answered it without hesitation, in the imposing tone of
perfect knowledge.

“A cotillion,” he said, decisively, “is the one-billionth part of a minus


million in quaternions, and is used by surveyors to determine the logarithm
of the cube root. That is, its use has hitherto been forbidden to the
government surveyors on account of the uncertainty of the formula. That,
however, has been finally determined by Prof. Lipsius, of Munich, and
hereafter it may be applied to delicate calculations in determining the
altitude of mountains too lofty for ascent. Gentlemen, I should like to ask
you in to take a night-cap with me, but, under the circumstances, you
understand.... Doctor, I don’t think we shall need you to-night. Good-
evening, friends.”
The Doctor and the Head Burgess ruminated over this new acquisition to
their stock of knowledge as they strolled on down the street. At last the
latter broke the silence and said, in a tone in which conviction struggled
with sleepiness:
“Doctor, I have often thought what a hard life those poor devils on the
mainland must have with their impassable mountains, and their railroads
that kill and mangle you if they get a millionth part of a cube root out of the
way, and the boundary-lines they are everlastingly quarreling about. Why,
here in Ausserland, see how simple it all is! We never have any trouble
about our boundary-lines. Where the land stops the water begins, and where
the land begins the water stops; and that’s all there is to it!”

And with these words, as the last puff of his pipe rose heavenward, the
Burgess dismissed the matter from his mind, and the Emperor’s
proclamation legitimizing the Third Figure of the Cotillion vanished from
his memory—and from that of all Ausserland—passing into oblivion with
those that had told of Ausserland’s change of nationality, of the conscription
of her exempt citizens, and of the death of the great-grandmother of the
hereditary Prince.
“SAMANTHA BOOM-DE-AY.”
was a long, rough, sunlit stretch of stony turnpike that
climbed across the flanks of a mountain range in Maine, and
skirted a great forest for many miles, on its way to an upland
farming-country near the Canada border.
As you ascended this road, on your right hand was a
continuous wall of dull-hued evergreens, straggly pines and
cedars, crowded closely and rising high above a thick
underbrush. Behind this lay the vast, mysterious, silent
wilderness. Here and there the emergence of a foamy, rushing river, or the
entrance of a narrow corduroy road or trail, afforded a glimpse into its
depths, and then you saw the slopes of hills and valleys, clad ever in one
smoky, bluish veil of fir and pine.
On the other hand, where you could see through the roadside brush, you
looked down the mountain slope to the plains below, where the brawling
mountain streams quieted down into pleasant water-courses; where broad
patches of meadow land and wheat field spread out from edges of the
woods, and where, far, far off, clusters of farm-houses, and further yet,
towns and villages, sent their smoke up above the hazy horizon.
It was a road of so much variety and sweep of view, as it kept its course
along the boundary of the forest’s dateless antiquity, and yet in full view of
the prosperous outposts of a well-established civilization, that the most
calloused traveler might have been expected to look about him and take an
interest in his surroundings. But the three people who drove slowly up this
hill one August afternoon might have been passing through a tunnel for all
the attention they paid to the shifting scene.
Their vehicle was a farm-wagon; a fine, fresh-painted Concord wagon.
The horses that drew it were large, sleek, and a little too fat. A comfortable
country prosperity appeared in the whole outfit; and, although the raiment
of the three travelers was unfashionably plain, they all three had an aspect
of robust health and physical well-being, which was much at variance with
their dismal countenances—for the middle-aged man who was driving
looked sheepish and embarrassed; the good-looking, sturdy young fellow
by his side was clearly in a state of frank, undisguised dejection, and the
black-garbed woman, who sat behind in a splint-bottomed chair, had the
extra-hard granite expression of the New England woman who particularly
disapproves of something; whether that something be the destruction of her
life’s best hopes or her neighbor’s method of making pie.
For mile after mile they jogged along in silence. Occasionally the elder
man would make some brief and commonplace remark in a tentative way,
as though to start a conversation. To these feeble attempts the young man
made no response whatever. The woman in black sometimes nodded and
sometimes said “Yes?” with a rising inflection, which is a form of torture
invented and much practiced in the New England States.

It was late in the afternoon when a noise behind and below them made
them all glance round. The middle-aged man drew his horses to one side;
and, in a cloud of dust, a big, old-fashioned stage of a dull-red color
overtook them and lumbered on its way, the two drivers interchanging
careless nods.
The woman did not alter her rigid attitude, and kept her eyes cast down;
but the passing of the stage awakened a noticeable interest in the two men
on the front seat. The elder gazed with surprise and curiosity at the freight
that the top of the stage-coach bore—three or four traveling trunks of
unusual size, shape and color, clamped with iron and studded with heavy
nails.
“Be them trunks?” he inquired, staring open-mouthed at the sight. “I
never seen trunks like them before.”
Neither of his companions
answered him; but a curious new
expression came into the young man’s
face. He sat up straight for the first
time; and, as the wagon drew back
into the narrow road, he began to
whistle softly and melodiously.
*
* *
When Samantha Spaulding was left
a widow with a little boy, she got, as
one of her neighbors expressed it,
“more politeness than pity.” In truth,
in so far as the condition has any luck
about it, Samantha was lucky in her
widowhood. She was a young widow,
and a well-to-do widow. Old man Spaulding had been a good provider and
a good husband; but he was much older than his wife, and had not
particularly engaged her affections. Now that he was dead, after some
eighteen months of married life, and had left her one of the two best farms
in the county, everybody supposed that Mis’ Spaulding would marry
Reuben Pett, who owned the other best farm, besides a saw-mill and a
stage-route. That is, everybody thought so, except Samantha and Pett. They
calmly kept on in their individual ways, and showed no inclination to join
their two properties, though these throve and waxed more and more
valuable year by year. They were good friends, however. Reuben Pett was a
sagacious counselor, and a prudent man of affairs; and when Samantha’s
boy became old enough to work, he was apprenticed to Mr. Pett, to the end
that he might some day take charge of the saw-mill business, which his
mother stood ready to buy for him.
But the youthful Baxter Spaulding had not reached the age of twenty
when he cast down his mother’s hopes in utter ruin by coming home from a
business trip to Augusta and announcing that he was going to marry, and
that the bride of his choice was a young lady of
the variety stage who danced for a living, her
specialty being known as “hitch-and-kick.”
Now, this may not seem, to you who read
this, quite a complete, perfect and
unimprovable thing in the way of the
abomination of desolation; but then you must
remember that you were not born and raised in
a far corner of the Maine hills, and that you
probably have so frequently seen play-actoress-
women of all sorts that the mere idea of them
has ceased to give you cold creeps down your
back. And to Samantha Spaulding the whole
theatrical system, from the Tragic Muse to the “hitch-and-kick artiste,” was
conceived in sin and born in iniquity; and what her son proposed to do was
to her no whit better than forgery, arson, or any other ungodliness. To you
of a less distinctively Aroostook code of morals, I may say that the
enchainer of young Spaulding’s heart was quite as good a little girl in her
morals and her manners as you need want to find on the stage or off it; and
“hitch-and-kick” dancing was to her only a matter of business, as serio-
comic singing had been to her mother, as playing Harlequin had been to her
father, and as grinning through a horse-collar had been to her grandfather
and great-grandfather, famous old English clowns in their day, one of whom
had been a partner of Grimaldi. She made her living, it is true, by traveling
around the country singing a song called “Ta-ra-ra Boom-de-ay,” which
required a great deal of high-kicking for its just and full artistic expression;
but then, it should be remembered, it was the way she had always made her
living, and her mother’s living, too, since the old lady lost her serio-comic
voice. And as her mother had taught her all she knew about dancing, and as
she and her mother had hardly been separated for an hour since she was out
of her cradle, Little Betty Billington looked on her profession, as you well
may imagine, with eyes quite different from those with which Mrs.
Samantha Spaulding regarded it. It was a lop-sided contest that ensued, and
that lasted for months. On one side were Baxter and his Betty and Betty’s
mama—after that good lady got over her natural objections to having her
daughter marry “out of the profession.” On the other side was Samantha,
determined enough to be a match for all three of them. Mr. Reuben Pett
hovered on the outskirts, asking only peace.
At last he was dragged into the fight. Baxter Spaulding went to Bangor,
where his lady’s company happened to be playing, with the avowed
intention of wedding Betty out of hand. When his mother found it out, she
took Reuben Pett and her boy’s apprenticeship-indenture to Bangor with
her, caught the youngster ere the deed was done, and, having the majesty of
the law behind her, she was taking her helpless captive home on this
particular August afternoon. He was on the front seat of the wagon,
Samantha was on the splint-bottomed chair, and Reuben Pett was driving.
*
* *
It was a two-days’ drive from the railroad station at Byram’s Pond
around the spur of the mountain to their home. The bi-weekly stage did it in
a day; but it was unwonted traveling for Mr. Pett’s easy-going team.
Therefore, the three travelers put up at Canada Jake’s camp; so called,
though it was only on the edge of the wilderness, because it was what
Maine people generally mean when they talk of a “camp”—a large shanty
of rough, unpainted planks, with a kitchen and eating-room below, and
rudely partitioned sleeping-rooms in the upper story. It stood by the
roadside, and served the purpose of an inn.
Canada Jake was lounging in the doorway as they came up, squat, bullet-
headed and bead-eyed; a very ordinary specimen of mean French Canadian.
He welcomed them in as if he were conferring a favor upon them, fed them
upon black, fried meat and soggy, boiled potatos, and later on bestowed
them in three wretched enclosures overhead.
He himself staid awake until the sound of two bass and one treble snore
penetrated the thin partition planks; and then he stole softly up the ladder
that served for stairway, and slipped into the moonlit little room where
Baxter Spaulding was lying on a cot-bed six inches too short for him.
Putting his finger upon his lips, he whispered to the wakeful youth:
“Sh-h-h-h-h-h! You got you’ boots on?”
“No,” said Baxter softly.
“Come wiz me and don’ make no noise!”
And the next thing that Baxter Spaulding knew, he was outside of the
house, behind the wood-pile, holding a slight but charming figure in his
arms, and saying:
“Why, Betty! why, Betty!” in a dazed sort of way, while a fat and
motherly lady near by stood shaking with silent sobs, like a jelly-fish
convulsed with sympathy and affection.
“We ’eaded you off in the stage-coach!” was all she said.
*
* *
The next morning Mr. Reuben Pett was called out of the land of dreams
by a familiar feminine voice from the next room.
“Reuben Pett!” it said; “where is Baxter?”
“Baxter!” yelled Mr. Pett; “your ma wants yer!”

But Baxter came not. His room was empty. Mr. Pett descended and
found his host out by the wood-pile, splitting kindling. Canada Jake had
seen nothing whatever of the young man. He opined that the youth most
’ave got up airlee, go feeshin’.
Reuben Pett went back and reported to Samantha Spaulding through the
door. Samantha’s voice came back to him as a voice from the bottom sub-
cellar of abysmal gloom.
“Reuben,” she said; “them women have been here!”
“Why, Samantha!” he said; “it ain’t possible!”
“I heard them last night,” returned Samantha, in tones of conviction. “I
know, now. I did. I thought then I was dreamin’.”
“Most likely you was, too!” said Mr. Pett, encouragingly.
“Well, I wa’n’t!” rejoined Mrs. Spaulding, with a suddenness and an
acerbity that made her listener jump. “They’ve stole my clothes!”
“Whatever do you mean, Samantha?” roared Reuben Pett.
“I mean,” said Mrs. Spaulding, in a tone that left no doubt whatever that
what she did mean she meant very hard; “I mean that that hussy has been
here in the night, and has took every stitch and string of my clothing, and
ain’t left me so much as a button-hole, except—except—except—”
“Except what?” demanded Reuben, in stark amazement.
“Except that there idolatrous flounced frock the shameless critter doos
her stage-dancing in!”
Mr. Pett might, perhaps, have offered appropriate condolences on this
bereavement had not a thought struck him which made him scramble down
the ladder again and hasten to the woodshed, where he had put up his team
the night before. The team was gone—the fat horses and fresh painted
wagon, and the tracks led back down the road up which they had ridden the
day before.
Once more Mr. Pett climbed the ladder; but when he announced his loss
he was met, to his astonishment, with severity instead of with sympathy.
“I don’t care, Reuben Pett,” Samantha spoke through the door; “if
you’ve lost ten horses and nineteen wagons. You got to hitch some kind of a
critter to suthin’, for we’re goin’ to ketch them people to-day or my name’s
not Samantha Spaulding.”
“But Law Sakes Alive, Samantha!” expostulated Mr. Pett; “you ain’t
goin’ to wear no circus clothes, be ye?”
“You go hunt a team, Mr. Pett,” returned his companion, tartly; “I know
my own business.”
Mr. Pett remonstrated. He pointed out that there was neither horse nor
vehicle to be had in the neighborhood, and that pursuit was practically
hopeless in view of the start which the runaways had. But Mrs. Spaulding
was obdurate with an obduracy that made the heart of Reuben Pett creep
into his boots. After ten minutes of vain combating, he saw, beyond a doubt,
that the chase would have to continue even if it were to be carried on
astraddle a pair of confiscated cows. Having
learned that much, he went drearily down
again to discuss the situation with Canada
Pete. Canada Pete was indisposed to be of
the slightest assistance, until Mr. Pett
reminded him of the danger of the law in
which he stands who aids a runaway
apprentice in his flight. After that, the sulky
Canadian awoke to a new and anxious
interest; and, before long, he remembered
that a lumberer who lived “a piece” up the
road had a bit of meadow-land reclaimed
from the forest, and sometimes kept an old
horse in it. It was a horse, however, that had
always positively refused to go under
saddle, so that a new complication barred
the way, until suddenly the swarthy face of
the habitant lit up with a joyful, white-
toothed grin.
“My old calèche zat I bring from Canada!
I let you have her, hey? You come wiz me!”
And Canada Pete led the way through the underbrush to a bit of a
clearing near his house, where were accumulated many years’ deposits of
household rubbish; and here, in a desert of tin-cans and broken bottles and
crockery, stood the oldest of all old calashes.
There are calashes and calashes, but the calash or calèche of Canada is
practically of one type. It is a high-hung, tilting chaise, with a commodious
back seat and a capacious hood, and with an absurd, narrow, cushioned bar
in front for the driver to sit on. It is a startling-looking vehicle in its mildest
form, and when you gaze upon a calash for the first time you will probably
wonder whether, if a stray boy should catch on behind, the shafts would not
fly up into the air, bearing the horse between them. Canada Pete’s calash
had evidently stood long a monument of decay, yet being of sturdy and
simple construction, it showed distinct signs of life when Pete seized its
curved shafts and ran it backward and forward to prove that the wheels
could still revolve and the great hood still nod and sway like a real calash in
commission. It was ragged, it was rusty, it was water-soaked and weather-
beaten, blistered and stained; but it hung together, and bobbed along behind
Canada Pete, lurching and rickety, but still a vehicle, and entitled to rank as
such.

The calash was taken into Pete’s back-yard; and then, after a brief and
energetic campaign, Pete secured the horse, which was a very good match
for the calash. He was an old horse, and he had the spring-halt. He held his
long ewe-neck to one side, being blind in one eye; and this gave him the
coquettish appearance of a mincing old maid. A little polka step, which he
affected with his fore-feet, served to carry out this idea.
Also, he had been feeding on grass for a whole Summer, and his spirits
were those of the young lambkin that gambols in the mead. He was happy,
and he wanted to make others happy, although he did not seem always to
know the right way to go about it. When Mr. Pett and Canada Pete had got
this animal harnessed up with odds and ends of rope and leather, they sat
down and wiped their brows. Then Mr. Pett started off to notify Mrs.
Samantha Spaulding.
Mr. Pett was a man unused to feminine society, except such as he had
grown up with from early childhood, and he was of a naturally modest,
even bashful disposition. It is not surprising, therefore, that he was startled
when, on re-entering the living-room of Canada Pete’s camp, he found
himself face to face with a strange lady, and a lady, at that, of a strangeness
that he had never conceived of before. She wore upon her head a
preposterously tall bonnet, or at least a towering structure that seemed to be
intended to serve the purpose of a bonnet. It reminded him—except for its
shininess and newness—of the hood of the calash; indeed, it may have
suggested itself vaguely to his memory that his grandmother had worn a
piece of head-gear something similar, though not so shapely, which in very
truth was nicknamed a “calash” from this obvious resemblance. The lady’s
shapely and generously feminine figure was closely drawn into a waist of
shining black satin, cut down in a V on the neck, before and behind, and
ornamented with very large sleeves of a strange pattern. But her skirts—for
they were voluminous beyond numeration—were the wonder of her attire.
Within fold after fold they swathed a foamy mystery of innumerable gauzy
white underpinnings. As Mr. Pett’s abashed eye traveled down this marvel
of costume it landed upon a pair of black stockings, the feet of which
appeared to be balanced somewhat uncertainly in black satin slippers with
queer high heels.
“Reuben Pett,” said the lady suddenly and with decision, “don’t you say
nothing! If you knew how them shoes was pinching me, you’d know what I
was goin’ through.”
Mr. Pett had to lean up against the door-post before recovering himself.
“Why, Samantha!” he said at last; “seems to me like you had gone
through more or less.”
Here Mrs. Spaulding reached out in an irritation that carried her beyond
all speech, and boxed Mr. Pett’s ears. Then she drew back, startled at her
own act, but even more surprised at Mr. Pett’s reception of it. He was
neither surprised nor disconcerted. He leaned back against the door-post
and gazed on unperturbed.
“My!” he said; “Samantha, be them that play-actresses’ clo’es?”
Mrs. Spaulding nodded grimly.
“Well, all I’ve got to say, Samantha,” remarked Reuben Pett, as he
straightened himself up and started out to bring their chariot to the door;
“all I’ve got to say, and all I want to say, is that she must be a mighty fine
figure of a woman, and that you’re busting her seams.”
Down the old dusty road the old calash jiggled and juggled, “weaving”
most of the way in easy tacks down the sharp declivities. On the front seat
—or, rather, on the upholstered bar—sat Reuben Pett, squirming
uncomfortably, and every now and then trying to sit side-saddle fashion for
the sake of easier converse with his fair passenger. Mrs. Spaulding occupied
the back seat, lifted high above her driver by the tilt

of the curious vehicle, which also served to make the white foundation of
her costume particularly visible, so that there were certain jolting moments
when she suggested a black-robed Venus rising from a snowy foam-crest.
At such moments Mr. Pett lost control of his horse to such an extent that the
animal actually danced and fairly turned his long neck around as though it
were set on a pivot. When such a crisis was reached, Mrs. Spaulding would
utter a shrill and startling “hi!” which would cause the horse to stop
suddenly, hurling Mr. Pett forward with such force that he would have to
grab his narrow perch to save his neck, and for the next hundred yards or so
of descent his attention would be wholly concentrated upon his duties as
driver—for the horse insisted upon waltzing at the slightest shock to his
nerves.
Mr. Pett’s tendency to turn around and stare should not be laid up against
him. For twenty years he had seen his neighbor, Mrs. Samantha Spaulding,
once, at least; perhaps twice or thrice; mayhap even six or seven times a
week; and yet, on this occasion, he had fair excuse for looking over his
shoulder now and then to assure himself that the fair passenger at whose
feet he—literally—sat, was indeed that very Samantha of his twenty years’
knowledge. How was he, who was only a man, and no ladies’ man at that,
to understand that the local dressmaker and the local habit of wearing
wrinkly black alpaca and bombazine were to blame for his never having
known that his next door neighbor had a superb bust and a gracious waist?
How was he to know that the blindness of his own eyes was alone
accountable for his ignorance of the whiteness of her teeth, and the
shapeliness of the arms that peeped from the big, old-fashioned sleeves?
Samantha’s especial care upon her farm was her well-appointed dairy, and it
is well known that to some women work in the spring-house imparts a
delicate creaminess of complexion; but he was no close observer, and how
was he to know that that was the reason why the little V in the front of
Samantha’s black satin bodice melted so softly into the fresh bright tint of
her neck and chin? How, indeed, was a man who had no better opportunities
than Reuben Pett had enjoyed, to understand that the pretty skirt-dancer
dress, a dainty, fanciful travesty of an old-time fashion, had only revealed
and not created an attractive and charming woman in his life-long friend
and neighbor?
Samantha was not thinking in the least of herself. She had accepted her
costume as something which she had no choice but to assume in the
exercise of an imperative duty. She wore it for conscience sake only, just as
any other New England martyr to her New England convictions of right
might have worn a mealsack or a suit of armor had circumstances imposed
such a necessity.
But when Reuben Pett had looked around three or four times, she
grasped her skirts in both hands and pushed them angrily down to their
utmost length. Then, with a true woman’s dislike of outraging pretty dress
material, she made a furtive experiment or two to see if her skirts would not
answer all the purposes of modesty without hanging wrong. Perhaps she
had a natural talent that way; at any rate, she found that they would.
“Samantha,” said Reuben Pett, over his shoulder, “what under the sun
sense be there in chasin’ them two young fools up? If they want to marry,
why not let ’em marry? It’s natural for ’em to want to, and it’s agin nature
to stop ’em. May be it wouldn’t be sech a bad marriage, after all. Now you
look at it in the light of conscience—”
“You’re a nice hand to be advocating marriage, Reuben Pett,” said Mrs.
Spaulding; “you jest hurry up that horse and I’ll look out for the light of
conscience.”
Mr. Pett chirruped to the capering ewe-neck, and they jolted downward
in silence for a half a mile. Then he said suddenly, as if emerging from a
cloud of reflection:
“I ain’t never said nothing agin marriage!”
*
* *
Noon-time came, and the hot August sun poured down upon them, until
the old calash felt, as Mr. Pett remarked, like a chariot of fire. This
observation was evolved in a humorous way to slacken the tension of a
situation which was becoming distinctly unpleasant. Moved by a spirit of
genial and broadly human benevolence which was somewhat unnatural to
him, Mr. Pett had insisted upon pleading the cause of the youthful runaways
with an insistence that was at once indiscreet and futile. In the end his
companion had ordered him to hold his tongue, an injunction he was quite
incapable of obeying. After a series of failures in the way of conversational
starters, he finally scored a success by suggesting that they should pause
and partake of the meagre refection which Canada Pete had furnished them
—a modest repast of doughnuts, apples and store-pie. This they ate at the
first creek where they found a convenient place to water the horse.
When they resumed their journey, they found that they were all refreshed
and in brighter mood. Even the horse was intoxicated by the water and that
form of verdure which may pass for grass on the margin of a mountain
highway in Maine.
This change of feeling was also perceptible in the manner and bearing of
the human beings who made up the cavalcade. Samantha adjusted her
furbelows with unconscious deftness and daintiness, while she gazed before
her into the bright blue heaven; and, I am sorry to say, sucked her teeth.
Reuben frankly flung one leg over the end of his seat, and conversed easily
as he drove along, poised like a boy who rides a bare-back horse to water.
After awhile he even felt emboldened to resume the forbidden theme of
conversation.
“Nature is nature, Samantha,” he said.
“ ’Tis in some folks,” responded Samantha, dryly; “there’s others seems
to be able to git along without it.” And Reuben turned this speech over in
his mind for a good ten minutes.
Then, just as he was evidently about to say something, he glanced up and
saw a sight which changed the current of his reflections. It was only a cloud
in the heavens, but it evidently awakened a new idea in his mind.
“Samantha,” he said, in a tone of voice that seemed inappropriately
cheerful; “they’s goin’ to be a thunder storm.”
“Fiddlesticks!” said Mrs. Spaulding.
“Certain,” asseverated Mr. Pett; “there she is a-comin up, right agin the
wind.”
A thunder storm on the edge of a Maine forest is not wholly a joke. It
sometimes has a way of playing with the forest trees much as a table d’hôte
diner plays with the wooden tooth-picks. Samantha’s protests, when Mr.
Pett stated that he was going to get under the cover of an abandoned saw-
mill which stood by the roadside a little way ahead of them, were more a
matter of form than anything else. But still, when they reached the rough
shed of unpainted and weather-beaten boards, and Mr. Pett, in turning in
gave the vehicle a sudden twist that broke the shaft, her anger at the delay
thus rendered necessary was beyond her control.
“I declare to goodness, Reuben Pett,” she cried; “if you ain’t the
awkwardest! Anybody’d a’most think you’d done that a purpose.”
“Oh, no, Samantha!” said Reuben Pett, pleasantly; “it ain’t right to talk
like that. This here machine’s dreadful old. Why, Samantha, we’d ought to
sympathize with it—you and me!”
“Speak for yourself, Mr. Pett,” said Samantha. “I ain’t so dreadful old,
whatever you may be.”
At the moment Mr. Pett made no rejoinder to this. He unshipped the
merry horse, and tied him to a post under the old saw-mill, and then he
pulled the calash up the runway into the first story, and patiently set about
the difficult task of mending the broken shaft, while Samantha, looking out
through the broad, open doorway, watched the fierce Summer storm
descend upon the land; and she tapped her impatient foot until it almost
burst its too narrow satin covering.
“No, Samantha,” Mr. Pett said, at last, intently at work upon his splicing;
“you ain’t so dreadful old, for a fact; but I’ve knowed you when you was a
dreadful sight younger. I’ve knowed you,” he continued, reflectively, “when
you was the spryest girl in ten miles round—when you could dance as
lively as that young lady whose clo’es you’re a-wearin’.”
“Don’t you dare to talk to me about that jade!” said Mrs. Spaulding,
snappishly.
“Why, no! certainly not!” said Mr. Pett; “I didn’t mean no comparison.
Only, as I was a-sayin’, there was a time, Samantha, when you could
dance.”

“And who says I can’t dance now?” demanded Mrs. Spaulding, with
anger in her voice.
“My! I remember wunst,” said Mr. Pett; and then the sense of
Samantha’s angry question seemed to penetrate his wandering mind.
“ ‘Dance now?’ ” he repeated. “Sho! Samantha, you couldn’t dance
nowadays if you was to try.”
“Who says I couldn’t?” asked Samantha, again, with a set look
developing around the corners of her mouth.
“I say you couldn’t,” replied Mr. Pett, obtusely. “ ’Tain’t in nature. But
there was a time, Samantha, when you was great on fancy steps.”
“Think I’m too old for fancy steps now, do you?” She looked at her
tormentor savagely, out of the corners of her eyes.
“Well, not too old, may be, Samantha,” went on Mr. Pett; “but may be
you ain’t that limber you was. I know how it is. I ain’t smart as I used to be,
myself. Why, do you remember that night down at the Corners, when we
two was the only ones that could jump over Squire Tate’s high andirons and
cut a pigeon-wing before we come down?”
Mr. Pett appeared to be entirely unconscious that Mrs. Spaulding’s
bosom was heaving, that her eyes were snapping angrily, and that her foot
was beating on the floor in that tattoo with which a woman announces that
she is near an end of her patience.
“How high was them andirons?” she asked, breathlessly.
“Oh, I don’t know,” answered Reuben, indifferently. He kept his eyes
fixed on his work; but while he worked his splice closer with his right hand,
with his left he took off his hat and held it out rather more than two feet
above the floor.
“ ’Bout as high as that, may be,” he said. “Remember the tune we done
that to? Went some sort of way like this, didn’t it?” And with that
remarkable force of talent which is only developed in country solitudes, Mr.
Pett began to whistle an old-time air, a jiggetty, wiggetty whirl-around
strain born of some dead darkey’s sea-sawing fiddle-bow, with a volume of
sustained sound that would have put to shame anything the saw-mill could
have done for itself in its buzzingest days.
“Whee-ee-ee, ee-ee, ee ee ee, whee, ee, ee, ee ee!” whistled Mr. Pett; and
then, softly, and as if only the dim stirring of memory moved him, he began
to call the old figures of the old dance.
“Forward all!” he crooned. “Turn partners! Sashay! Alleman’ all! Whee-
ee-ee, ee-ee, ee ee, ee ee ee, whee, ee, ee, ee, ee, ee ee!”
And suddenly, like the tiger leaping from her lair, the soft pattering and
shuffling of feet behind him resolved itself into a quick, furious rhythmic
beat, and Samantha Spaulding shot high into the air, holding up her skirts
with both hands, while her neat ankles crossed each other in a marvelous
complication of agility a good twelve inches above his outstretched hat.
“There!” she cried, as she landed with a flourish that combined skill and
grace; “there’s what I done with you, and much I think of it! If you want to
see dancin’ that is dancin’ look here. Here’s what I did with Ben Griggs at
the shuckin’ that same year; and you wa’n’t there, and good reason why!”
And then and there, while Reuben Pett’s great rasping whistle rang
through the old saw-mill, shrilling above the roar of the storm outside, Mrs.
Samantha Spaulding executed with lightning rapidity and with the precision
of perfect and confident knowledge, a dancing-step which for scientific
complexity and daring originality had been twenty years before the surprise,
the delight, the tingling, shocking, tempting nine-days’-wonder of the
country-side.
“Whee-ee-ee, ee-ee, ee ee, ee ee ee, whee, ee, ee ee, ee ee!” Reuben
Pett’s whistle died away from sheer lack of breath as Samantha came to the
end of her dance.
*
* *
There is nothing that hath a more heavy and leaden cold than a chilled
enthusiasm. When the storm was over, although a laughing light

played over the landscape; although diamond sparkles lit up the grateful
white mist that rose from the refreshed earth; although the sun shone as
though he had been expecting that thunder storm all day, and was
inexpressibly glad that it was over and done with, Samantha leaned back in
her seat in the calash, and nursed a cheerless bitterness of spirit—such a
bitterness as is known only to the New England woman to whom has come
a realization of the fact that she has made a fool of herself. Samantha
Spaulding. Made a fool of herself. At her age. After twenty years of
respectable widowhood. Her, of all folks. And with that old fool. Who’d
be’n a-settin’ and a-settin’ and a-settin’ all these years. And never said Boo!
And now for him to twist her round his finger like that. She felt like—well,
she didn’t know how she did feel.
She was so long wrapped up in her own thoughts that it was with a start
that she awoke to the fact that they were making very slow progress, and
that this was due to the very peculiar conduct of Mr. Pett. He was making
little or no effort to urge the horse along, and the horse, consequently,
having got tired of wasting his bright spirits on the empty air, was
maundering. So was Mr. Pett, in another way. He mumbled to himself; from
time to time he whistled scraps of old-fashioned tunes, and occasionally he
sang to himself a brief catch—the catch coming in about the third or fourth
bar.
“Look here, Reuben Pett!” demanded Samantha, shrilly; “be you going
to get to Byram’s Pond to-night?”
“I kin,” replied Reuben.
“Well, be you?” Samantha Spaulding inquired.
“I d’no. Fact is, I wa’n’t figurin’ on that just now.”
“Well, what was you figurin’ on?” snapped Mrs. Spaulding.
“When you’s goin’ to marry me,” Mr. Pett answered with perfect
composure. “Look here, Samantha! it’s this way: here’s twenty years
you’ve kept me waitin’.”
“Me kept you waitin’! Well, Reuben Pett, if I ever!”
“Don’t arguefy, Samantha; don’t arguefy,” remonstrated Mr. Pett; “I ain’t
rakin up no details. What we’ve got to deal with is this question as it stands
to-day. Be you a-goin’ to marry me or be you not? And if you be, when be
you?”
“Reuben Pett,” exclaimed Samantha, with a showing of severity which
was very creditable under the circumstances; “ain’t you ashamed of talk
like that between folks of our age?”
“We ain’t no age—no age in particular, Samantha,” said Mr. Pett. “A
woman who can cut a pigeon-wing over a hat held up higher than any two
pair of andirons that I ever see is young enough for me, anyway.” And he
chuckled over his successful duplicity.
Samantha blushed a red that was none the less becoming for a tinge of
russet. Then she took a leaf out of Mr. Pett’s book.
“Young enough for you?” she repeated. “Well, I guess so! I wa’n’t
thinkin’ of myself when I said old, Mr. Pett. I was thinkin’ of folks who was
gettin’ most too old to drive down hill in a hurry.”
“Who’s that?” asked Reuben.
“I ain’t namin’ any names,” said Samantha; “but I’ve knowed the time
when you wasn’t so awful afraid of gettin’ a spill off the front seat of a
calash. Lord! how time does take the tuck out of some folks!” she
concluded, addressing vacancy.
“Do you mean to say that I da’sn’t drive you down to Byram’s Pond to-
night?” Mr. Pett inquired defiantly.
“I don’t know anything about it,” said Mrs. Spaulding.
Mr. Pett stuck a crooked forefinger into his lady-love’s face, and gazed
at her with such an intensity that she was obliged at last to return his
penetrating gaze.
“If I get you to Byram’s Pond before the train goes, will you marry me
the first meetin’ house we come to?”
“I will,” said Mrs. Spaulding, after a
moment’s hesitation, well remembering
what the other party to the bargain had
forgotten, that there was no church in
Byram Pond, nor nearer than forty miles
down the railroad.
*
* *
In the warm dusk of a Summer’s
evening, a limping, shackle-gaited,
bewildered horse, dragging a calash in the
last stages of ruin, brought two travelers
into the village of Byram’s Pond. Far up on
the hills there lingered yet the clouds of dust
that marked where that calash had come
down those hills at a pace whereat no calash
ever came down hill before. Dust covered
the two travelers so thickly, that, although the woman’s costume was of
peculiar and striking construction, its eccentricities were lost in a dull and
uniform grayness. Her bonnet, however, would have excited comment. It
had apparently been of remarkable height; but pounding against the hood of
the calash had so knocked it out of all semblance to its original shape, that
with its great wire hoops sticking out “four ways for Sunday,” it looked
more like a discarded crinoline perched upon her head than any known
form of feminine bonnet.

The calash slowed up as it drew near the town. Suddenly it stopped


short, and both the travelers gazed with startled interest at a capacious white
tent reared by the roadside. From within this tent came the strains of a
straining melodeon. Over the portal was stretched a canvas sign:
GOSPEL TENT OF REV. J. HANKEY.
As the travelers stared with all their eyes, they saw the flap of the tent
thrown back, and four figures came out. There were two ladies, a stout,
middle-aged lady, a shapely, buxom young lady, a tall, broad-shouldered
young man, and the fourth figure was unmistakably a Minister of one of the
Congregational denominations. The young man and the two ladies walked
down the road a little way, and, entering a solid-looking farm wagon, drove
off behind a pair of plump horses, in the direction of the railroad station,
while the minister waved them a farewell that was also a benediction.
“Git down, Samantha!” said Reuben Pett, “and straighten out that bonnet
of yours. Parson’s got another job before prayer-meetin’ begins.”
MY DEAR MRS. BILLINGTON.
ISS CARMELITA BILLINGTON sat in a bent-wood
rocking-chair in an upper room of a great hotel by the sea,
and cried for a little space, and then for a little space dabbed
at her hot cheeks and red eyes with a handkerchief wet with
cologne; and dabbed and cried, and dabbed and cried,
without seeming to get any “forwarder.” The sun and the
fresh breeze and the smell of the sea came in through her open windows,
but she heeded them not. She mopped herself with cologne till she felt as if
she could never again bear to have that honest scent near her dainty nose;
but between the mops the tears trickled and trickled and trickled; and she
was dreadfully afraid that inwardly, into the surprising great big cavity that
had suddenly found room for itself in her poor little heart, the tears would
trickle, trickle, trickle forever. It was no use telling herself she had done
right. When you have done right and wish you hadn’t had to you can’t help
having a profound contempt for the right. The right is respectable, of
course, and proper and commendable and—in short, it’s the right;—but, oh!
what a nuisance it is! You can’t help wondering in your private mind why
the right is so disagreeable and unpleasant and unsatisfactory, and the
wrong so extremely nice. Of course, it was right to refuse Jack Hatterly; but
why, why on earth couldn’t it just as easily have been right to accept him?
And the more she thought about it the more she doubted whether it was
always quite right to do right, and whether it was not sometimes entirely
wrong not to do wrong.
No; it was no use telling herself to be a brave girl. She was a brave girl
and she knew it. In the face of the heartless world she could bear herself as
jauntily as if she were heartless, too; but in the privacy of her own room,
with Mama fast asleep on the verandah below, she could not see the
slightest use in humbugging herself. She was perfectly miserable, and the
rest of her reflections might have been summed up in the simple phrase of
early girlhood, “So there!”
It was no consolation to poor Carmelita’s feelings that her little private
tragedy was of a most business-like, commonplace, unromantic
complexion. It only made her more disgusted with herself for having made
up her mind to do the right thing. She was not torn from her chosen love by
the hands of cruel parents. Her parents had never denied her anything in her
life, and if she had really wanted to wed a bankrupt bashaw with three tails
and an elephant’s head, she could have had her will. Nor did picturesque
poverty have anything to do with the situation. She was rich and so was
Jack. Nor could she rail against a parental code of morality too stern for
tender hearts. There was not the least atom of objection to Jack in any
respect. He was absolutely as nice as could be—and, unless I am greatly
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.

More than just a book-buying platform, we strive to be a bridge


connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.

Join us on a journey of knowledge exploration, passion nurturing, and


personal growth every day!

ebookbell.com

You might also like