EE Product News

Migrating to Digital Filters

Know how to design an analog filter but haven't yet tried a digital filter? In this installment of Step-by-Step Design, Microchip Senior Applications Engineer, Rishi Vasuki, shows you how to create a low-pass filter the digital way.

STEP by STEP Design

STEP by STEP Design

 

Migrating to Digital Filters

By Rishi Vasuki, Senior Applications Engineer, Digital Signal Controller Division, Microhip Technology, Inc.

 

The function of a filter is to eliminate unwanted components of the signal (such as random noise) or to extract useful parts of the signal (such as the signal components lying within a certain frequency range). Let’s say you want to design, simulate and deploy a low-pass filter in your circuit. The one thing you probably know up front is the approximate frequency response needed from the low-pass filter. What do you do next? This article describes an approach to designing and simulating digital filters in a matter of minutes. For our example, we’ll use two GUI-based software packages to design, simulate and eventually implement our filter–the dsPIC DSC Filter Design software and dsPICworks data analysis and design software.

 

STEP 1

IDENTIFYING YOUR REQUIREMENTS

Let’s assume you’ve used an analog-to-digital converter to sample an input signal at 12 kHz. You’ve also identified a need to filter out frequencies beyond 3300 Hz from the input signal. To accomplish this, you invoke the dsPIC DSC Filter Design software. The software’s toolbar shows you many ways of starting your filter design process. If, for example, you wish to use an Infinite Impulse Response (IIR) filter, simply click on the "IIR" icon and step through the first dialog box (see Figure 1).

      The "Filter Specification Input" dialog box that appears next requires you to specify what you want the filter to do. The text box labeled "stopband ripple (dB)" allows you to specify the amount of attenuation you would like to apply to the signal in the stopband. The passband and stopband frequencies specify a transition band. If you don’t know how to ensure Nyquist criteria while specifying these frequencies, the tool can help you by popping open a dialog box.

 

FIGURE 1

 

 

STEP 2

EVALUATE YOUR FILTERING OPTIONS

Once you get past the dialog boxes in Figure 1, the filter design software evaluates your filtering requirements and provides an estimate of the filter order for an equivalent analog IIR filter. Since there can be five types of IIR filters, based on their ripple characteristics in the passband and stopband, the software lists out the filter order estimates for all five types of IIR filters (see Figure 2). The tool automatically selects the optimum digital filter implementation for the requirements you specified in Step 1. The optimum filter is typically the one with the lowest order, since the filter order is directly proportional to filter execution time in a DSP implementation. In a few scenarios, such as a closed-loop control system, you may override the automatic selection and choose a Butterworth filter, since you desire a flat response (i.e., no ripple) in both passband and stopband. For our example, we will use the default selection provided by the tool, i.e. the elliptic filter that exhibits equiripple characteristics in the passband and stopband.

 

 

FIGURE 2

 

STEP 3

EXAMINING THE DESIGNED FILTER

After clicking "Next" in Figure 2, the software displays a variety of plots

(see Figure 3). You may use the plots to verify that the software generated a filter that matched the requirements you provided. This is useful, especially if you overrode the default settings in Figure 2. Next, you need to create a filter coefficient file (*.flt) for the purposes of simulating the filter. Figure 3 shows the menu option that is used to save the filter coefficient file. The filter coefficient file contains 16 coefficients required to implement the 8th order Elliptic IIR filter. The coefficients are designed so that the 8th-order filter is implemented as four cascaded stages of 2nd-order filters (popularly known as "biquads").

 

FIGURE 3

 

STEP 4

STIMULATING YOUR FILTER

Now that we have saved our filter coefficients, it’s time to run some data through the filter and examine whether the filter operates as desired. For this purpose, we’ll use the dsPICworks data analysis and design software. This software has the ability to generate or import waveforms, perform various arithmetic and DSP operations (filtering, FFT, etc.) on the waveforms and export them to Windows WAV or ASCII text files. For our example, we’ll generate a signal that has two sinusoidal components at frequencies of 100 Hz and 4300 Hz. The time-domain signal is shown in the top-left region in Figure 4. The bottom-left region in Figure 4 shows the frequency components of the signal. The input signal is run through the filter we designed in steps 1 - 3. The dialog box shown in Figure 4 allows the user to supply an input waveform file, the filter coefficient file, and the file name for the output waveform file. The filtered output signal is shown in the top-right portion of Figure 4. The bottom-right region in Figure 4 shows the frequency components of the filtered output signal. You can safely assume that the filter will perform identically on the actual embedded 16-bit processor, because dsPICworks software performs all computations in 16-bit, fixed-point format.

 

FIGURE 4

 

STEP 5

TRYING OUT OPTIONS FOR "SIZE"

If you’re not satisfied with the designed filter, you can iterate steps 1 through 4 with different choices of filtering, including FIR filters. Remember that we selected IIR filters in Step 1. Typically, IIR filters provide a sharp response without using much data memory. For implementing an 8th-order filter, about 64 bytes is sufficient. FIR filters are quite the opposite, but they are essential in applications that require a linear-phase response. An FIR filter that provides the same response as the IIR filter we designed could consume about 350 bytes of data memory. However, you can decrease this by half if you place the filter coefficients in program memory.

 

STEP 6

RUNNING THE FILTER IN YOUR EMBEDDED SYSTEM

The dsPIC Filter Design software features a code-generator menu that creates a source file containing filter coefficients. Additionally, it provides C-callable IIR and FIR filtering functions in source files that you can drop into your development environment. In addition to these files, you’ll need a C compiler, an in-circuit debugger and a development board to run the designed filters on-chip.

 

Summary

The migration to digital filters has been simplified over time. There are free and low-cost PC-based development tools that enable you to design and simulate filters, and generate code, in a matter of minutes. What’s more, they actually mimic the 16-bit operations performed by the microprocessor. With the level of analog and system integration built in to the digital signal controllers of today, these tools make a compelling case for the migration to digital filters.

Company: MICROCHIP TECHNOLOGY INC.

Product URL: Click here for more information

TAGS: Microchip
Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish