filter design for dspic dsc digital filter design and analysis system

82
Filter Design for dsPIC DSC Digital Filter Design and Analysis System Momentum Data Systems, Inc.

Upload: others

Post on 12-Sep-2021

11 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

Filter Design for dsPIC™ DSC

Digital Filter Design and Analysis System

Momentum Data Systems, Inc.

Page 2: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

Copyright/Trademark Information

Copyright 2008 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: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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

Page 4: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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.

Page 5: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

Filter Design for dsPIC™ DSCTable of contents

Chapter 1 - Introduction1.1 Design Capabilities 1-21.2 General System Features. 1-41.3 Installation 1-5

1.3.1 Application Software Installation 1-5

1.4 Input Specifications 1-61.5 Design Methods 1-71.6 System Operation 1-8

Chapter 2 - Examples2.1 IIR Lowpass 2-22.2 IIR Bandpass 2-52.3 FIR Lowpass 2-72.4 Equiripple FIR Lowpass 2-102.5 Using a dsPICfd Filter in dsPICworks 2-12

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‘ FD Filter Design 3-11

3.3 View Menu 3-123.3.1 Toolbar 13-23.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-243.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 Plot Data Files 3-33

3.7 Code Generation Menu 3-34

Page 6: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

3.7.1 Create C Code 3-353.7.2 C Code File Generation 3-353.7.3 Microchip dsPIC30F/33F Code Generation 3-35

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

Chapter 4 - Filter Coefficient Files4.1 IIR FILTER COEFFICIENT FILES 4-2

4.1.1 General Discussion on Cascaded Biquad Sections 4-34.1.2 Fractional Fixed Point Cascaded Biquad Sections 4-5

4.2 FIR FILTER COEFFICIENT FILE 4-9Chapter 5 - Addendum

5.1 References 5-25.2 IIR Design Output Example 5-3

Page 7: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

CHAPTER 1 Introduction to Filter Design for Microchip Technology dsPIC30F/dsPIC33F

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

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

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

dsPIC Filter Design Reference Guide Page 1 - 1

Page 8: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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

Page 9: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

–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

Page 10: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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

Page 11: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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.

For dsPICFD:

<drive>:\dsPICFD.msi

For dsPICFDLite:

<drive>:\dsPICFDLite.msi

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

dsPIC Filter Design Reference Guide Page 1 - 5

Page 12: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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.

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 requiredfor 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) .

1.0

1-δ1

Frequency

δ2

Page 1 - 6 dsPIC Filter Design Reference Guide

Page 13: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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)

dsPIC Filter Design Reference Guide Page 1 - 7

Page 14: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

1.6 System Operation

The dsPICFD 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.0, and 5E03 are all equallyacceptable forms of input.

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

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

or for dsPICFDlite use:

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

Page 1 - 8 dsPIC Filter Design Reference Guide

Page 15: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

CHAPTER 2 dsPIC Filter Design Examples

The authors of dsPICFD 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)

dsPIC Filter Design Reference Guide Page 2 - 1

Page 16: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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, thepassband frequency is set at 800Hz and the stopband frequency is set to 1600 Hz. Notethat for a lowpass filter the stopband frequency must be greater than the passbandfrequency 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 ). Theripple values are all specified as positive values. The passband value must be < thestopband value. Typical passband values are 0.1 to 3 dB. Typical stopband values are40dB or greater.

Page 2 - 2 dsPIC Filter Design Reference Guide

Page 17: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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.

dsPIC Filter Design Reference Guide Page 2 - 3

Page 18: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

FIGURE 2-3 System Responses for Example 1

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

Page 2 - 4 dsPIC Filter Design Reference Guide

Page 19: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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 willbe significantly more efficient than other analog prototypes. In general, unless one hasa specific reason for picking a different analog prototype, the Ellliptic filer prototype should be used for IIR filter design.

FIGURE 2-5 Select Analog Prototype and Filter Order

dsPIC Filter Design Reference Guide Page 2 - 5

Page 20: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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 characteristicof all IIR filters that are generated using the elliptical design

Page 2 - 6 dsPIC Filter Design Reference Guide

Page 21: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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.

The frequencies are specified in Hertz. The sampling frequency is set at 5000 Hz, thepassband frequency is set at 800Hz and the stopband frequency is set to 1600 Hz. Notethat for a lowpass filter the stopband frequency must be greater than the passbandfrequency 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 ). Theripple values are all specified as positive values. The passband value must be < thestopband value. Typical passband values are 0.1 to 3 dB. Typical stopband values are40dB or greater.

dsPIC Filter Design Reference Guide Page 2 - 7

Page 22: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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 2 - 8 dsPIC Filter Design Reference Guide

Page 23: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

FIGURE 2-9 System Responses for Example 3

An FIR filter has ripples in both the passband and stopband. The ripples in the stopbandare easily seen in the magnitude plot. The ripples in the passband can be seen by zoomingin 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-symmetriccoefficients, then the group delay is not a constant.

dsPIC Filter Design Reference Guide Page 2 - 9

Page 24: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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. The FIR design uses the smallestripple value. This is almost always the stopband ripple. Hence, the FIR design withwindows 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

Page 25: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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.

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

dsPIC Filter Design Reference Guide Page 2 - 11

Page 26: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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

Page 27: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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

dsPIC Filter Design Reference Guide Page 3 - 1

Page 28: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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 3 - 2 dsPIC Filter Design Reference Guide

Page 29: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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

dsPIC Filter Design Reference Guide Page 3 - 3

Page 30: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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.

Page 3 - 4 dsPIC Filter Design Reference Guide

Page 31: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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

dsPIC Filter Design Reference Guide Page 3 - 5

Page 32: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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 3 - 6 dsPIC Filter Design Reference Guide

Page 33: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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.

dsPIC Filter Design Reference Guide Page 3 - 7

Page 34: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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 3 - 8 dsPIC Filter Design Reference Guide

Page 35: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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

Page 36: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

• 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

Page 37: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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

dsPIC Filter Design Reference Guide Page 3 - 11

Page 38: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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

Page 39: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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

dsPIC Filter Design Reference Guide Page 3 - 13

Page 40: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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 3 - 14 dsPIC Filter Design Reference Guide

Page 41: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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

dsPIC Filter Design Reference Guide Page 3 - 15

Page 42: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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 3 - 16 dsPIC Filter Design Reference Guide

Page 43: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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 baseband 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.

dsPIC Filter Design Reference Guide Page 3 - 17

Page 44: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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 3 - 18 dsPIC Filter Design Reference Guide

Page 45: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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 -6Triangular -27.31 25.70 -12Hanning -31.47 43.94 -18Hamming -43.19 54.17 -6Blackman -58.11 75.29 -18Exact Blackman -68.20 85.57 -63 Term Cosine -62.05 79.16 -63 Term Cosine with Continuous 3rd Derivative

-46.74 61.36 -30

Minimum 3 Term Cosine -71.48 86.40 -64 Term Cosine -74.39 87.78 -64 Term Cosine with Continuous 5th Derivative

-60.95 77.03 -42

Minimum 4 Term Cosine -98.17 115.55 -6Harris Flat Top -80.05 97.03 -6Good 4 Term Blackman Harris -81.76 99.78 -6Kaiser Selectable

SelectableSelectableSelectable

-6Dolph-Tschebyscheff 0Taylor 0Gaussian -6

dsPIC Filter Design Reference Guide Page 3 - 19

Page 46: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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 3 - 20 dsPIC Filter Design Reference Guide

Page 47: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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

Page 48: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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 3 - 22 dsPIC Filter Design Reference Guide

Page 49: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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.

dsPIC Filter Design Reference Guide Page 3 - 23

Page 50: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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 orattenuation 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 3 - 24 dsPIC Filter Design Reference Guide

Page 51: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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

dsPIC Filter Design Reference Guide Page 3 - 25

Page 52: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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 3 - 26 dsPIC Filter Design Reference Guide

Page 53: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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

Page 54: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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 3 - 28 dsPIC Filter Design Reference Guide

Page 55: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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 RangeFrequency 0 to fs/2

Magnitude 0 to 1

Log Magnitude -100 to 0

Number of time steps 300

dsPIC Filter Design Reference Guide Page 3 - 29

Page 56: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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 Transposed Canonic Second Order Sections, or Canonic Second OrderSections.

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

Page 57: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

(EQ 1)

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 SectionsCascaded 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:

(EQ 2)

3.6.4 Create Specification File

The dsPICFD 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.

y n( )

2k----------

bi0

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

wi1 n 1–( )

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

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–( )

ai2

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

y n( )

2k----------

bi0

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

bi1

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

bi2

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

dsPIC Filter Design Reference Guide Page 3 - 31

Page 58: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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

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

Page 3 - 32 dsPIC Filter Design Reference Guide

Page 59: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

3.6.6 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-30 Plot Data Files

dsPIC Filter Design Reference Guide Page 3 - 33

Page 60: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

3.7 Code Generation Menu

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

FIGURE 3-31 Code Generation Menu

Page 3 - 34 dsPIC Filter Design Reference Guide

Page 61: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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 dsPIC30F/33F Code Generation

The dsPIC FD system supports optimized assembly language code generation specificallyfor Microchip’s dsPIC30F/33F processor. Select thedsPIC30F/33F option as shownbelow.

FIGURE 3-32 Code Generation options

dsPIC Filter Design Reference Guide Page 3 - 35

Page 62: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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

This assembly file contains the assembly definition of the filter structure, the filtercoefficients 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 generatedassembly 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)• 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 typechosen (FIR, IIR Transpose, IIR Canonic or IIR Canonic Extended Precision). Therespective general subroutine along with the generated <FilterName>.s assembly filemust be added to the MPLAB Integrated Development Environment (IDE) project. Thegeneral subroutines will use the filter structure and filter coefficients present in thegenerated FilterName.s file as inputs.

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

Page 63: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

The following dialog box is displayed after the code generation option dialog box isdisplayed. 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

Page 64: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

The following is an example of a sample code generated for a transposed IIR Filter. Notethat the text contained at the bottom of the generated assembly file shows how to use thefilter 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,xmemoryTestCGCoefs:.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, ymemoryTestCGStates1: .space TestCGNumSections*2TestCGStates2: .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 programSet 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

Page 65: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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

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 theCanonic Routine (Form 2). However, it behaves significantly better for filters where thepoles 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 takessignificantly more clock cycles than any 16-bit filter implementation. This filter imple-mentation uses the same difference equations as the CanonicIIR filter. Note, this optionis not available for the dsPICFDLITE system.

These routines have the same calling sequence, filter names and structure names as theDSP 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 thefilter files described in Table 3.5.

In the event of Case 2), just add the generated C Header file. The MPLAB plugin mayhave 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 byfollowing 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 CanonicIIRroutine. The supplied routine must be used for this capability. Also note that this capabilityis not available for dsPICFdlite.

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_FilterExtendedPrecision.s

Canonic IIR _IIRCanonicExtendedPrecision.s

_IIRCanonicExtendedPrecision

32

dsPIC Filter Design Reference Guide Page 3 - 39

Page 66: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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-35 Window Menu

Page 3 - 40 dsPIC Filter Design Reference Guide

Page 67: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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

dsPIC Filter Design Reference Guide Page 3 - 41

Page 68: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

FIGURE 3-37 Color Selection

FIGURE 3-38 Font Selection

Page 3 - 42 dsPIC Filter Design Reference Guide

Page 69: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

FILTER COEFFICIENT FILE

CHAPTER 4 FILTER COEFFICIENT FILE

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

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

dsPIC Filter Design Reference Guide Page 4 - 1

Page 70: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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 - cascadedbiquad sections

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

Page 4 - 2 dsPIC Filter Design Reference Guide

Page 71: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

FILTER COEFFICIENT FILE IIR FILTER COEFFICIENT FILES

4.1.1 General Discussion on Cascaded Biquad Sections

Let

(EQ 1)

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

(EQ 2)

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 2time periods. The denominator coefficients have been complemented to allow adds inthe difference equation. First order sections are treated as second order sections bymultiplying both the numerator and denominator by z or in effect, setting the second orderdelays to zero.

In converting from the floating point to fixed point format, the number of bits is used todetermine the number of significant positions in the fraction. Then bi0, bi1, bi2 are forcedto 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 exponentvalue 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 thenumber is greater than 1. Coefficient ai0 is assumed to have a value of 1.0. Denominatorshift counts are normally greater than or equal to zero.

To actually implement a biquad section in a DSP microprocessor, the coefficients mustbe in fractional form. The coefficients in the fixed point format record are in fractionalformat even if their actual value is greater than 1. This can be visualized best byconsidering the fixed point format of the coefficients to be a block floating point with thefractional values stored in the rightmost hexadecimal digits and the shift count residingin 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 fractionalvalues prior to accumulating intermediate sums. This can be done by ensuring that eachoperand in a sum has the same shift count or exponent. The final output of biquad sectionsshould have a shift count of 0 to avoid scaling in the subsequent biquad section.

H z( ) Hdbi0z2 bi1z bi2+ +

ai0z2 ai1z ai2+ +----------------------------------------

i 1=

N

∏=

H z( ) Hdbi0 bi1z 1– bi2z 2–+ +

ai0 ai1z 1– ai2z 2–+ +-----------------------------------------------

i 1=

N

∏=

dsPIC Filter Design Reference Guide Page 4 - 3

Page 72: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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 thedifference equations for implementing cascaded second order sections in cascaded formI (Transpose) are:

(EQ 3)

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

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

(EQ 4)

y n( ) bi0x n( ) wi1 n 1–( )+=wi1 n( ) bi1x n( ) ai2y n( ) wi2 n 1–( )+ +=

wi2 n( ) bi2x n( ) ai2y n( )+=

wi n( ) x n( ) ai1wi n 1–( ) ai2wi n 2–( )+ +=y n( ) bi0wi n( ) bi1wi n 1–( ) bi2wi n 2–( )+ +=

Page 4 - 4 dsPIC Filter Design Reference Guide

Page 73: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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 thefollowing exception: all coefficients except ai0 have initially been scaled so that theabsolute value of the coefficient is less than 1.0. The largest coefficient in absolute valuehas the maximum precision allowed. Coefficients with smaller absolute values may havefewer bits to represent them. If the shift count is zero then the difference equations canbe used as specified in Section 4.1.1 .

The binary points must be aligned prior to the addition of two values. This means thatshift counts must be identical for this operation. While the filter is designed so that thefinal gain is 0dB or the maximum range is -1 to +1, filter coefficients can be greater than1.0 and intermediate results can be greater than 1.0. Coefficients are divided by a powerof 2 (i.e. 21, 22, 23, etc.) until the coefficients are less than 1.0. The power of 2 is the shiftcount. The numerator values have been rescaled to prevent or minimize overflow. Thisrescaling 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 1for certain values particularly if cascaded canonic form II is used.

This discussion implies using intermediate shifts for implementation of the differenceequations. This may not, however, be necessary. It depends on how the differenceequations are implemented.

Cascaded Transpose (Form I)

A positive shift count k for a section means that the difference equations for form I areactually as follows:

(EQ 5)

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 aleft shift of k bits and this value is used for the y(n) computations as well as for input tothe next section as x(n). The ai1 and ai2 have been complemented in the FLT file so anadd instead of a subtract is used. Hd, the overall gain, is normally 1.0 and can, therefore,be ignored.

y n( )

2k----------

bi0

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

wi1 n 1–( )

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

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( )+=

dsPIC Filter Design Reference Guide Page 4 - 5

Page 74: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

IIR FILTER COEFFICIENT FILES FILTER COEFFICIENT FILE

Cascaded Canonic (Form II)

The difference equations for form II are:

(EQ 6)

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 and2 respectively.

For Form II this is the scale down factor for the incoming sample. To find the actual valueof the scale down factor, just shift the overall gain value by the shift count. If the shiftcount 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 eachsection shows the power of 2 that was needed to get the absolute value of each coefficientless 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 floatingpoint numbers. The first column is the floating point equivalent of the fixed pointcoefficients. The second column is the hexadecimal value of the quantized floating pointcoefficients. The third column is the original coefficients and hence may have values >1.0in absolute value.

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

FILTER COEFFICIENT FILEIIR DESIGNFILTER TYPE LOW PASSANALOG FILTER TYPE INVERSE TSCHEBYSCHEFFPASSBAND RIPPLE IN -dB -.1111E+00STOPBAND RIPPLE IN -dB -.4444E+02PASSBAND CUTOFF FREQUENCY 0.100000E+01 HertzSTOPBAND CUTOFF FREQUENCY 0.200000E+01 HertzSAMPLING FREQUENCY 0.800000E+01 Hertz

wi n( )

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

2k----------

ai1

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

ai2

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

y n( )

2k----------

bi0

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

bi1

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

bi2

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

Page 4 - 6 dsPIC Filter Design Reference Guide

Page 75: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

FILTER COEFFICIENT FILE IIR FILTER COEFFICIENT FILES

FILTER DESIGN METHOD: BILINEAR TRANSFORMATIONFILTER ORDER 5 5hNUMBER OF SECTIONS 3 3hNO. OF QUANTIZED BITS 16 10hQUANTIZATION TYPE - FRACTIONAL FIXED POINTCOEFFICIENTS 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 FILEIIR DESIGNFILTER TYPE LOW PASSANALOG FILTER TYPE TSCHEBYSCHEFFPASSBAND RIPPLE IN -dB -.1111E+00STOPBAND RIPPLE IN -dB -.4444E+02PASSBAND CUTOFF FREQUENCY 0.100000E+01 Hertz

dsPIC Filter Design Reference Guide Page 4 - 7

Page 76: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

IIR FILTER COEFFICIENT FILES FILTER COEFFICIENT FILE

STOPBAND CUTOFF FREQUENCY 0.200000E+01 HertzSAMPLING FREQUENCY 0.800000E+01 HertzFILTER DESIGN METHOD: BILINEAR TRANSFORMATIONFILTER ORDER 5 5hNUMBER OF SECTIONS 3 3hNO. OF QUANTIZED BITS 16 10hQUANTIZATION TYPE - FRACTIONAL FIXED POINTCOEFFICIENTS 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

Page 77: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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:

(EQ 7)

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 tapsin decimal, hexadecimal and number of bits in quantized coeffiicients. Lines 8 and 9 areessentially the overall gain factor. The next N lines are the quantized coefficients withthe first column being the decimal form and the second column the hexadecimal form ofthe coefficient. The next N lines are the quantized coefficients in floating point form withcolumn 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 FILEFIR 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 */

y n( ) h i( )x n i–( )

i 0=

N

∑=

dsPIC Filter Design Reference Guide Page 4 - 9

Page 78: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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

Page 79: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

CHAPTER 5 Addendum

dsPIC Filter Design Reference Guide Page 5 - 1

Page 80: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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

Page 81: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

5.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 8)

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

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

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

∏= =

dsPIC Filter Design Reference Guide Page 5 - 3

Page 82: Filter Design for dsPIC DSC Digital Filter Design and Analysis System

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

Page 5 - 4 dsPIC Filter Design Reference Guide