72
Filter Design for dsPIC MCU Digital Filter Design and Analysis System for use with Microchip Technology dsPIC Microcontrollers Momentum Data Systems, Inc.

dsPIC

Embed Size (px)

Citation preview

Page 1: dsPIC

Filter Design for dsPIC MCU

Digital Filter Design and Analysis System

for use with Microchip Technology dsPIC Microcontrollers

Momentum Data Systems, Inc.

Page 2: dsPIC

Copyright/Trademark Information

Copyright 2002 Momentum Data Systems17330 Brookhurst Street, Suite 230Fountain 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.

Page 3: dsPIC

LICENSE AGREEMENT

PLEASE READ THE FOLLOWING TERMS AND CONDITIONS BEFORE USING THIS PROGRAM. USE OF THE PROGRAM INDICATES YOUR ACCEPTANCE OF THESE TERMS AND CONDITIONS. IF YOU DO NOT AGREE WITH THEM, RETURN THE PROGRAM 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 posses-sion, 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 soft-ware 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 con-ditions of this Agreement. If you transfer the pro-gram, 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, MODIFI-CATION, OR MERGED PORTION OF THIS PROGRAM TO ANY OTHER PARTY, YOUR LICENSE IS AUTOMAT-ICALLY 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 termina-

tion to destroy the program together with all copies, modifi-cations 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 pur-chase. In the event of notification within the warranty period of defects in material or workmanship, MDS will replace the defective diskettes or documentation. The rem-edy for breach of this warranty shall be limited to replace-ment and shall not encompass any other damages, including but not limited to loss of profit, special, incidental, conse-quential, or other similar claims.

Momentum Data Systems, Inc. and its distributors specifi-cally disclaims all other warranties, expressed or implied, including but not limited to, implied warranties of mer-chantability and fitness for a particular purpose with respect to defects in the software and documentation and the pro-gram license granted herein, in particular, and without lim-iting 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 opera-tion 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, under-stand 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 agreement, oral or written, and any other communica-tions between us relating to the subject matter of this Agree-ment.

IF YOU HAVE ANY QUESTIONS CONCERNING THIS AGREEMENT, PLEASE CONTACT MOMENTUM DATA SYSTEMS.

Page 4: dsPIC
Page 5: dsPIC

dsPIC Filter Design Reference Guide Page i

Filter Design for Microchip dsPIC MCU

Table of Contents

Chapter 1 Introduction to Filter Design for Microchip Technology dsPIC MCU

1.1 Design Capabilities 1-2

1.2 General System Features. 1-4

1.3 Installation 1-51.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 dsPIC Filter Design Examples2.1 IIR Lowpass 2-2

2.2 IIR Bandpass 2-4

2.3 FIR Lowpass 2-6

2.4 Equiripple FIR Lowpass 2-8

Chapter 3 System Operation3.1 Toolbar 3-3

3.1.1 Status Bar 3-5

3.2 File Menu 3-63.2.1 Load Specification File 3-73.2.2 Print 3-83.2.3 Printer Setup 3-83.2.4 System Settings 3-93.2.5 User Information 3-103.2.6 Exit 3-103.2.7 About dsPIC Filter Design 3-11

3.3 View Menu 3-123.3.1 Toolbar 3-123.3.2 Status Bar 3-123.3.3 Text Filter File View 3-13

3.4 Design Menu 3-143.4.1 IIR Design 3-153.4.2 FIR Design with Windows 3-173.4.3 Equiripple FIR Design 3-20

3.5 Filter Menu 3-223.5.1 Lowpass 3-233.5.2 Highpass 3-23

Page 6: dsPIC

Page ii dsPIC Filter Design Reference Guide

3.5.3 Bandpass 3-253.5.4 Bandstop 3-26

3.6 Output Menu 3-273.6.1 Plot Control 3-273.6.2 Snap to Grid 3-303.6.3 Quantization 3-303.6.4 Create Specification File 3-313.6.5 Create Filter Coefficient File 3-323.6.6 Create Matlab File 3-323.6.7 Create Plot Data Files 3-33

3.7 Code Generation Menu 3-343.7.1 Create C Code 3-353.7.2 C Code File Generation 3-353.7.3 Microchip dsPIC30 Code Generation 3-35

3.8 Window Menu 3-403.8.1 Select Plots 3-413.8.2 Display Control 3-41

Chapter 4 Addendum4.1 References 4-2

4.2 IIR Design Output Example 4-3

Page 7: dsPIC

dsPIC Filter Design Reference Guide Page 1 - 1

CHAPTER 1 Introduction to Filter Design for Microchip Technology dsPIC MCU

This manual is a reference guide to the Filter Design for dsPIC MCU ("dsPIC FD")specifically developed for use with Microchip Technology’s dsPIC30F 16-bit MCUProduct Family. It is intended to explain the usage of the system and what the variousscreen displays and computer printouts mean. It is not intended to be a tutorial on digitalsignal processing since several excellent texts on the subject exist and it is assumed thatthe 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.

More advanced versions of QEDesign are also available. Please call Momentum DataSystems for further information. These systems support significantly more powerful filterdesign techniques.

Page 8: dsPIC

Page 1 - 2 dsPIC Filter Design Reference Guide

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• Filter orders up to 20 for Bandpass and Bandstop Filters• 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• 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 9: dsPIC

dsPIC Filter Design Reference Guide Page 1 - 3

–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

• Choice of placement of coefficients in Program Space or Data Space• dsPIC30F Assembly Code• C wrapper/header code generation

Other General Features

• 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)

Page 10: dsPIC

Page 1 - 4 dsPIC Filter Design Reference Guide

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 11: dsPIC

dsPIC Filter Design Reference Guide Page 1 - 5

1.3 Installation

1.3.1 Application Software Installation

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

<drive>:\setup

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

Page 12: dsPIC

Page 1 - 6 dsPIC Filter Design Reference Guide

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.

Stopband specifications are given in the form

-20log10(δ2)

Thus the magnitude of the stopband is from [0, δ2].

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.

Page 13: dsPIC

dsPIC Filter Design Reference Guide Page 1 - 7

1.5 Design Methods

For the IIR design, a normalized lowpass analog transfer function is generated based onthe given filter specifications. This normalized lowpass analog transfer function is thentransformed to an unnormalized analog transfer function (lowpass,highpass,bandpass orbandstop) via the analog frequency transformation formulae. Values for the frequencytransformation are suitably chosen to compensate for the prewarping caused by thesubsequent bilinear transformation.

The unnormalized transfer functions for Lowpass, Highpass, Bandpass and BandstopFilters are then transformed to the digital domain via the bilinear transformation. Detailsof the transformations are printed in the output file SFIL.OUT. Output for each designwill be accumulated in this file until it is printed. The filter characteristics including theimpulse response are simulated via cascaded second order sections with the poles andzeros 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 usingthe window calculation, again based on input specifications. The coefficients for the tapsare then determined by using the Fourier series design techniques for computing theimpulse response and the window coefficients.

The Equiripple FIR design uses the Remez2 exchange algorithm to determine an optimalsolution. The solution is optimal in the minimax sense - that is the maximum error overthe entire frequency band is minimized. This produces equiripple results in both thepassband 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)

Page 14: dsPIC

Page 1 - 8 dsPIC Filter Design Reference Guide

1.6 System Operation

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

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

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

To start the system: Double-click on the dsPIC FD icon to launch the system or enter thefollowing command:

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

Page 15: dsPIC

dsPIC Filter Design Reference Guide Page 2 - 1

CHAPTER 2 dsPIC Filter Design Examples

The authors of dsPIC FD believe that the most efficient way to become familiar with theimplementation and potential of the system is to step through the examples provided. Thefollowing pages contain examples of the various design methods and are organized in thefollowing 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)

Page 16: dsPIC

Page 2 - 2 dsPIC Filter Design Reference Guide

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.

FIGURE 2-2 Select Analog Prototype and Filter Order

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

Page 17: dsPIC

dsPIC Filter Design Reference Guide Page 2 - 3

FIGURE 2-3 System Responses for Example 1

Page 18: dsPIC

Page 2 - 4 dsPIC Filter Design Reference Guide

2.2 IIR Bandpass

This example is an IIR bandpass filter with an Elliptic Analog prototype.

FIGURE 2-4 Bandpass Filter Specifications

This filter has relatively narrow transition bands. The Elliptic filter design method willbe significantly more efficient than other analog prototypes.

FIGURE 2-5 Select Analog Prototype and Filter Order

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

Page 19: dsPIC

dsPIC Filter Design Reference Guide Page 2 - 5

FIGURE 2-6 System Responses for Example 2

Page 20: dsPIC

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 windowfunction is usually selected for this type of design.

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 filterorders that a rectangular window would be better. However, a rectangular window willnot provide a design where the first sidelobe of the stopband will be less than 45 dB.

Page 21: dsPIC

dsPIC Filter Design Reference Guide Page 2 - 7

FIGURE 2-9 System Responses for Example 3

Page 22: dsPIC

Page 2 - 8 dsPIC Filter Design Reference Guide

2.4 Equiripple FIR Lowpass

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

FIGURE 2-10 Lowpass Filter Specifications

The Equiripple design can make use of both ripple values in the design of the filter whereasthe FIR design with windows cannot. The FIR design with windows uses the only oneripple value and will over design the other ripple value

FIGURE 2-11 Select Filter Order

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

Page 23: dsPIC

dsPIC Filter Design Reference Guide Page 2 - 9

FIGURE 2-12 System Responses for Example 4

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

Page 24: dsPIC

Page 2 - 10 dsPIC Filter Design Reference Guide

Page 25: dsPIC

dsPIC Filter Design Reference Guide Page 3 - 1

CHAPTER 3 System Operation

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

TABLE 3-1 Main Menu Bar

Selection DescriptionFile 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

Page 26: dsPIC

Page 3 - 2 dsPIC Filter Design Reference Guide

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 itemsare covered in this chapter.

Page 27: dsPIC

dsPIC Filter Design Reference Guide Page 3 - 3

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 theyappear 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

Page 28: dsPIC

Page 3 - 4 dsPIC Filter Design Reference Guide

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 FileOUTPUT/Create C Code File, OUTPUT/Create Matlab File

Page 29: dsPIC

dsPIC Filter Design Reference Guide Page 3 - 5

3.1.1 Status Bar

FIGURE 3-3 Status Bar Display

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

Status

Snap to Grid On/Off

Q16 - Resolution

Page 30: dsPIC

Page 3 - 6 dsPIC Filter Design Reference Guide

3.2 File Menu

Select the file menu by placing the cursor over the word FILE, click and hold the selectionby moving the cursor to the appropriate item in the drop-down menu, prior to releasingthe mouse button. Note that the enabled options are listed in black with disabled optionsappearing 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 31: dsPIC

dsPIC Filter Design Reference Guide Page 3 - 7

3.2.1 Load Specification File

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

FIGURE 3-5 Filter Specification File Selection

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

Page 32: dsPIC

Page 3 - 8 dsPIC Filter Design Reference Guide

3.2.2 Print

On completion of a filter design, filter plots can be printed. The print menu does not applyto 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 33: dsPIC

dsPIC Filter Design Reference Guide Page 3 - 9

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

Page 34: dsPIC

Page 3 - 10 dsPIC Filter Design Reference Guide

• 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 35: dsPIC

dsPIC Filter Design Reference Guide Page 3 - 11

3.2.7 About dsPIC FD Filter Design

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

FIGURE 3-10 About Screen

Page 36: dsPIC

Page 3 - 12 dsPIC Filter Design Reference Guide

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 37: dsPIC

dsPIC Filter Design Reference Guide Page 3 - 13

3.3.3 Text Filter File View

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

FIGURE 3-12 Text Display

Page 38: dsPIC

Page 3 - 14 dsPIC Filter Design Reference Guide

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, itshould 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 thedesigns.

Page 39: dsPIC

dsPIC Filter Design Reference Guide Page 3 - 15

3.4.1 IIR Design

Selects the system design method to Infinite Impulse Response (IIR) design. IIR designsall have feedback loops in the difference equations that implement the filters - that is theoutput value in a linear function of previous output values as well as current and previousinput values. IIR designs are classical filter designs using analog design methods whichtransform 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 analogprototypes. After selecting “Next” on the IIR Design Menu the following dialog box willbe displayed.

FIGURE 3-15 Estimated Filter Order/Analog Type

Page 40: dsPIC

Page 3 - 16 dsPIC Filter Design Reference Guide

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

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

Page 41: dsPIC

dsPIC Filter Design Reference Guide Page 3 - 17

3.4.2 FIR Design with Windows

Sets the system design method to Finite Impulse Response (FIR) Windows design. FIRdesigns produce a filter in which difference equations do not have feedback loops - thatis, the output value is a function only of current and previous input values. Previous outputvalues are not part of these filter calculations. The Windows type of FIR design is doneby forming a truncated Fourier Series to represent the desired frequency response and'windowing' or multiplying the resulting coefficients element by element with a windowfunction to reduce the Gibbs effect of truncating the Fourier series. The dsPIC FD systemsets 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 passband ripple and the stopband ripplefor filters. However, for window designs, the system selects the minimum ripple (smallestin linear sense) and uses that value for both the stopband and passband ripples. Thisrestriction 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, orBandstop, a dialog box similar to the following dialog box is displayed with the estimatedorder 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 tapsequal to the estimate. The estimate can be overridden by any value from 2 to 513.

Page 42: dsPIC

Page 3 - 18 dsPIC Filter Design Reference Guide

FIGURE 3-17 Select Window Function

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

Page 43: dsPIC

dsPIC Filter Design Reference Guide Page 3 - 19

TABLE 3-2 Window Function Limitations

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

Window Function Sidelobe Peak(dB)

Stopband Attenuation (dB)

Asymptotic 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 3rd Derivative

-46.74 61.36 -30

Minimum 3 Term Cosine -71.48 86.40 -6

4 Term Cosine -74.39 87.78 -6

4 Term Cosine with Continuous 5th Derivative

-60.95 77.03 -42

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 SelectableSelectableSelectableSelectable

-6

Dolph-Tschebyscheff 0

Taylor 0

Gaussian -6

Page 44: dsPIC

Page 3 - 20 dsPIC Filter Design Reference Guide

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 beaccepted 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. Thealgorithm appears to terminate normally in these cases, but the results do not give thedesired results. Typically the gain will exceed 1.0 even though this is the expectedmaximum gain.

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

Page 45: dsPIC

dsPIC Filter Design Reference Guide Page 3 - 21

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

Page 46: dsPIC

Page 3 - 22 dsPIC Filter Design Reference Guide

3.5 Filter Menu

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

TABLE 3-3 Filter Types

FIGURE 3-20 Filter Menu

Filter Type IIR Design FIR Design

Lowpass ü üHighpass ü üBandpass ü üBandstop ü ü

Page 47: dsPIC

dsPIC Filter Design Reference Guide Page 3 - 23

3.5.1 Lowpass

The following dialog box appears if Lowpass was selected from the DESIGN menu orFILTER/Lowpass was selected. All fields are mandatory and a valid entry must be ineach of them. Frequencies are in Hertz. The stopband and passband frequencies must beless 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. Theattenuation or ripple of the stopband and passband is expressed in dB. While both thepassband ripple and the stopband ripple are required, the filter order and results aredetermined using the stopband ripple only for FIR design with Windows. Both fields arerequired 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 is0.01dB to 3dB. A typical range of values for stopband ripple is 20dB to 100dB. Thepassband ripple must be less than the stopband ripple.

3.5.2 Highpass

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

Furthermore, the passband frequency of a highpass filter must be greater than the stopbandfrequency. 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 andresults are determined using the stopband ripple only for FIR design with Windows. Bothfields are required in case this specification is used in either an IIR design or an FIREquiripple (Parks-McClellan) design. A typical range of values for passband ripple or

Page 48: dsPIC

Page 3 - 24 dsPIC Filter Design Reference Guide

attenuation is 0.01dB to 3dB. A typical range of values for the stopband ripple is 20dBto 100dB.

FIGURE 3-22 Highpass Filter Input Screen

Page 49: dsPIC

dsPIC Filter Design Reference Guide Page 3 - 25

3.5.3 Bandpass

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

While both the passband ripple and the stopband ripple are required, the filter order isdetermined for FIR design with Windows using the stopband ripple only. Both fields arerequired 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 anacceptable equiripple bandpass filter.

FIGURE 3-23 Bandpass Filter

Page 50: dsPIC

Page 3 - 26 dsPIC Filter Design Reference Guide

3.5.4 Bandstop

The following dialog box appears if a Bandstop filter was selected on the DESIGN menuor FILTER/Bandstop was selected. This dialog box is virtually identical to the Bandpassdialog 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 andresults are determined using the stopband ripple only for FIR design with Windows. Bothfields are required in case this specification is used in either an IIR design or an FIREquiripple (Parks-McClellan) design.

FIGURE 3-24 Bandstop Filter

Page 51: dsPIC

dsPIC Filter Design Reference Guide Page 3 - 27

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:

Page 52: dsPIC

Page 3 - 28 dsPIC Filter Design Reference Guide

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 onceset 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 seethe change from linear frequency scale to log frequency scale, the ‘Accept’ button mustbe 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 RangeThe 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 RangeThe 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 53: dsPIC

dsPIC Filter Design Reference Guide Page 3 - 29

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 ScaleTo 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 PlotsGrid 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 LocationsThe '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 OutputDetailed 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 AutomaticallyWhen this option is selected, the plotting ranges will automatically be set to the fol-lowing values whenever the problem is changed:

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.

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

Page 54: dsPIC

Page 3 - 30 dsPIC Filter Design Reference Guide

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 mouseto form a rectangle. Releasing the right button will cause the plot to be zoomed to thatrectangle.

If the Snap To Grid option is on, the largest rectangle formed by the gridlines whichcompletely encloses the rectangle drawn by dragging the mouse, will be the new plotvalues.

3.6.3 Quantization

If OUTPUT/Quantization is selected, the following dialog box is displayed, allowing theselection of either Transpoosed Canonic Second Order Sections, or Canonic Second OrderSections.

FIGURE 3-27 Quantization Option

Realization Type for Cascaded Sections

• Transposed Canonic Second Order SectionsThis 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 output 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:

y n( )

2k---------- bi0

2k------x n( )

wi1 n 1–( )

2k-------------------------+=

Page 55: dsPIC

dsPIC Filter Design Reference Guide Page 3 - 31

(EQ 1)

The output of section i is he input 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. The coefficients of the numerator sections are scaled such that the output of any order that feeds into the numerator coefficients. 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:

(EQ 2)

3.6.4 Create Specification File

The dsPIC FD system allows a filter specification to be saved in a file. If this option isselected, a subsequent dialog box will request the file name. The file will be created withan SPC suffix.

FIGURE 3-28 Filter Specification File

wi1 n( )

2k---------------- bi1

2k------x n( )

ai1

2k------y n( )

wi2 n 1–( )

2k-------------------------+ +=

wi2 n( )

2k---------------- bi2

2k------x n( )

ai2

2k------y n( )+=

wi n( )

2k------------- x n( )

2k---------- ai1

2k------wi n 1–( )

bi1

2k------wi n 1–( )

bi2

2k------wi n 2–( )+ + +=

y n( )

2k---------- bi0

2k------wi n( )

bi1

2k------w n 1–( )

bi2

2k------wi n 2–( )+ +=

Page 56: dsPIC

Page 3 - 32 dsPIC Filter Design Reference Guide

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 isselected, a subsequent dialog box will request the file name. The file will be created withan FLT suffix.

3.6.6 Create Matlab File

To save a filter in Matlab file format, use the following screen:

FIGURE 3-30 Matlab File Specification

Page 57: dsPIC

dsPIC Filter Design Reference Guide Page 3 - 33

3.6.7 Create Plot Data Files

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

FIGURE 3-31 Plot Data Files

Any IIR filter is saved as a product of second order sections. The file format is a matrixof size n x 6 where n is the number of sections. The gain value is absorbed in the firstsection. The file is a pure text file suitable for loading as a text file into Matlab.

FIR filters are saved as a column vector where the order of the column is the filter length,the gain which is normally 1 is absorbed into the coefficients.

Page 58: dsPIC

Page 3 - 34 dsPIC Filter Design Reference Guide

3.7 Code Generation Menu

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

FIGURE 3-32 Code Generation Menu

Page 59: dsPIC

dsPIC Filter Design Reference Guide Page 3 - 35

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 usedas either a subroutine or main program is generated. This C program uses two includefiles: qed_filt.c and qed_cgen.h. The filter routines are in qed_filt.c and the functionprototypes and structure definitions are defined in qed_cgen.h.

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

3.7.3 Microchip dsPIC30 Code Generation

The dsPIC FD system supports optimized assembly language code generation specificallyfor Microchip’s dsPIC30 processor. Select the dsPIC30 option as shown below.

Page 60: dsPIC

Page 3 - 36 dsPIC Filter Design Reference Guide

FIGURE 3-33 Code Generation options

The dsPIC30 FD code generator always creates an assembler file, *.s, where the filenameis specified by the user in the file save dialog box.

This file contains the assembly definition of the filter structure, the filter coefficients anda code fragment showing how to call the generalized filter routine. Assuming that thename 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 beused 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)

These general routines reside in the dsPIC FD setup folder depending on the filter typechosen in dsPIC FD (FIR, IIR Transpose or IIR Canonic). The respective generalsubroutine along with the generated FilterName.s assembly file must be added to theMPLAB Integrated Development Environment (IDE) project. The general subroutineswill use the filter structure and filter coefficients present in the generated FilterName.sfile as inputs.

The C support files option allows creation of a C header file: FilterName.h. This file isautomatically 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 inY space. The coefficient space selection is used to indicate where the coefficients need

Page 61: dsPIC

dsPIC Filter Design Reference Guide Page 3 - 37

to be stored. The generated assembly code structure for the filter has the information onwhether X space or program space is used for coefficients.

Optional Files:

• C Header File: FilterName.hThis 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, FilterName_sim.cmd, FilterName_make.bat This option generates a C program that creates FilterName_imresponse.dat. It also automatically builds the FilterName.h and FilterName_sim.cmd which is the com-mand file for the command line simulator dsPIC30.exe. Run the batch file FilterName_make.bat to assemble, compile, link and execute the command line sim-ulator.

• M-File: FilterName_matlab.m or FilterName_octave.mThis option generates a command file for use in either MATLAB or OCTAVE.

FIGURE 3-34 Examples of Files Created when both C wrapper and M FILE options are selected

The command file will generate a plot of the impulse response and the log magnitudefrequency plot of the filter. The simulator batch file FilterName_sim.cmd must be runbefore executing either *.m file.

This Matlab command file is not the same file generated by Output/Create Matlab File.This file is used to create a frequency response for the impulse response of the filter. Thefile created by Output/Create Matlab File is a data file with filter coefficients only.

The simulator batch file creates FilterName_imresponse.dat. This file is required forexecution of the *.m file.

Page 62: dsPIC

Page 3 - 38 dsPIC Filter Design Reference Guide

FIGURE 3-35 Save dsPIC30 code

The following is an example of a sample code generated for an FIR filter. Note this textis contained at the bottom of the generated assembly file.

FIGURE 3-36 Sample Code

Page 63: dsPIC

dsPIC Filter Design Reference Guide Page 3 - 39

There are three filter routines and three initialization routines. These routine names areshown on the following table:

The transpose IIR routine is the preferred choice for IIR filters (called form 1 in thequantization menu). This routine uses more instructions than the Canonic Routine (Form2). However, it behaves significantly better for filters where the poles are close to the unitcircle.

TABLE 3-5 Table of Filter Routine Names

File Name Filter type Filter Routine Name Input Routine Name

FIR_Filter.s FIR _BlockFIRFilter _FIRFilterInit

IIRT_Filter.s Transposed IIR _BlockIIRTransposeFilter _IIR TransposeFilterInit

IIRC_Filter.s Canonic IIR _BlockIIRCanonicFilter _IIRCanonicInit

Page 64: dsPIC

Page 3 - 40 dsPIC Filter Design Reference Guide

3.8 Window Menu

The WINDOW menu allows selection and control of the graphical displays. A list of allgraphical displays are displayed at the bottom of the menu. The Cascade and Tile optionsare self-explanatory.

FIGURE 3-37 Window Menu

Page 65: dsPIC

dsPIC Filter Design Reference Guide Page 3 - 41

3.8.1 Select Plots

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

FIGURE 3-38 Plot Display Selection

Plots which have been deselected using the Cancel window button can be reselected usingthis 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: hardcopyprintouts are black and white only). The following dialog boxes are provided:

Page 66: dsPIC

Page 3 - 42 dsPIC Filter Design Reference Guide

FIGURE 3-39 Color Selection

FIGURE 3-40 Font Selection

Page 67: dsPIC

dsPIC Filter Design Reference Guide Page 3 - 43

FIGURE 3-41 Line Style Selection

Page 68: dsPIC

Page 3 - 44 dsPIC Filter Design Reference Guide

Page 69: dsPIC

dsPIC Filter Design Reference Guide Page 4 - 1

CHAPTER 4 Addendum

Page 70: dsPIC

Page 4 - 2 dsPIC Filter Design Reference Guide

4.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 71: dsPIC

dsPIC Filter Design Reference Guide Page 4 - 3

4.2 IIR Design Output Example

Following is an example of design output for an IIR Bandpass filter. The various parts areexplained as follows, with arrows denoting the corresponding segments on the exampleshown in Figure 4.1

1. Problem description or filter specification

2. Normalized lowpass transfer function

(EQ 3)

Where N is the number of second order sections.

3. Unnormalized analog transfer function U(s) formed by using analog frequencytransformations for Lowpass to Bandpass in this example

(EQ 4)

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.

(EQ 5)

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.

H z( ) Hdbi0s2 bi1s bi2+ +

s2 a+ i1s ai2+----------------------------------------

i 1=

N

∏=

ss2 ω0

2+Bs

----------------- →

H z( ) Hdbi0z2 bi1 bi2+ +

z2 ai1 ai2+ +--------------------------------------

i 1=

N

∏ Hdbi0 bi1z 1– bi2z 2–+ +( )

1 ai1z 1– ai2z 2–+ +( )----------------------------------------------------

i 1=

N

∏= =

Page 72: dsPIC

Page 4 - 4 dsPIC Filter Design Reference Guide

FIGURE 4-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+006 .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