Está en la página 1de 82

Filter Design for dsPIC™ DSC

Digital Filter Design and Analysis System

Momentum Data Systems, Inc.


Copyright/Trademark Information

Copyright 2008
Momentum Data Systems
17330 Brookhurst Street, Suite 230
Fountain Valley, CA 92708

World rights reserved. No part of this publication may be stored in a retrieval system, transmitted,
or reproduced in any way, including but not limited to photocopy, photograph, magnetic or other
record, without the prior agreement and written permission of Momentum Data Systems.

Information in this manual is subject to change without notice and does not represent a commit-
ment on the part of Momentum Data systems. The software described in this reference guide is
furnished under a license agreement and may be used or copied only in accordance with the terms
of the agreement.

This manual was produced and printed using FrameMaker.


FrameMaker is a registered trademark of Adobe.

All trademarks are copyrighted to their respective owners.


Microchip, dsPIC, and MPLAB are trademarks of Microchip Technology Inc. and are used under
license.
LICENSE AGREEMENT
PLEASE READ THE FOLLOWING TERMS AND CONDITIONS BEFORE USING THIS PROGRAM. USE OF THE PROGRAM INDI-
CATES YOUR ACCEPTANCE OF THESE TERMS AND CONDITIONS. IF YOU DO NOT AGREE WITH THEM, RETURN THE PRO-
GRAM ALONG WITH PROOF OF PURCHASE AND YOUR MONEY WILL BE REFUNDED BY SELLER

Momentum Data Systems, provides this program and licenses its use. You assume responsibility for the selection of the
program to achieve your intended results, and for the installation, use and results obtained from the program.

LICENSE

You are licensed to:


1. use the program on any machine in your possession, but you may not have a copy on more than one machine at
any given time unless a floating license has been purchased; Users receiving upgrades must destroy all copies of
previous software releases;
2. copy the program into any machine-readable or printed form for backup purposes in support of your use of the
program;
3. incorporate the results generated by this system into another program for your use;
4. transfer the program and license to another party if the other party agrees to accept the terms and conditions of
this Agreement. If you transfer the program, you must at the same time either transfer all copies whether in
printed or machine-readable form to the same party or destroy any copies not transferred; When transferring the
license to another party, please inform MDS as to the name of the new registered owner.

YOU MAY NOT USE, COPY, MODIFY, OR TRANSFER THIS PROGRAM, OR ANY COPY, MODIFICATION, OR
MERGED PORTION, IN WHOLE OR IN PART, EXCEPT AS EXPRESSLY PROVIDED FOR IN THIS LICENSE. IF YOU
TRANSFER POSSESSION OF ANY COPY, MODIFICATION, OR MERGED PORTION OF THIS PROGRAM TO ANY
OTHER PARTY, YOUR LICENSE IS AUTOMATICALLY TERMINATED.

TERM

The license is effective until terminated. You may terminate it at any other time by destroying the program together with
all copies, modifications and merged portions in any form. It will also terminate upon conditions set forth elsewhere in
this Agreement or if you fail to comply with any term or condition of this Agreement. You agree upon such termination to
destroy the program together with all copies, modifications and merged portions in any form with the exception of User
Programs.

LIMITED WARRANTY

With respect to the software and physical documentation enclosed herein, Momentum Data Systems, Inc. (MDS) warrants
the same to be free of defects in materials and workmanship for period of 30 days from the date of purchase. In the event
of notification within the warranty period of defects in material or workmanship, MDS will replace the defective diskettes
or documentation. The remedy for breach of this warranty shall be limited to replacement and shall not encompass any
other damages, including but not limited to loss of profit, special, incidental, consequential, or other similar claims.

Momentum Data Systems, Inc. and its distributors specifically disclaims all other warranties, expressed or implied,
including but not limited to, implied warranties of merchantability and fitness for a particular purpose with respect to
defects in the software and documentation and the program license granted herein, in particular, and without limiting
operation of the program license with respect to any particular application, use, or purpose. In no event shall MDS and its
distributors be liable for any loss of profit or any other commercial damage including but not limited to special, incidental,
consequential or other damages.

GENERAL

You may not sublicense, assign or transfer the license or program except as expressly provided in this Agreement.
Momentum Data Systems, Inc. does not warrant that operation of the program will be uninterrupted or error-free.

MDS agrees to provide free technical support to all users that are registered owners. This support will be free of charge for
a period of at least 90 days following the date of your purchase.

This Agreement will be governed by the laws of the State of California, excluding any conflict of laws provisions.

You acknowledge that you have read this agreement, understand it, and agree to be bound by its terms and conditions. You
further agree that it is the complete and exclusive agreement between us which supersedes any proposal or prior agree-
ment, oral or written, and any other communications between us relating to the subject matter of this Agreement.

IF YOU HAVE ANY QUESTIONS CONCERNING THIS AGREEMENT, PLEASE CONTACT MOMENTUM DATA
SYSTEMS.
Filter Design for dsPIC™ DSC
Table of contents

Chapter 1 - Introduction
1.1 Design Capabilities 1-2
1.2 General System Features. 1-4
1.3 Installation 1-5
1.3.1 Application Software Installation 1-5
1.4 Input Specifications 1-6
1.5 Design Methods 1-7
1.6 System Operation 1-8
Chapter 2 - Examples
2.1 IIR Lowpass 2-2
2.2 IIR Bandpass 2-5
2.3 FIR Lowpass 2-7
2.4 Equiripple FIR Lowpass 2-10
2.5 Using a dsPICfd Filter in dsPICworks 2-12
Chapter 3 - System Operation
3.1 Toolbar 3-3
3.1.1 Status Bar 3-5
3.2 File Menu 3-6
3.2.1 Load Specification File 3-7
3.2.2 Print 3-8
3.2.3 Printer Setup 3-8
3.2.4 System Settings 3-9
3.2.5 User Information 3-10
3.2.6 Exit 3-10
3.2.7 About dsPIC‘ FD Filter Design 3-11
3.3 View Menu 3-12
3.3.1 Toolbar 13-2
3.3.2 Status Bar 3-12
3.3.3 Text Filter File View 3-13
3.4 Design Menu 3-14
3.4.1 IIR Design 3-15
3.4.2 FIR Design with Windows 3-17
3.4.3 Equiripple FIR Design 3-20
3.5 Filter Menu 3-22
3.5.1 Lowpass 3-23
3.5.2 Highpass 3-24
3.5.3 Bandpass 3-25
3.5.4 Bandstop 3-26
3.6 Output Menu 3-27
3.6.1 Plot Control 3-27
3.6.2 Snap to Grid 3-30
3.6.3 Quantization 3-30
3.6.4 Create Specification File 3-31
3.6.5 Create Filter Coefficient File 3-32
3.6.6 Create Plot Data Files 3-33
3.7 Code Generation Menu 3-34
3.7.1 Create C Code 3-35
3.7.2 C Code File Generation 3-35
3.7.3 Microchip dsPIC30F/33F Code Generation 3-35
3.8 Window Menu 3-40
3.8.1 Select Plots 3-41
3.8.2 Display Control 3-41
Chapter 4 - Filter Coefficient Files
4.1 IIR FILTER COEFFICIENT FILES 4-2
4.1.1 General Discussion on Cascaded Biquad Sections 4-3
4.1.2 Fractional Fixed Point Cascaded Biquad Sections 4-5
4.2 FIR FILTER COEFFICIENT FILE 4-9
Chapter 5 - Addendum
5.1 References 5-2
5.2 IIR Design Output Example 5-3
CHAPTE R 1 Introduction to Filter
Design for Microchip
Technology dsPIC30F/
dsPIC33F

This manual is a reference guide to the Filter Design System dsPICFd specifically
developed for use with Microchip Technology’s dsPIC30F/dsPIC33F™ family. It is
intended to explain the usage of the system and what the various screen displays and
computer printouts mean. It is not intended to be a tutorial on digital signal processing
since several excellent texts on the subject exist and it is assumed that the user has had a
certain amount of academic or professional exposure to the subject. Several references
are given in Chapter 4, should more in-depth information be required.

This software tool dsPICFd will allow the user to design coefficients for digital filters
and provides a seamless manner of getting a filter routine and its associated coefficients
into an MPLAB project.

More advanced versions of QEDesign are also available. Please call Momentum Data
Systems for further information. These systems support significantly more powerful filter
design techniques.

dsPIC Filter Design Reference Guide Page 1 - 1


1.1 Design Capabilities
Infinite Impulse Response Filter Design:

• Lowpass, Highpass, Bandpass, and Bandstop Filters


• Filter orders up to 10 for Lowpass and Highpass Filters (4 for dsPICFdlite)
• Filter orders up to 20 for Bandpass and Bandstop Filters (8 for dsPICFdlite)
• Five Analog Prototype Filters are available:
–Butterworth
–Tschebyscheff
–Inverse Tschebyscheff
–Elliptic
–Bessel
• Digital Transformations are performed by the following method:
–Bilinear Transformation Method
• Reports show design details such as all transformations from normalized lowpass
filter to desired filter
Finite Impulse Response Filter Design:

• Design Method Selection


–FIR Windows Design
–FIR Equiripple Design (Parks-McClellan)
• Lowpass, Highpass, Bandpass, and Bandstop filters
• An FIR filter can have up to 513 taps (64 for dsPICFdlite)
• Following window functions are supported:
–Rectangular
–Hanning (Hann)
–Hamming
–Triangular
–Blackman
–Exact Blackman
–3 Term Cosine
–3 Term Cosine with continuous 3rd Derivative
–Minimum 3 Term Cosine
–4 Term Cosine
–4 Term Cosine with continuous 5th Derivative
–Minimum 4 Term Cosine
–Good 4 Term Blackman Harris

Page 1 - 2 dsPIC Filter Design Reference Guide


–Harris Flat Top
–Kaiser
–Dolph-Tschebyscheff
–Taylor
–Gaussian
• Reports show design details such as window coefficients and Impulse Response
prior to multiplying by the window function
• Filters are designed for a maximum gain of 1
Code Generation Features

• The filter design program supports C callable assembly language reoutines that
implement the designed filter.
• The user creates the desired filter within dsPICfd. When a satisfactory filter has
been created, the code generator can be invoked to create the files associated with
the filter.
• An option to create a C main program to execute the filter using the simulator is
allowed.
• There is support for 32-bit coefficients in the dsPICFd system. This capability is not
available for dsPICFdlite.

Other General Features


• MPLAB C30 computer syntax is used for all calls to assembly language routines.
• Graphical Output includes:
–Magnitude Response vs. Frequency
–Log Magnitude vs. Frequency
–Phase Response vs. Frequency
–Group Delay vs. Frequency
–Impulse Response vs. Time (per sample)
–Step Response vs. Time (per sample)
–Pole and Zero Locations (IIR only)

dsPIC Filter Design Reference Guide Page 1 - 3


1.2 General System Features.
1. Recycling of input for comparative analysis - input for a filter is retained until a new
specification is called for. This allows various IIR designs to be compared with FIR
window designs as well as FIR equiripple designs.

2. Use of 64 bit floating point for all design calculations ensures that maximum
accuracy is maintained for the design calculations. Certain critical calculations are
carried out in 128 bit precision.

3. Specification file which allows the retention and retrieval of filter specifications.

4. Help screens for all data entry fields.

5. Cursor tracking on all frequency domain plots. X and Y coordinates read out
automatically as the cursor is tracked on the function by holding the mouse button
down and dragging across the window as desired.

6. Graphical Zooming is available.

Page 1 - 4 dsPIC Filter Design Reference Guide


1.3 Installation

1.3.1 Application Software Installation

The system is automatically installed by executing the following command at the DOS
prompt or the run dialog.

For dsPICFD:
<drive>:\dsPICFD.msi

For dsPICFDLite:
<drive>:\dsPICFDLite.msi

Note: this executes SETUP.EXE on the cd which decompresses the files and installs the
software group.

dsPIC Filter Design Reference Guide Page 1 - 5


1.4 Input Specifications

The magnitude specification of the passband of a filter is given in the form


-20log10(1.0-δ1)

This assumes the magnitude range of the passband is from [1-δ1,1], δ1>0 and δ1<1

Stopband specifications are given in the form


-20log10(δ2)

Thus the magnitude of the stopband is from [0, δ2] and δ2<1

Note that: -20log10(1.0-δ1) and -20log10(δ2) are positive numbers. These values are often
referred to as passband ripple and stopband ripple, but a more accurate description would
be maximum passband attenuation and minimum stopband attenuation.

These forms are used throughout all IIR and FIR designs for Lowpass, Highpass,
Bandpass and Bandstop Filters.

1.0

1-δ1

δ2

Frequency

All IIR and FIR filters have their stopband and passband filters specified in this manner.
There are no unique specifications for each filter type. Such transformations if required
for design calculators are all handled automatically by the design program.

Note that the definitions of the passband and stopband values are positive numbers.
Furthermore -20log10(1.0-δ1) < -20log10(δ2) .

Page 1 - 6 dsPIC Filter Design Reference Guide


1.5 Design Methods

For the IIR design, a normalized lowpass analog transfer function is generated based on
the given filter specifications. This normalized lowpass analog transfer function is then
transformed to an unnormalized analog transfer function (lowpass,highpass,bandpass or
bandstop) via the analog frequency transformation formulae. Values for the frequency
transformation are suitably chosen to compensate for the prewarping caused by the
subsequent bilinear transformation.

The unnormalized transfer functions for Lowpass, Highpass, Bandpass and Bandstop
Filters are then transformed to the digital domain via the bilinear transformation. Details
of the transformations are printed in the output file SFIL.OUT. Output for each design
will be accumulated in this file until it is printed. The filter characteristics including the
impulse response are simulated via cascaded second order sections with the poles and
zeros grouped using the L. B. Jackson algorithm1 to minimize stability problems.

For the FIR design with windows, the number of taps in the filter are determined using
the window calculation, again based on input specifications. The coefficients for the taps
are then determined by using the Fourier series design techniques for computing the
impulse response and the window coefficients.

The Equiripple FIR design uses the Remez2 exchange algorithm to determine an optimal
solution. The solution is optimal in the minimax sense - that is the maximum error over
the entire frequency band is minimized. This produces equiripple results in both the
passband and stopband.

1. Jackson, L. B. Digital Filters and Signal Processing - see Addendum (8)


2. Jackson, L. B. Digital Filters and Signal Processing - see Addendum (8)

dsPIC Filter Design Reference Guide Page 1 - 7


1.6 System Operation

The dsPICFD system was designed to be intuitively easy to use without sacrificing any
of the powerful design capabilities required for a sophisticated engineering application.
The top menu bar provides all the necessary options to design filters and will save
previously inputted data thus allowing specifications to be changed with the minimum of
effort. To alter a field, simply move the cursor into the relevant field using the mouse or
Enter keys and re-enter the desired data.

The menus and dialogs are largely self-explanatory, thus allowing the system to be used
with the minimum of difficulty. The user merely selects the desired option/s by following
the menu and dialog prompts. All dialog boxes have a cancel box which will cause the
system to revert to the previous dialog box.

It is not necessary to input data in floating point format as the system will automatically
convert integers to the correct format. For example, 5000, 5000.0, and 5E03 are all equally
acceptable forms of input.

To start the system: Double-click on the dsPICFD icon to launch the system or enter the
following command:
<drive:><\path\>dsPICFD.exe

or for dsPICFDlite use:


<drive:><\path\>dsPICFDlite.exe

Page 1 - 8 dsPIC Filter Design Reference Guide


CHAPTE R 2 dsPIC Filter Design
Examples

The authors of dsPICFD believe that the most efficient way to become familiar with the
implementation and potential of the system is to step through the examples provided. The
following pages contain examples of the various design methods and are organized in the
following manner:

DESIGN METHOD and PROBLEM STATEMENT TOGETHER WITH INPUT,


OUTPUTS are SFIL.OUT (Analysis provided with each design) and PLOTS.

The examples implemented are:

TABLE 2-1 Example Listing

Example Filter Type


1 IIR Lowpass (Tschebyscheff)
2 IIR Bandpass (Elliptic)
3 FIR Lowpass (Kaiser)
4 Equiripple FIR (Lowpass)

dsPIC Filter Design Reference Guide Page 2 - 1


2.1 IIR Lowpass

The first example is an IIR design with an inverse Tschebyscheff analog prototype.

FIGURE 2-1 Lowpass Filter Specifications

The frequencies are specified in Hertz. The sampling frequency is set at 5000 Hz, the
passband frequency is set at 800Hz and the stopband frequency is set to 1600 Hz. Note
that for a lowpass filter the stopband frequency must be greater than the passband
frequency and both frequencies must be less than half the sampling frequency.

Both the passband and the stopband ripples are specified in dB (see Section 1.4 ). The
ripple values are all specified as positive values. The passband value must be < the
stopband value. Typical passband values are 0.1 to 3 dB. Typical stopband values are
40dB or greater.

Page 2 - 2 dsPIC Filter Design Reference Guide


FIGURE 2-2 Select Analog Prototype and Filter Order

Inverse Tschebyscheff is selected for the analog prototype. The filter order will default
to 5 unless overridden in this dialog box.

dsPIC Filter Design Reference Guide Page 2 - 3


FIGURE 2-3 System Responses for Example 1

Some interesting things to note about this filter design - the zeros on the unit circle
correspond to the frquencies in the log frequency plot where the response has a null .xxxx

Page 2 - 4 dsPIC Filter Design Reference Guide


2.2 IIR Bandpass
This example is an IIR bandpass filter with an Elliptic Analog prototype. Since this is a
bandpass filter, there are two passband frequencies. The passband frequencies must be
contained within the two stopband frequencies. This is explained in detail in the HELP
menu.

FIGURE 2-4 Bandpass Filter Specifications

This filter has relatively narrow transition bands. The Elliptic filter design method will
be significantly more efficient than other analog prototypes. In general, unless one has
a specific reason for picking a different analog prototype, the Ellliptic filer prototype s
hould be used for IIR filter design.

FIGURE 2-5 Select Analog Prototype and Filter Order

dsPIC Filter Design Reference Guide Page 2 - 5


The elliptic filter design is selected and the default filter order of 8 is also selected.

FIGURE 2-6 System Responses for Example 2

Note that there are ripples in both the passband and the stopband. This is characteristic
of all IIR filters that are generated using the elliptical design

Page 2 - 6 dsPIC Filter Design Reference Guide


2.3 FIR Lowpass
The same lowpass filter specifications as in Example 1 are used for this FIR lowpass fil-
ter.

FIGURE 2-7 Lowpass Filter Specifications

Several window functions are available for FIR design. However, the Kaiser window
function is usually selected for this type of design.

The frequencies are specified in Hertz. The sampling frequency is set at 5000 Hz, the
passband frequency is set at 800Hz and the stopband frequency is set to 1600 Hz. Note
that for a lowpass filter the stopband frequency must be greater than the passband
frequency and both frequencies must be less than half the sampling frequency.

Both the passband and the stopband ripples are specified in dB (see Section 1.4 ). The
ripple values are all specified as positive values. The passband value must be < the
stopband value. Typical passband values are 0.1 to 3 dB. Typical stopband values are
40dB or greater.

dsPIC Filter Design Reference Guide Page 2 - 7


FIGURE 2-8 Select Window Function and Filter Order

The Kaiser window design is selected with a default order of 19. It appears from the filter
orders that a rectangular window would be better. However, a rectangular window will
not provide a design where the first sidelobe of the stopband will be less than 45 dB.

Page 2 - 8 dsPIC Filter Design Reference Guide


FIGURE 2-9 System Responses for Example 3

An FIR filter has ripples in both the passband and stopband. The ripples in the stopband
are easily seen in the magnitude plot. The ripples in the passband can be seen by zooming
in on the passband portion of the log magnitude or magnitude plot.

Also note that the phase plot is essentially a straight line and the group delay is a constant.
Both of these phenomena are characteristic of an FIR design with symmetric or anti-
symmetric coeeficients. If an FIR filter does not have symmetric or anti-symmetric
coefficients, then the group delay is not a constant.

dsPIC Filter Design Reference Guide Page 2 - 9


2.4 Equiripple FIR Lowpass

The same lowpass filter specifications as in Examples 1 and 3 are used for this FIR lowpass
filter

FIGURE 2-10 Lowpass Filter Specifications

The Equiripple design can make use of both ripple values in the design of the filter whereas
the FIR design with windows cannot. The FIR design with windows uses the only one
ripple value and will over design the other ripple value. The FIR design uses the smallest
ripple value. This is almost always the stopband ripple. Hence, the FIR design with
windows cannot be as efficient as the equiripple deisgn.

FIGURE 2-11 Select Filter Order

Note that the filter order is 11 - much less than the Kaiser window design.

Page 2 - 10 dsPIC Filter Design Reference Guide


FIGURE 2-12 System Responses for Example 4

The magnitude plot for this design is considerably different than the magnitude plot for
the Kaiser window design. The equiripple design makes use of the two ripple values and
thus requires fewer taps or coefficients to achieve the desired design specifications.

An FIR window design has only one ripple value for its design calculations. The smallest
ripple value will be used for the design calculation - usually this is the stopband ripple
value - hence the filter is over-designed in the passband. What that means is that the
passband ripple is smaller than requested by the user.

dsPIC Filter Design Reference Guide Page 2 - 11


2.5 Using a dsPICfd Filter in dsPICworks

A filter can be exported for use in dsPICworks.

Just create an FLT file. Then select said file when applying a filter in dsPICworks.

Page 2 - 12 dsPIC Filter Design Reference Guide


CHAPTE R 3 System Operation

System operation is controlled via the standard graphical user interface of a main menu
bar with pull-down menus and dialog boxes. The main menu bar consists of the following
entries:

TABLE 3-1 Main Menu Bar

Selection Description
File Allows loading of previously stored filter and analysis input
specifications
View View the design data and filter files
Design Selection of Filter Design Options
Filter Selection of Filter Types
Output Selects plotting options and output files
Codegen Generates dsPIC assembly code
Window Standard Windows Operations to select output and graphical
options

dsPIC Filter Design Reference Guide Page 3 - 1


After the system has been started, the following screen will be displayed:

FIGURE 3-1 Start-Up Screen

The FILE, VIEW, DESIGN, FILTER, OUTPUT, CODEGEN and WINDOW menu items
are covered in this chapter.

Page 3 - 2 dsPIC Filter Design Reference Guide


3.1 Toolbar

The toolbar allows the user to select the most commonly used features by button.

The toolbar appears as follows:

FIGURE 3-2 Toolbar buttons

The buttons and equivalent Menu options are detailed below in the order in which they
appear on the toolbar.

Load Files

FILE/Load Filter Specification File

About/Printer Options

FILE/About,
FILE/Printer

Plot Display Options

WINDOW/Cascade,
WINDOW/Tile

Design Type Options

DESIGN/IIR,
DESIGN/FIR,
DESIGN/Equiripple

dsPIC Filter Design Reference Guide Page 3 - 3


Filter Types

FILTER/Lowpass,
FILTER/Highpass,
FILTER/Bandpass,
FILTER/Bandstop

Quantization Option

OUTPUT/Quantization

Start Design

FILTER/Start Design

Output Options

OUTPUT/Create Filter Specification File,


OUTPUT/Create Filter Coefficient File
OUTPUT/Create C Code File.

Page 3 - 4 dsPIC Filter Design Reference Guide


3.1.1 Status Bar

FIGURE 3-3 Status Bar Display

The Status Bar which appears at the bottom of the screen displays the following
information:

Status

Snap to Grid On/Off

Q16 - Resolution

dsPIC Filter Design Reference Guide Page 3 - 5


3.2 File Menu

Select the file menu by placing the cursor over the word FILE, click and hold the selection
by moving the cursor to the appropriate item in the drop-down menu, prior to releasing
the mouse button. Note that the enabled options are listed in black with disabled options
appearing in gray. The FILE menu appears as follows:

FIGURE 3-4 File Menu

Certainly the most powerful feature of this menu is the ability to automatically load
previously stored specifications via FILE/Load Specifications.

Page 3 - 6 dsPIC Filter Design Reference Guide


3.2.1 Load Specification File

If the FILE/Load Specifications option was selected, the following dialog box will be
displayed.

FIGURE 3-5 Filter Specification File Selection

All filter specification files suffixed by .SPC will be displayed. A filter specification file
can be created by selecting OUTPUT/Create Specification File after a filter design is
complete. The dialog box corresponding to the current design method will be started
automatically after a specification file is selected. If necessary, the design method will be
changed to a method that can design the filter.

dsPIC Filter Design Reference Guide Page 3 - 7


3.2.2 Print

On completion of a filter design, filter plots can be printed. The print menu does not apply
to text windows. Text files must be printed outside of QED Lite.

FIGURE 3-6 Print Selection

Note: hardcopy plots are always printed in black and white.

3.2.3 Printer Setup

Select the desired printer setup. Note these parameters are not saved after the system exits.

Page 3 - 8 dsPIC Filter Design Reference Guide


FIGURE 3-7 Printer Selection

The printer setup box will vary according to the type of printer.

3.2.4 System Settings

The system settings dialog box controls global aspects of dsPIC FD operations.

FIGURE 3-8 System Setting Options

dsPIC Filter Design Reference Guide Page 3 - 9


• Exit Mode: These options determine what information is retained on exiting the
application.
• Open a view window when a text file is created: If this option is selected, a View
window is opened with the contents of the text file. This applies to all output files.

3.2.5 User Information

The text in the User Information will be displayed on the graphical displays and printouts.

FIGURE 3-9 User Information Screen

3.2.6 Exit

Exits the application.

Page 3 - 10 dsPIC Filter Design Reference Guide


3.2.7 About dsPIC™ FD Filter Design

Displays the current version number and technical support information. Technical support
is available for customers subscribing to maintenance contracts - please contact our sales
department for further information.

FIGURE 3-10 About Screen

dsPIC Filter Design Reference Guide Page 3 - 11


3.3 View Menu
The items for this menu are shown as follows:

FIGURE 3-11 View Menu Items

3.3.1 Toolbar

This option toggles the Toolbar display on and off.

3.3.2 Status Bar

This option toggles the Status Bar display on and off.

Page 3 - 12 dsPIC Filter Design Reference Guide


3.3.3 Text Filter File View

All files can be read in text format. Simply select the file type by scrolling through the
available file types. Text files cannot be printed within dsPIC FD.

FIGURE 3-12 Text Display

dsPIC Filter Design Reference Guide Page 3 - 13


3.4 Design Menu
This section describes the filter design capabilities of the system.
• Infinite Impulse Response (IIR) Design
• Finite Impulse Response (FIR) Design
• Equiripple FIR Design

The following menu is the primary means of starting the design of digital filters.

FIGURE 3-13 Design Menu

The various design methods and filter types will be discussed in some detail although, it
should be noted, that some filter types are specific to a particular design method.

An output file (SFIL.OUT) is automatically created showing detailed calculations for the
designs.

Page 3 - 14 dsPIC Filter Design Reference Guide


3.4.1 IIR Design

Selects the system design method to Infinite Impulse Response (IIR) design. IIR designs
all have feedback loops in the difference equations that implement the filters - that is the
output value in a linear function of previous output values as well as current and previous
input values. IIR designs are classical filter designs using analog design methods which
transform the resulting S domain filter to a Z domain filter.

FIGURE 3-14 IIR Design Options

Filter Type

IIR designs for Lowpass, Highpass, Bandpass and Bandstop filters all use analog
prototypes. After selecting “Next” on the IIR Design Menu the following dialog box will
be displayed.

FIGURE 3-15 Estimated Filter Order/Analog Type

dsPIC Filter Design Reference Guide Page 3 - 15


The estimated orders for the five types of analog filters are displayed. In selecting a filter
type, one should bear in mind certain salient characteristics of these analog filters. The
Butterworth filter is maximally flat in the passband and exhibits no ripples in either the
passband or the stopband. The Tschebyscheff and Inverse Tschebyscheff exhibit a more
rapid cutoff than the Butterworth filter, but at the expense of ripples in either the passband
or the stopband. The Tschebyscheff filter has its ripples in the passband whereas the
Inverse Tschebyscheff filter has its ripples in the stopband. The Elliptic filter has the
sharpest cutoff from the passband to the stopband, but has ripples in both the stopband
and the passband and has a higher nonlinearity in its phase response. These characteristics
carry over to the digital form of the transfer function. The Bessel filter order is estimated
using the Butterworth order calculation. This order is probably optimistic and some fine
tuning is required. The Bessel filter does not have as sharp a roll-off as the Butterworth
filter.

The desired order is an optional field. If nothing is specified, then the order associated
with the selected analog filter type is used. The desired order field can be any positive
integer (must be a multiple of 2 for bandstop or bandpass filters) and is not restricted to
merely incrementing the filter order.

Page 3 - 16 dsPIC Filter Design Reference Guide


3.4.2 FIR Design with Windows

Sets the system design method to Finite Impulse Response (FIR) Windows design. FIR
designs produce a filter in which difference equations do not have feedback loops - that
is, the output value is a function only of current and previous input values. Previous output
values are not part of these filter calculations. The Windows type of FIR design is done
by forming a truncated Fourier Series to represent the desired frequency response and
'windowing' or multiplying the resulting coefficients element by element with a window
function to reduce the Gibbs effect of truncating the Fourier series. The dsPIC FD system
sets the filter coefficient symmetries such that all FIR filters have linear phase.

FIGURE 3-16 FIR Design Menu

The system allows the specification of both the baseband ripple and the stopband ripple
for filters. However, for window designs, the system selects the minimum ripple (smallest
in linear sense) and uses that value for both the stopband and passband ripples. This
restriction is an inherent mathematical restriction of the FIR window design.
Select Window Function and Filter Order

After the system accepts specifications for either Lowpass, Highpass, Bandpass, or
Bandstop, a dialog box similar to the following dialog box is displayed with the estimated
order for each of the supported window functions.
The dsPIC FD system defaults to the Kaiser Window.

The desired filter length is optional --if left blank the system will set the number of taps
equal to the estimate. The estimate can be overridden by any value from 2 to 513.

dsPIC Filter Design Reference Guide Page 3 - 17


FIGURE 3-17 Select Window Function

In selecting a window function for a filter, the number of taps cannot be used as a sole
decision factor. Most of the Windows have a fixed falloff to the first sidelobe of the
stopband - this value is the stopband attenuation in the following table:

Page 3 - 18 dsPIC Filter Design Reference Guide


TABLE 3-2 Window Function Limitations

Window Function Sidelobe Peak Stopband Asymptotic


(dB) Attenuation (dB) Decay dB/Octave
Rectangular -13.37 20.96 -6
Triangular -27.31 25.70 -12
Hanning -31.47 43.94 -18
Hamming -43.19 54.17 -6
Blackman -58.11 75.29 -18
Exact Blackman -68.20 85.57 -6
3 Term Cosine -62.05 79.16 -6
3 Term Cosine with Continuous -46.74 61.36 -30
3rd Derivative
Minimum 3 Term Cosine -71.48 86.40 -6
4 Term Cosine -74.39 87.78 -6
4 Term Cosine with Continuous -60.95 77.03 -42
5th Derivative
Minimum 4 Term Cosine -98.17 115.55 -6
Harris Flat Top -80.05 97.03 -6
Good 4 Term Blackman Harris -81.76 99.78 -6
Kaiser Selectable -6
Dolph-Tschebyscheff Selectable 0
Selectable
Taylor 0
Selectable
Gaussian -6

For the Windows with fixed stopband attenuation longer filter lengths reduces the
transition bandwidth. The rectangular window is essentially no windowing and illustrates
the Gibbs effect on truncating a Fourier series. Windows marked as ‘Selectable’ allow
variable falloff to the main sidelobe and variable transition bands.

dsPIC Filter Design Reference Guide Page 3 - 19


3.4.3 Equiripple FIR Design

Selecting this menu item will set the system design method to Equiripple FIR design.
This method is also known as the Parks-McClellan algorithm.

FIGURE 3-18 Equiripple FIR Design Menu

The following design box will be displayed during the design calculations for Lowpass,
Highpass, Bandpass, and Bandstop filter designs. The estimated number of taps will be
accepted as a default if a desired number of taps is not entered.

FIGURE 3-19 Design Options

The number of taps for Equiripple designs can be any number from 3 to 513.
Equiripple FIR Filter Design Limitations

System specifications in Equiripple design may not be met for a variety of reasons. The
algorithm appears to terminate normally in these cases, but the results do not give the
desired results. Typically the gain will exceed 1.0 even though this is the expected
maximum gain.

If the detailed magnitude and log magnitude report was requested, the values can be
examined to see how far from the desired value the computations are.

Page 3 - 20 dsPIC Filter Design Reference Guide


Errors of this nature are usually caused by one of the following factors:

1. Transition band too narrow

2. Very narrow passbands

3. Very narrow stopbands

dsPIC Filter Design Reference Guide Page 3 - 21


3.5 Filter Menu
The following table displays the various type of filters and available design methods:

TABLE 3-3 Filter Types

Filter Type IIR Design FIR Design


Lowpass 9 9
Highpass 9 9
Bandpass 9 9
Bandstop 9 9

FIGURE 3-20 Filter Menu

Page 3 - 22 dsPIC Filter Design Reference Guide


3.5.1 Lowpass

The following dialog box appears if Lowpass was selected from the DESIGN menu or
FILTER/Lowpass was selected. All fields are mandatory and a valid entry must be in
each of them. Frequencies are in Hertz. The stopband and passband frequencies must be
less than the sampling frequency/2.

FIGURE 3-21 Lowpass Filter Input Screen

The passband frequency of a lowpass filter must be less than the stopband frequency. The
attenuation or ripple of the stopband and passband is expressed in dB. While both the
passband ripple and the stopband ripple are required, the filter order and results are
determined using the stopband ripple only for FIR design with Windows. Both fields are
required in case this specification is used in either an IIR design or an FIR Equiripple
(Parks-McClellan) design. A typical range of values for passband ripple or attenuation is
0.01dB to 3dB. A typical range of values for stopband ripple is 20dB to 100dB. The
passband ripple must be less than the stopband ripple.

dsPIC Filter Design Reference Guide Page 3 - 23


3.5.2 Highpass

The following dialog box appears if Highpass was selected from the DESIGN menu or
FILTER/Highpass was selected. The passband frequency must be greater than the
stopband frequency. Both the stopband frequency and the passband frequency must be
less than the sampling frequency/2. The passband ripple or attenuation must be less than
the stopband ripple. Typical values for passband ripples range from .01dB to 3dB while
typical values for the stopband ripple range from 20dB to 100dB.

Furthermore, the passband frequency of a highpass filter must be greater than the stopband
frequency. The attenuation or ripple of the stopband and passband is expressed in dB.
While both the passband ripple and the stopband ripple are required, the filter order and
results are determined using the stopband ripple only for FIR design with Windows. Both
fields are required in case this specification is used in either an IIR design or an FIR
Equiripple (Parks-McClellan) design. A typical range of values for passband ripple or
attenuation is 0.01dB to 3dB. A typical range of values for the stopband ripple is 20dB
to 100dB.

FIGURE 3-22 Highpass Filter Input Screen

Page 3 - 24 dsPIC Filter Design Reference Guide


3.5.3 Bandpass

The following dialog box appears if a bandpass filter was selected. There are two
frequencies for the passband and two frequencies for the stopband. All frequencies must
be less than the sampling frequency/2. The first passband frequency must be less than the
second passband frequency and the first passband frequency must be greater than the first
stopband frequency. Similarly, the second passband frequency must be less than the
second stopband frequency.

While both the passband ripple and the stopband ripple are required, the filter order is
determined for FIR design with Windows using the stopband ripple only. Both fields are
required in case this specification is used in either an IIR design or an FIR Equiripple
(Parks-McClellan) design. For an Equiripple design, the transition regions are set inter-
nally such that the transition regions are symmetric. This is required to design an
acceptable equiripple bandpass filter.

FIGURE 3-23 Bandpass Filter

dsPIC Filter Design Reference Guide Page 3 - 25


3.5.4 Bandstop

The following dialog box appears if a Bandstop filter was selected on the DESIGN menu
or FILTER/Bandstop was selected. This dialog box is virtually identical to the Bandpass
dialog box. However, different design rules apply
• The first passband frequency must be less than the second passband frequency and
the first stopband frequency must be less than the second stopband frequency.
• The first passband frequency must be less than the first stopband frequency and the
second stopband frequency must be less than the second passband frequency.

While both the passband ripple and the stopband ripple are required, the filter order and
results are determined using the stopband ripple only for FIR design with Windows. Both
fields are required in case this specification is used in either an IIR design or an FIR
Equiripple (Parks-McClellan) design.

FIGURE 3-24 Bandstop Filter

Page 3 - 26 dsPIC Filter Design Reference Guide


3.6 Output Menu

The OUTPUT menu contains a variety of options related to data output - graphical,
hardcopy, or data files.

FIGURE 3-25 Output Menu

3.6.1 Plot Control

Selecting OUTPUT/ Plot Control causes the following dialog box to be displayed:

dsPIC Filter Design Reference Guide Page 3 - 27


FIGURE 3-26 Plot Parameter Screen

The Plot control dialog box allows the plotting limits to be changed for a specific filter .

All of the Check Box options are global system settings. This means that the option once
set will remain in effect until explicitly reset via this dialog box.

The settings are not activated until the next replot. This means, for example, that to see
the change from linear frequency scale to log frequency scale, the ‘Accept’ button must
be selected to force a replot.
• Frequency Range
The system defaults to a range of [0,fs/2] where fs is the sampling frequency. The
purpose of the frequency selection is to allow one to narrow in on a transition area
from passband to stopband. However, it is not restricted to this. One can demon-
strate the periodicity of the magnitude and phase response by specifying a range that
is greater than [0,fs].
• Magnitude Range
The standard range of values for the magnitude plot is from zero to one. However,
this can be changed to any value between 0 and 10. Typically this can be used to
look at the passband ripple characteristics or the stopband ripple.
• Log Magnitude Range
The standard range of values for the Log Magnitude plot is -100 dB to 0 dB and
these can be changed to any values between -200dB and +10dB.
• Number of Time Steps
For the IIR design, the system by default will compute the impulse response and step
response for 300 time steps. This can be overridden by entering a different number

Page 3 - 28 dsPIC Filter Design Reference Guide


in the field designated “# Time Steps”. A maximum value of 32,000 time steps is
allowed. However, computing 32,000 time steps may take as much as five minutes
to compute depending on the speed of the computer.
• Log Frequency Scale
To select logarithmic frequency scale, place a check mark in this box. The default
number of decades for a log frequency plot is 5. The lower limit of the frequency
range will be reset to reflect the 5 decade range. Smaller ranges or different ranges
can be selected by specifically setting frequency range values.
• Grid Lines on Plots
Grid lines will appear on all plots if selected, otherwise only tick marks on the axes
will be available.
• Sinc Interpolation
If this option is on a sin x/x interpolator is used to calculate the impulse and step
responses of FIR filters with lengths < 100. For short filters and anti-symmetric fil-
ters, this will make significant difference in the plots. Note: the sinc interpolation
essentially simulates the effect of a D to A converter.
• Compute Pole/Zero Locations
The 'Compute Pole and Zero Locations' option applies only to system analysis.
Clearing this option will turn the calculation of poles and zeros for the ratio of poly-
nomials input off. This should be done if the root finder fails when trying to find
roots of a high order polynomial.
• Add Detailed Plot Values to Output
Detailed reports are also available for Magnitude, Log10 Magnitude, Phase and
Group Delay graphs. These reports are the values used in the plots and are appended
to the file named SFIL.OUT if this entry is selected.
• Change Plotting Ranges Automatically
When this option is selected, the plotting ranges will automatically be set to the fol-
lowing values whenever the problem is changed:

TABLE 3-4 Plot Ranges

Option Range
Frequency 0 to fs/2
Magnitude 0 to 1
Log Magnitude -100 to 0
Number of time steps 300

If the design has been completed and just the plotting ranges are to be changed, then
changes in these values will be reflected in the plots after selecting the done button.
If the option is deselected then the values in the plotting ranges will be used for all
subsequent plots even if the problem is changed. This allows fixed plotting ranges
independent of problem definition.

dsPIC Filter Design Reference Guide Page 3 - 29


3.6.2 Snap to Grid

This feature allows the user to snap plots to a grid.

Zooms are achieved by clicking with the right mouse button and then dragging the mouse
to form a rectangle. Releasing the right button will cause the plot to be zoomed to that
rectangle.

If the Snap To Grid option is on, the largest rectangle formed by the gridlines which
completely encloses the rectangle drawn by dragging the mouse, will be the new plot
values.

3.6.3 Quantization

If OUTPUT/Quantization is selected, the following dialog box is displayed, allowing the


selection of either Transposed Canonic Second Order Sections, or Canonic Second Order
Sections.

FIGURE 3-27 Quantization Option

Number of Quantized Bits

Select either 16 or 32 bits. Setting the number of bits to 32 will force usage of the
extended precision IIR Filter. This value must be 16 for FIR filters. Note that the
extended precision IIR filter is not available in the dsPICFDlite system. If the num-
ber of bits is 32, only the canonic second order section case can be selected for real-
ization type.
Realization Type for Cascaded Sections

• Transposed Canonic Second Order Sections


This is cascaded biquad sections. For cascaded biquad sections, the poles and zeros
are paired to minimize the gain from any one section. This is done by pairing a pole
with its nearest zero. The sections are then ordered by the radius of the poles with
the smallest radius first. Scaling coefficients are computed so that the maximum out-
put of any section is one in absolute value. The scaling coefficients are absorbed
into the numerator coefficients of the transfer function. This procedure produces a
final multiplier with a value of 1.0.
The difference equations for section i are:

Page 3 - 30 dsPIC Filter Design Reference Guide


(n)
y---------- b i0 w i1 ( n – 1 )
k
= -----k- x ( n ) + ------------------------
k
-
2 2 2

w i1 ( n ) b a i1 w i2 ( n – 1 )
k
- = -----i1k- x ( n ) + ------
--------------- k
y ( n ) + ------------------------
k
- (EQ 1)
2 2 2 2

w i2 ( n ) b a i2
- = -----i2- x ( n ) + ------
--------------- y(n)
k k k
2 2 2
The input to the section is x(n) and the output of the section is y(n)
The output of section i is the input of section i + 1
i.e. the y(n) of section i is the x(n) of section i+1
• Canonic Second Order Sections
Cascaded canonic sections requires scaling down the input signal to the first section.
This is due to the feedback in the first summing node. This form of the difference
equations results in a simpler implementation. However, scaling down the input
reduces the Signal to Noise Ratio. Unless the number of clock cycles is an important
issue, it is recommended that transpose canonic sections be used.
The difference equations for section i are:

wi ( n ) ( n ) ------
a a i2
- = x----------
------------ + i1k w i ( n – 1 ) + ------ w (n – 2)
k k k i
2 2 2 2
y(n) b i0 b i1 b i2
----------
k
= ------ w ( n ) + ------k w i ( n – 1 ) + ------k w i ( n – 2 )
k i
(EQ 2)
2 2 2 2

3.6.4 Create Specification File

The dsPICFD system allows a filter specification to be saved in a file. If this option is
selected, a subsequent dialog box will request the file name. The file will be created with
an SPC suffix.

dsPIC Filter Design Reference Guide Page 3 - 31


FIGURE 3-28 Filter Specification File

3.6.5 Create Filter Coefficient File

FIGURE 3-29 Filter Coefficient File

The dsPIC FD system allows filter coefficients to be saved in a file. If this option is
selected, a subsequent dialog box will request the file name. The file will be created with
an FLT suffix.

This file is only used for applying a filter created in dsPICworks. It is not necessary to
understand the details of this file in using the dsPIC FD design program. Please refer to
Chapter 4 for detailed information on the Filter Coefficients.

Page 3 - 32 dsPIC Filter Design Reference Guide


3.6.6 Create Plot Data Files

The data which generates the current plots can be written to a set of files. This allows
processing in other visualization or computational applications. All files will have the
same prefix with differing suffixes.

FIGURE 3-30 Plot Data Files

dsPIC Filter Design Reference Guide Page 3 - 33


3.7 Code Generation Menu

There are two Code Generation options - generating C Code or Microchip’s dsPIC
assembly language code.

FIGURE 3-31 Code Generation Menu

Page 3 - 34 dsPIC Filter Design Reference Guide


3.7.1 Create C Code

Creates optimized C Code based on the user’s designs to a specified file.

3.7.2 C Code File Generation

C Code can be created for any filter. A fully documented C program which can be used
as either a subroutine or main program is generated. This C program uses two include
files: qed_filt.c and qed_cgen.h. The filter routines are in qed_filt.c and the function
prototypes and structure definitions are defined in qed_cgen.h.

The generated C code is most appropriately used in a floating point DSP or a personal
computer.

3.7.3 Microchip dsPIC30F/33F Code Generation

The dsPIC FD system supports optimized assembly language code generation specifically
for Microchip’s dsPIC30F/33F processor. Select thedsPIC30F/33F option as shown
below.

FIGURE 3-32 Code Generation options

dsPIC Filter Design Reference Guide Page 3 - 35


The dsPIC30 FD code generator always creates an assembler file where the filename is
specified by the user in the file save dialog box.

This assembly file contains the assembly definition of the filter structure, the filter
coefficients and a code fragment showing how to call the generalized filter routine.
Assuming that the name entered in the file save dialog is <FilterName>, the generated
assembly file is <FilterName>.s".

The "Use General Subroutine" radio button specifies that the filter source routine to be
used is one of the following:
• FIR_Filter.s (Used in the case of FIR Filters)
• IIRT_Filter.s (Used in the case of Transposed IIR Filters)
• IIRC_Filter.s (used in the case of Canonic IIR Filters)
• IIRC_FilterExtendedPrecision.s (used in the case of Extended Precision IIR Filters)

These general routines reside in the dsPICFD setup folder depending on the filter type
chosen (FIR, IIR Transpose, IIR Canonic or IIR Canonic Extended Precision). The
respective general subroutine along with the generated <FilterName>.s assembly file
must be added to the MPLAB Integrated Development Environment (IDE) project. The
general subroutines will use the filter structure and filter coefficients present in the
generated FilterName.s file as inputs.

The C support files option allows creation of a C header file: <FilterName>.h. This file
is automatically created if the C wrapper option is selected for simulation of the filter.

Coefficients can be placed in X space or program space. Coefficients cannot be placed in


Y space. The coefficient space selection is used to indicate where the coefficients need
to be stored. The generated assembly code structure for the filter has the information on
whether X space or program space is used for coefficients.
Optional Files:

• C Header File: FilterName.h


This file creates the external reference from C to the assembly language filter struc-
ture for the specified filter. It also has a sample code fragment showing how to call
the generalized filter routine.
• C Wrapper: FilterName_sim_c
Use the C30 compiler to build the C program to execute the filter. The program can
be executed using the simulator option of MPLAB. Executing the main program will
result in a file named:
<filter_name>_impresponse.dat.
This file can be imported into dsPICworks and then a FFT can be performed on the
imported file to get a log magnitude display (BODE plot) of the impulse response.

Page 3 - 36 dsPIC Filter Design Reference Guide


The following dialog box is displayed after the code generation option dialog box is
displayed. This dialog sets the base file name that is used to create all of the generated files.

FIGURE 3-33 Save dsPIC30/33 code

dsPIC Filter Design Reference Guide Page 3 - 37


The following is an example of a sample code generated for a transposed IIR Filter. Note
that the text contained at the bottom of the generated assembly file shows how to use the
filter in assembly language.

FIGURE 3-34 Sample Code


; File TestCG.s
.equ TestCGNumSections, 2
; Allocate and initialize filter coefficients
; These coefficients have been designed for use in the Transpose filter only
.section .xdata,data,xmemory
TestCGCoefs:
.hword 0x052C ; b( 1,0)/2
.hword 0x0783 ; b( 1,1)/2
.hword 0x44B5 ; a( 1,1)/2
.hword 0x052C ; b( 1,2)/2
.hword 0xE96F ; a( 1,2)/2
.hword 0x1277 ; b( 2,0)/2
.hword 0x02AC ; b( 2,1)/2
.hword 0x46C9 ; a( 2,1)/2
.hword 0x1277 ; b( 2,2)/2
.hword 0xD11A ; a( 2,2)/2
; ..............................................................................

; Allocate states buffers in (uninitialized) Y data space

.section .ybss, bss, ymemory


TestCGStates1:
.space TestCGNumSections*2
TestCGStates2:
.space TestCGNumSections*2
; ..............................................................................
; Allocate and intialize filter structure
.section .data
.global _TestCGFilter
_TestCGFilter:

.hword TestCGNumSections-1
.hword TestCGCoefs
.hword 0xFF00
.hword TestCGStates1
.hword TestCGStates2
.hword 0x0000
; ..............................................................................
; Sample assembly language calling program
; The following declarations can be cut and pasted as needed into a program
; .extern _IIRTransposedInit
; .extern _IIRTransposed
; .extern _TestCGFilter
; .section .bss

; The input and output buffers can be made any desired size
; the value 40 is just an example - however, one must ensure
; that the output buffer is at least as long as the number of samples
; to be filtered (parameter 1)
;input: .space 40
;output: .space 40
; .text
;; This code can be copied and pasted as needed into a program
Set up pointers to access input samples, filter taps, delay line and
; output samples.
; mov #_TestCGFilter, W0; Initalize W0 to filter structure
; call _IIRTransposedInit; call this function once
;
; The next 4 instructions are required prior to each subroutine call
to _IIRTransposed
; mov #_TestCGFilter, W3; Initalize W3 to filter structure
; mov #input, W2; Initalize W2 to input buffer
; mov #output, W1; Initalize W1 to output buffer
; mov #20, W0 ; Initialize W0 with number of required output samples
; call _IIRTransposed; call as many times as needed

Page 3 - 38 dsPIC Filter Design Reference Guide


There are four filter routines and four initialization routines. These routine names are
shown on the following table:

TABLE 3-5 Table of Filter Routine Names

File Name Filter type Filter Routine Name Input Routine Name # Bits/Coefficientt
FIR_Filter.s FIR _FIR _FIRInit 16
IIRT_Filter.s Transposed IIR _IIRTransposed _IIR TransposedInit 16
IIRC_Filter.s Canonic IIR _IIRCanonic _IIRCanonicInit 16
IIRC_FilterExtende Canonic IIR _IIRCanonicExtend _IIRCanonicExtend 32
dPrecision.s edPrecision.s edPrecision

For the 16-bit filters, the transposed IIR routine is the preferred choice for IIR filters
(called form 1 in the quantization menu). This routine uses more instructions than the
Canonic Routine (Form 2). However, it behaves significantly better for filters where the
poles are close to the unit circle.

For the 32 bit filter coefficients, the IIRC_FilterExtendedPrecision format is automati-


cally chosen. Note that while this routine has more precision in its results, it takes
significantly more clock cycles than any 16-bit filter implementation. This filter imple-
mentation uses the same difference equations as the CanonicIIR filter. Note, this option
is not available for the dsPICFDLITE system.

These routines have the same calling sequence, filter names and structure names as the
DSP library. (See MPLAB C30 HELP File).

There are 3 likely scenarios for using the generated code from dsPICFD. These are:
1. Test the filter with an impulse response in a standalone project
2. Add the filter to an existing project with the filter routines called by C Code
3. Add the filter to an existing project with the filter routines called by asm code

For the first two cases, select the optional C Code file generation.

In the event of Case 1), create a standalone project wiht the generated files and one of the
filter files described in Table 3.5.

In the event of Case 2), just add the generated C Header file. The MPLAB plugin may
have added the main to the project. In this case, delete the main program.

For case 3, do not generate any C files. The generated asembly file can be used by
following the instructions printed in the comments at the bottom of the file.

Note that there is no library routine for the Extended Precision version of the CanonicIIR
routine. The supplied routine must be used for this capability. Also note that this capability
is not available for dsPICFdlite.

dsPIC Filter Design Reference Guide Page 3 - 39


3.8 Window Menu
The WINDOW menu allows selection and control of the graphical displays. A list of all
graphical displays are displayed at the bottom of the menu. The Cascade and Tile options
are self-explanatory.

FIGURE 3-35 Window Menu

Page 3 - 40 dsPIC Filter Design Reference Guide


3.8.1 Select Plots

Clicking the Select Plots option causes the following menu item to be displayed:

FIGURE 3-36 Plot Display Selection

Plots which have been deselected using the Cancel window button can be reselected using
this dialog box. All selected plots are indicated by a check mark.

3.8.2 Display Control

Allows the selection of color, font and line style for plots and prints (Note: hardcopy
printouts are black and white only). The following dialog boxes are provided:

dsPIC Filter Design Reference Guide Page 3 - 41


FIGURE 3-37 Color Selection

FIGURE 3-38 Font Selection

Page 3 - 42 dsPIC Filter Design Reference Guide


FILTER COEFFICIENT FILE

CHAPTE R 4 FILTER COEFFICIENT


FILE

Filter coefficient files can be generated from the design system. The filter coefficient
files contain the values of the quantized coefficients of the digital filters intended for
actual implementation of a digital filter. Each file is an ASCII file. As such, these files
can be processed by any text editor or application program.

The filter coefficient files are used as the interface file to dsPICworks. These files can be
used by dsPICworks to apply a filter designed by dsPICFD or dsPICFDlite to any time
domain signal. Alternatively, one can execute the generated C program and create a file
that can be imported into dsPICworks.

dsPIC Filter Design Reference Guide Page 4 - 1


IIR FILTER COEFFICIENT FILES FILTER COEFFICIENT FILE

4.1 IIR FILTER COEFFICIENT FILES

This supported format for IIR filter coefficient files is: Fractional fixed point - cascaded
biquad sections

The options are selected from the Quantization Option screen and the method of realiza-
tion.

Page 4 - 2 dsPIC Filter Design Reference Guide


FILTER COEFFICIENT FILE IIR FILTER COEFFICIENT FILES

4.1.1 General Discussion on Cascaded Biquad Sections

Let

N
2
b i0 z + b i1 z + b i2
H ( z ) = Hd ∏ ----------------------------------------
2
a i0 z + a i1 z + a i2
(EQ 1)

i=1

the transfer function of second order sections, where N is the number of second order
sections. H(z) can also be written as:

N
–2
b i0 + b i1 z – 1 + b i2 z
H ( z ) = Hd
∏ -----------------------------------------------
a i0 + a i1 z – 1 + a i2 z
–2
(EQ 2)

i=1

by dividing numerator and denominator by z2.

The z-1 terms represent a delay of 1 time period and the z-2 terms represent a delay of 2
time periods. The denominator coefficients have been complemented to allow adds in
the difference equation. First order sections are treated as second order sections by
multiplying both the numerator and denominator by z or in effect, setting the second order
delays to zero.

In converting from the floating point to fixed point format, the number of bits is used to
determine the number of significant positions in the fraction. Then bi0, bi1, bi2 are forced
to the same exponent value. This exponent value becomes the numerator shift count.
Similarly, ai1, ai2 are shifted until they have the same exponent value. This exponent
value becomes the denominator shift count. If a shift count is less than or equal to zero,
the number is a fraction. If the shift count is greater than zero, the absolute value of the
number is greater than 1. Coefficient ai0 is assumed to have a value of 1.0. Denominator
shift counts are normally greater than or equal to zero.

To actually implement a biquad section in a DSP microprocessor, the coefficients must


be in fractional form. The coefficients in the fixed point format record are in fractional
format even if their actual value is greater than 1. This can be visualized best by
considering the fixed point format of the coefficients to be a block floating point with the
fractional values stored in the rightmost hexadecimal digits and the shift count residing
in the shift count record. There are 8 hexadecimal digits.

If the number of quantized bits is 'n', then the fractional coefficient is in the rightmost 'n'
bits. Also note that negative numbers are represented in their 2's complement form.

To implement a biquad section, it is necessary to align the binary point of the fractional
values prior to accumulating intermediate sums. This can be done by ensuring that each
operand in a sum has the same shift count or exponent. The final output of biquad sections
should have a shift count of 0 to avoid scaling in the subsequent biquad section.

dsPIC Filter Design Reference Guide Page 4 - 3


IIR FILTER COEFFICIENT FILES FILTER COEFFICIENT FILE

Let x(n) be the input to the i'th section and y(n) be the output of the i'th section. Then the
difference equations for implementing cascaded second order sections in cascaded form
I (Transpose) are:

y ( n ) = b i0 x ( n ) + w i1 ( n – 1 )
w i1 ( n ) = b i1 x ( n ) + a i2 y ( n ) + w i2 ( n – 1 ) (EQ 3)
w i2 ( n ) = b i2 x ( n ) + a i2 y ( n )

Note: ai1 and ai2 are complemented in the coefficient file so an add is used instead of a
subtract. Hd is 1.0 for Direct Form I. .

The difference equations for cascaded second order sections in cascaded form II (Canonic)
are:

(EQ 4)

w i ( n ) = x ( n ) + a i1 w i ( n – 1 ) + a i2 w i ( n – 2 )
y ( n ) = b i0 w i ( n ) + b i1 w i ( n – 1 ) + b i2 w i ( n – 2 )

Page 4 - 4 dsPIC Filter Design Reference Guide


FILTER COEFFICIENT FILE IIR FILTER COEFFICIENT FILES

4.1.2 Fractional Fixed Point Cascaded Biquad Sections

The discussion of implementation details in Section 4.1.1 is pertinent here, with the
following exception: all coefficients except ai0 have initially been scaled so that the
absolute value of the coefficient is less than 1.0. The largest coefficient in absolute value
has the maximum precision allowed. Coefficients with smaller absolute values may have
fewer bits to represent them. If the shift count is zero then the difference equations can
be used as specified in Section 4.1.1 .

The binary points must be aligned prior to the addition of two values. This means that
shift counts must be identical for this operation. While the filter is designed so that the
final gain is 0dB or the maximum range is -1 to +1, filter coefficients can be greater than
1.0 and intermediate results can be greater than 1.0. Coefficients are divided by a power
of 2 (i.e. 21, 22, 23, etc.) until the coefficients are less than 1.0. The power of 2 is the shift
count. The numerator values have been rescaled to prevent or minimize overflow. This
rescaling is realization dependent. Thus, form I coefficients are used in
form I equations, etc. Usually, the shift count is zero or one. However, it may exceed 1
for certain values particularly if cascaded canonic form II is used.
This discussion implies using intermediate shifts for implementation of the difference
equations. This may not, however, be necessary. It depends on how the difference
equations are implemented.
Cascaded Transpose (Form I)
A positive shift count k for a section means that the difference equations for form I are
actually as follows:

y(n) b i0 w i1 ( n – 1 )
----------
k
= ------k x ( n ) + ------------------------
k
-
2 2 2
w i1 ( n ) b a i1 w i2 ( n – 1 )
- = -----i1k- x ( n ) + ------
--------------- y ( n ) + ------------------------
- (EQ 5)
k k k
2 2 2 2
w i2 ( n ) b i2 a i2
---------------
k
- = ------
k
x ( n ) + -----k- y ( n )
2 2 2

Note: y(n) is the output of section i, is x(n) the input to section i + 1; also y(n) not y(n)/
2k, is needed in the computation for section i. So the true value of y(n) is formed by a
left shift of k bits and this value is used for the y(n) computations as well as for input to
the next section as x(n). The ai1 and ai2 have been complemented in the FLT file so an
add instead of a subtract is used. Hd, the overall gain, is normally 1.0 and can, therefore,
be ignored.

dsPIC Filter Design Reference Guide Page 4 - 5


IIR FILTER COEFFICIENT FILES FILTER COEFFICIENT FILE

Cascaded Canonic (Form II)


The difference equations for form II are:

wi ( n ) x(n) a a i2
------------- = ---------- + -----i1- w i ( n – 1 ) + ------ w (n – 2)
k k k k i
2 2 2 2
(EQ 6)
y(n) b b i1 b i2
---------- = -----i0- w i ( n ) + ------ w ( n – 1 ) + ------ w (n – 2)
k k k i k i
2 2 2 2
1. The incoming signal x(n), must be right shifted k bits

2. Also the intermediate value wi(n)/2k must be shifted by k bits to get the true value
of wi(n).

3. Furthermore, y(n)/2k must be left shifted by k bits to obtain the true value for y(n).

4. y(n), the output of section i is x(n) the input for section i + 1, thus there is a left
shift on output of section i and a right shift on input to section i + 1. Clearly, these
two shifts can be combined into one shift. Also, ai1 and ai2 have been complemented.

5. Hd, the overall gain, is usually less than 1.0 and must be used as a multiplier of the
incoming signal prior to the first section, otherwise overflow will result.
Figure 4 - 1 and Figure 4 - 2 are examples of coefficient files for Cascade Forms 1 and
2 respectively.
For Form II this is the scale down factor for the incoming sample. To find the actual value
of the scale down factor, just shift the overall gain value by the shift count. If the shift
count is negative, shift left. If the shift count is positive, shift right.
Next are 6 values for each section, shift count, b0, b1, b2, a1, a2. The shift count for each
section shows the power of 2 that was needed to get the absolute value of each coefficient
less than 1. The actual values for b0, b1, b2, a1, a2 have been divided by this shift count,
and all values are displayed in both demical and hexadecimal.
Following the display of lines, a fixed point for each sections are three columns of floating
point numbers. The first column is the floating point equivalent of the fixed point
coefficients. The second column is the hexadecimal value of the quantized floating point
coefficients. The third column is the original coefficients and hence may have values >1.0
in absolute value.

FIGURE 4 - 1 Example Cascade Form I Coefficient File - Fractional Fixed Point

FILTER COEFFICIENT FILE


IIR DESIGN
FILTER TYPE LOW PASS
ANALOG FILTER TYPE INVERSE TSCHEBYSCHEFF
PASSBAND RIPPLE IN -dB -.1111E+00
STOPBAND RIPPLE IN -dB -.4444E+02
PASSBAND CUTOFF FREQUENCY 0.100000E+01 Hertz
STOPBAND CUTOFF FREQUENCY 0.200000E+01 Hertz
SAMPLING FREQUENCY 0.800000E+01 Hertz

Page 4 - 6 dsPIC Filter Design Reference Guide


FILTER COEFFICIENT FILE IIR FILTER COEFFICIENT FILES

FILTER DESIGN METHOD: BILINEAR TRANSFORMATION


FILTER ORDER 5 5h
NUMBER OF SECTIONS 3 3h
NO. OF QUANTIZED BITS 16 10h
QUANTIZATION TYPE - FRACTIONAL FIXED POINT
COEFFICIENTS SCALED FOR CASCADE FORM I
0 0 /* shift count for overall gain */
32767 7FFF /* overall gain */
0 0 /* shift count for section 1 values */
7652 1DE4 /* section 1 coefficient B0 */
7430 1D06 /* section 1 coefficient B1 */
7652 1DE4 /* section 1 coefficient B2 */
16251 3F7B /* section 1 coefficient -A1*/
-6219 FFFFE7B5 /* section 1 coefficient -A2*/
0 0 /* shift count for section 2 values */
11072 2B40 /* section 2 coefficient B0 */
1082 43A /* section 2 coefficient B1 */
11072 2B40 /* section 2 coefficient B2 */
26713 6859 /* section 2 coefficient -A1*/
-20793 FFFFAEC7 /* section 2 coefficient -A2*/
0 0 /* shift count for section 3 values */
15501 3C8D /* section 3 coefficient B0 */
15501 3C8D /* section 3 coefficient B1 */
0 0 /* section 3 coefficient B2 */
5945 1739 /* section 3 coefficient -A1*/
0 0 /* section 3 coefficient -A2*/
0.2335205078125000E+00 3FCDE40000000000 0.23352051E+00 /* section 1 B0 */
0.2267456054687500E+00 3FCD060000000000 0.22674561E+00 /* section 1 B1 */
0.2335205078125000E+00 3FCDE40000000000 0.23352051E+00 /* section 1 B2 */
0.4959411621093750E+00 BFDFBD8000000000 0.49594116E+00 /* section 1 -A1*/
-.1897888183593750E+00 3FC84B0000000000 -.18978882E+00 /* section 1 -A2*/
0.3378906250000000E+00 3FD5A00000000000 0.33789063E+00 /* section 2 B0 */
0.3302001953125000E-01 3FA0E80000000000 0.33020020E-01 /* section 2 B1 */
0.3378906250000000E+00 3FD5A00000000000 0.33789063E+00 /* section 2 B2 */
0.8152160644531250E+00 BFEA164000000000 0.81521606E+00 /* section 2 -A1*/
-.6345520019531250E+00 3FE44E4000000000 -.63455200E+00 /* section 2 -A2*/
0.4730529785156250E+00 3FDE468000000000 0.47305298E+00 /* section 3 B0 */
0.4730529785156250E+00 3FDE468000000000 0.47305298E+00 /* section 3 B1 */
0.0000000000000000E+00 0000000000000000 0.00000000E+00 /* section 3 B2 */
0.1814270019531250E+00 BFC7390000000000 0.18142700E+00 /* section 3 -A1*/
0.0000000000000000E+00 0000000000000000 0.00000000E+00 /* section 3 -A2*/

FIGURE 4 - 2 Example Cascade Form II Coefficient File - Fractional Fixed Point


FILTER COEFFICIENT FILE
IIR DESIGN
FILTER TYPE LOW PASS
ANALOG FILTER TYPE TSCHEBYSCHEFF
PASSBAND RIPPLE IN -dB -.1111E+00
STOPBAND RIPPLE IN -dB -.4444E+02
PASSBAND CUTOFF FREQUENCY 0.100000E+01 Hertz

dsPIC Filter Design Reference Guide Page 4 - 7


IIR FILTER COEFFICIENT FILES FILTER COEFFICIENT FILE

STOPBAND CUTOFF FREQUENCY 0.200000E+01 Hertz


SAMPLING FREQUENCY 0.800000E+01 Hertz
FILTER DESIGN METHOD: BILINEAR TRANSFORMATION
FILTER ORDER 5 5h
NUMBER OF SECTIONS 3 3h
NO. OF QUANTIZED BITS 16 10h
QUANTIZATION TYPE - FRACTIONAL FIXED POINT
COEFFICIENTS SCALED FOR CASCADE FORM II
-1 FFFFFFFF /* shift count for overall gain */
16634 40FA /* overall gain */
1 1 /* shift count for section 1 values */
1150 47E /* section 1 coefficient B0 */
2300 8FC /* section 1 coefficient B1 */
1150 47E /* section 1 coefficient B2 */
20042 4E4A /* section 1 coefficient -A1*/
-8457 FFFFDEF7 /* section 1 coefficient -A2*/
1 1 /* shift count for section 2 values */
3398 D46 /* section 2 coefficient B0 */
6797 1A8D /* section 2 coefficient B1 */
3398 D46 /* section 2 coefficient B2 */
19526 4C46 /* section 2 coefficient -A1*/
-13079 FFFFCCE9 /* section 2 coefficient -A2*/
0 0 /* shift count for section 3 values */
17631 44DF /* section 3 coefficient B0 */
17631 44DF /* section 3 coefficient B1 */
0 0 /* section 3 coefficient B2 */
21025 5221 /* section 3 coefficient -A1*/
0 0 /* section 3 coefficient -A2*/
0.3509521484375000E-01 3FA1F80000000000 0.70190430E-01 /* section 1 B0 */
0.7019042968750000E-01 3FB1F80000000000 0.14038086E+00 /* section 1 B1 */
0.3509521484375000E-01 3FA1F80000000000 0.70190430E-01 /* section 1 B2 */
0.6116333007812500E+00 BFE3928000000000 0.12232666E+01 /* section 1 -A1*/
-.2580871582031250E+00 3FD0848000000000 -.51617432E+00 /* section 1 -A2*/
0.1036987304687500E+00 3FBA8C0000000000 0.20739746E+00 /* section 2 B0 */
0.2074279785156250E+00 3FCA8D0000000000 0.41485596E+00 /* section 2 B1 */
0.1036987304687500E+00 3FBA8C0000000000 0.20739746E+00 /* section 2 B2 */
0.5958862304687500E+00 BFE3118000000000 0.11917725E+01 /* section 2 -A1*/
-.3991394042968750E+00 3FD98B8000000000 -.79827881E+00 /* section 2 -A2*/
0.5380554199218750E+00 3FE137C000000000 0.53805542E+00 /* section 3 B0 */
0.5380554199218750E+00 3FE137C000000000 0.53805542E+00 /* section 3 B1 */
0.0000000000000000E+00 0000000000000000 0.00000000E+00 /* section 3 B2 */
0.6416320800781250E+00 BFE4884000000000 0.64163208E+00 /* section 3 -A1*/
0.0000000000000000E+00 0000000000000000 0.00000000E+00 /* section 3 -A2*/

Page 4 - 8 dsPIC Filter Design Reference Guide


FILTER COEFFICIENT FILE FIR FILTER COEFFICIENT FILE

4.2 FIR FILTER COEFFICIENT FILE

The simplest way to implement an FIR filter is to use the following difference equation:

y(n) =
∑ h ( i )x ( n – i ) (EQ 7)

i=0

where N = filter order. See Figure 4 - 3 for an example of the coefficient file.

The first three lines are comments followed by four lines representing the number of taps
in decimal, hexadecimal and number of bits in quantized coeffiicients. Lines 8 and 9 are
essentially the overall gain factor. The next N lines are the quantized coefficients with
the first column being the decimal form and the second column the hexadecimal form of
the coefficient. The next N lines are the quantized coefficients in floating point form with
column 1 being the decimal value and column 2 the hexadecimal format of the number.

FIGURE 4 - 3 Example of FIR Coefficient File - Fixed Point: Gain = 0.5

FILTER COEFFICIENT FILE


FIR DESIGN
SAMPLING FREQUENCY 0.800000E+01 Hertz
23 /* number of taps in decimal */
17 /* number of taps in hexadecimal */
16 /* number of bits in quantized coefficients (dec) */
10 /* number of bits in quantized coefficients (hex) */
-1 /* shift count in decimal */
FFFFFFFF 0.500000000E+00 /* shift count (hex), gain multiplier */
93 5D /* coefficient of tap 0 */
-304 FFFFFED0 /* coefficient of tap 1 */
-636 FFFFFD84 /* coefficient of tap 2 */
0 0 /* coefficient of tap 3 */
1387 56B /* coefficient of tap 4 */
1501 5DD /* coefficient of tap 5 */
-1138 FFFFFB8E /* coefficient of tap 6 */
-4202 FFFFEF96 /* coefficient of tap 7 */
-2351 FFFFF6D1 /* coefficient of tap 8 */
6956 1B2C /* coefficient of tap 9 */
18889 49C9 /* coefficient of tap 10 */
24395 5F4B /* coefficient of tap 11 */
18889 49C9 /* coefficient of tap 12 */
6956 1B2C /* coefficient of tap 13 */
-2351 FFFFF6D1 /* coefficient of tap 14 */
-4202 FFFFEF96 /* coefficient of tap 15 */
-1138 FFFFFB8E /* coefficient of tap 16 */
1501 5DD /* coefficient of tap 17 */
1387 56B /* coefficient of tap 18 */
0 0 /* coefficient of tap 19 */
-636 FFFFFD84 /* coefficient of tap 20 */
-304 FFFFFED0 /* coefficient of tap 21 */

dsPIC Filter Design Reference Guide Page 4 - 9


FIR FILTER COEFFICIENT FILE FILTER COEFFICIENT FILE

93 5D /* coefficient of tap 22 */
0.2838134765625000E-02 3F67400000000000/* coefficient of tap 0 */
-.9277343750000000E-02 BF83000000000000/* coefficient of tap 1 */
-.1940917968750000E-01 BF93E00000000000/* coefficient of tap 2 */
0.0000000000000000E+00 0000000000000000/* coefficient of tap 3 */
0.4232788085937500E-01 3FA5AC0000000000/* coefficient of tap 4 */
0.4580688476562500E-01 3FA7740000000000/* coefficient of tap 5 */
-.3472900390625000E-01 BFA1C80000000000/* coefficient of tap 6 */
-.1282348632812500E+00 BFC06A0000000000/* coefficient of tap 7 */
-.7174682617187500E-01 BFB25E0000000000/* coefficient of tap 8 */
0.2122802734375000E+00 3FCB2C0000000000/* coefficient of tap 9 */
0.5764465332031250E+00 3FE2724000000000/* coefficient of tap 10 */
0.7444763183593750E+00 3FE7D2C000000000/* coefficient of tap 11 */
0.5764465332031250E+00 3FE2724000000000/* coefficient of tap 12 */
0.2122802734375000E+00 3FCB2C0000000000/* coefficient of tap 13 */
-.7174682617187500E-01 BFB25E0000000000/* coefficient of tap 14 */
-.1282348632812500E+00 BFC06A0000000000/* coefficient of tap 15 */
-.3472900390625000E-01 BFA1C80000000000/* coefficient of tap 16 */
0.4580688476562500E-01 3FA7740000000000/* coefficient of tap 17 */
0.4232788085937500E-01 3FA5AC0000000000/* coefficient of tap 18 */
0.0000000000000000E+00 0000000000000000/* coefficient of tap 19 */
-.1940917968750000E-01 BF93E00000000000/* coefficient of tap 20 */
-.9277343750000000E-02 BF83000000000000/* coefficient of tap 21 */
0.2838134765625000E-02 3F67400000000000/* coefficient of tap 22 */

Page 4 - 10 dsPIC Filter Design Reference Guide


CHAPTE R 5 Addendum

dsPIC Filter Design Reference Guide Page 5 - 1


5.1 References
1. Antoniou, Andreas. Digital Filter Analysis and Design: McGraw Hill, 1979

2. Bernhardt, Paul A. Simplified Design of High Order Recursive Group Delay Filters,
IEEE Transactions on Acoustics, Speech, and Signal Processing. Vol. ASSP-29, No.
5, October 1980.

3. Crochiere, R. E. & Rabiner L. R., Multirate Digital Signal Processing: Prentice Hall,
1983.

4. Elliott Douglas F. Handbook of Digital Signal Processing Engineering Applications:


Academic Press Inc, 1987.

5. Harris F.J., On the Use of Windows for Harmonic Analysis with the Discrete Fourier
Transform. Proc. IEEE, Vol 66, No. 1, pp. 51-83, Jan 1978.

6. Hogenauer, E. B. An Economical Class of Digital Filters for Decimation and


Interpolation; IEEE Transactions on Acoustics, Speech, and Signal Processing. Vol.
ASSP-29, No. 2, April 1981.

7. Jackson, L. B. Digital Filters and Signal Processing. Kluwer, 1986.

8. Jayant, N. S. & Noll P. Digital Coding of Waveforms. Prentice Hall, 1984.

9. Kaiser, J. F. Nonrecursive Digital Filter Design using the IO - SinH Window Function:
Proceedings of IEEE International Symposium on Circuits and Systems, 1984.

10. Nuttal A. H. Some Windows with Very Good Sidelobe Behavior, IEEE Trans. Acoust.,
Speech and Signal Processing, vol ASSP-29, No. 1, pp 84-91, Feb. 1981.

11. Oppenheim, Alan V. & Shafer, Ronald W. Digital Signal Processing: Prentice Hall,
1975.

12. Parks, T.W. & Burrus C.S. Digital Filter Design. John Wiley & Sons, Inc., 1987.

13. Proakis John G & Manolakis Dimitris G. Digital Signal Processing Principles,
Algorithms, and Applications. 2nd Edition. Macmillan Publishing, New York, 1992.

14. Rabiner, Lawrence R & Gold, Bernard. Theory & Application of Digital Signal
Processing: Prentice Hall, 1975.

15. Roberts, Richard A & Mullis, Clifford T. Digital Signal Processing: Addison-Wesley,
1987.

16. Webster R.J. On Qualifying Windows for FIR Filter Design, IEEE Trans. Acoust.,
Speech & Signal Processing, vol. ASSP-31, no. 1, pp 237-240, Feb. 1983.

17. Charles Schuler and Mahesh Chugani. Digital Signal Processing: A Hands-On
Approach: Glencoe/McGraw-Hill, 2003

Page 5 - 2 dsPIC Filter Design Reference Guide


5.2 IIR Design Output Example
Following is an example of design output for an IIR Bandpass filter. The various parts are
explained as follows, with arrows denoting the corresponding segments on the example
shown in Figure 4.1

1. Problem description or filter specification

2. Normalized lowpass transfer function

N
2
b i0 s + b i1 s + b i2
H(z) = Hd ∏ ----------------------------------------
2
s + a i1 s + a i2
(EQ 8)

i=1

Where N is the number of second order sections.

3. Unnormalized analog transfer function U(s) formed by using analog frequency


transformations for Lowpass to Bandpass in this example

2 2
s +ω
s → ⎛ ----------------0-⎞ (EQ 9)
⎝ Bs ⎠
where B is the bandwidth and ω0 is the center frequency. These values are pre-
warped for the bilinear transformation. Note: the order for the unnormalized trans-
fer function U(s) doubles for a Lowpass to Bandpass transformation. U(s) is the
product of the 2nd order sections.

4. The digital transfer function H(z) formed from the unnormalized transfer function
U(s) by applying the bilinear transformation H(z) is the product of the 2nd order
sections.
N N
⎛ b i0 z + b i1 + b i2⎞
2 –1 –2
( b i0 + b i1 z + b i2 z )
H ( z ) = Hd ∏ ⎜ -------------------------------------
⎝ z + a i1 + a i2 ⎠
2
-⎟ = H d
∏ ----------------------------------------------------
–1
( 1 + a i1 z + a i2 z )
–2
(EQ 10)

i=1 i=1

5. The zeros of H(z)

6. The poles of H(z)

7. Numerator and Denominator of H(z) in powers of z.

8. The maximum and minimum impulse response as calculated by simulating the filter
response to an impulse input response.

dsPIC Filter Design Reference Guide Page 5 - 3


FIGURE 5-1 IIR Bandpass Filter
FILTER TYPE BAND PASS
ANALOG FILTER TYPE ELLIPTIC
PASSBAND RIPPLE IN -dB -1.0000
STOPBAND RIPPLE IN -dB -45.0000
PASSBAND CUTOFF FREQUENCIES 900.000 1100.00 HERTZ
STOPBAND CUTOFF FREQUENCIES 800.000 1200.00 HERTZ
SAMPLING FREQUENCY 6000.00 HERTZ
FILTER ORDER: 8
1 FILTER DESIGN METHOD: BILINEAR TRANSFORMATION
NORMALIZED ANALOG TRANSFER FUNCTION T(s)
NUMERATOR COEFFICIENTS DENOMINATOR COEFFICIENTS
************************************* *************************************
2 S**2 TERM S TERM CONST TERM S**2 TERM S TERM CONST TERM
.100000E+01 .000000E+00 .116352E+02 .100000E+01 .506146E+00 .166324E+00
.100000E+01 .000000E+00 .222240E+01 .100000E+01 .172643E+00 .512697E+00
INITIAL GAIN .293912143E-02
UNNORMALIZED ANALOG TRANSFER FUNCTION T(s)
NUMERATOR COEFFICIENTS DENOMINATOR COEFFICIENTS
************************************* *************************************
S**2 TERM S TERM CONST TERM S**2 TERM S TERM CONST TERM
3 .232838E+00 .000000E+00 .369783E+07 .100000E+01 .559404E+03 .427568E+08
.232838E+00 .000000E+00 .332854E+08 .100000E+01 .623399E+03 .530990E+08
.232838E+00 .000000E+00 .673253E+07 .100000E+01 .177624E+03 .374781E+08
.232838E+00 .000000E+00 .182819E+08 .100000E+01 .225823E+03 .605779E+08
INITIAL GAIN 1.00000000
DIGITAL TRANSFER FUNCTION Hd(z)
NUMERATOR COEFFICIENTS DENOMINATOR COEFFICIENTS
************************************* *************************************
Z**2 TERM Z TERM CONST TERM Z**2 TERM Z TERM CONST TERM
4 .3265918765 -.0023787440 .3265918765 1.00000 -.8886603703 .9268667712
.1924154175 -.3083779691 .1924154175 1.00000 -1.0466058250 .9306056718
.2499455221 -.1471073544 .2499455221 1.00000 -.8048919128 .9738539128
.2192763630 -.2918822351 .2192763630 1.00000 -1.1603089476 .9767824321
INITIAL GAIN 1.00000000
ZEROES OF TRANSFER FUNCTION Hd(z)
5 REAL PART IMAGINARY PART REAL PART IMAGINARY PART RADIUS
.364176846E-02 .999993369E+00 .364176846E-02 -.999993369E+00 .100000000E+01
.801333836E+00 .598217422E+00 .801333836E+00 -.598217422E+00 .100000000E+01
.294278836E+00 .955719607E+00 .294278836E+00 -.955719607E+00 .100000000E+01
.665557909E+00 .746346213E+00 .665557909E+00 -.746346213E+00 .100000000E+01
POLES OF TRANSFER FUNCTION Hd(z)
REAL PART IMAGINARY PART REAL PART IMAGINARY PART RADIUS
.444330185E+00 .854071108E+00 .444330185E+00 -.854071108E+00 .962739202E+00
6 .523302913E+00 .810407141E+00 .523302913E+00 -.810407141E+00 .964679051E+00
.402445956E+00 .901050035E+00 .402445956E+00 -.901050035E+00 .986840368E+00
.580154474E+00 .800127002E+00 .580154474E+00 -.800127002E+00 .988323040E+00
NUMERATOR COEFFICIENTS - HIGHEST ORDER FIRST (in z)
7 .344415292E-02 -.121565672E-01 .271595297E-01 -.408909819E-01 .474622508E-01
-.408909819E-01 .271595297E-01 -.121565672E-01 .344415292E-02
DENOMINATOR COEFFICIENTS - HIGHEST ORDER FIRST (in z)
8 .100000000E+01 -.390046706E+01 .947529599E+01 -.147737178E+02 .170945309E+02
-.140611397E+02 .858318379E+01 -.336223066E+01 .820492586E+00
IMPULSE RESPONSE MIN = -.685317E-01, MAX = .680743E-01

Page 5 - 4 dsPIC Filter Design Reference Guide

También podría gustarte