# The “Ins and Outs” of digital filter design and implementation

**Editor’s Note:** *This article first appeared in the Winter 2012 edition of Xilinx's quarterly *Xcell Journal *magazine, and is reproduced here with their kind permission (***Click Here*** to see the magazine).*

Filters are a key part of any signal-processing system, and as modern applications have grown more complex, so has filter design. FPGAs provide the ability to design and implement filters with performance characteristics that would be very difficult to re-create with analog methods. What’s more, these digital filters are immune to certain issues that plague analog implementations, notably component drift and tolerances (over temperature, aging and radiation, for high-reliability applications). These analog effects significantly degrade the filter performance, especially in areas such as passband ripple.

Of course, digital models have their own quirks. The rounding schemes used within the mathematics of the filters can be a problem, as these rounding errors will accumulate, impacting performance by, for example, raising the noise floor of the filter. The engineer can fall back on a number of approaches to minimize this impact, and schemes such as convergent rounding will provide better performance than traditional rounding. In the end, rounding-error problems are far less severe than those of the analog component contribution.

One of the major benefits of using an FPGA as the building block for a filter is the ability to easily modify or update the filter coefficients late in the design cycle with minimal impact, should the need for performance changes arise due to integration issues or requirements changes.**Filter types and topologies **

Most engineers familiar with digital signal processing will be aware that there are four main types of filters. Low-pass filters only allow signals below a predetermined cutoff frequency to be output. High-pass filters are the inverse of the low pass, and will only allow through frequencies above the cutoff frequency. Bandpass filters allow a predetermined bandwidth of frequencies, preventing other frequencies from entering. Finally, band-reject filters are the inverse of the bandpass variety, and therefore reject a predetermined bandwidth while allowing all others to pass through.

Most digital filters are implemented by one of two methods: finite impulse response (FIR) and infinite impulse response (IIR). Let’s take a closer look at how to design and implement FIR filters, which are also often called windowed-sinc filters.

So why are we focusing upon FIR filters? The main difference between the two filter styles is the presence or lack of feedback. The absence of feedback within the FIR filter means that for a given input response, the output of the filter will eventually settle to zero. For an IIR filter subject to the same input which does contain feedback, the output will not settle back to zero.

The lack of feedback within the filter implementation makes the FIR filter inherently stable, as all of the filter’s poles are located at the origin. The IIR filter is less forgiving. Its stability must be carefully considered as you are designing it, making the windowed-sinc filter easier for engineers new to DSP to understand and implement.

If you were to ask an engineer to draw a diagram of the perfect low-pass filter in the frequency domain, most would produce a sketch similar to that shown in Figure 1.

**Figure 1. Ideal low-pass filter performance, with abrupt**

transition from passband to stopband.

transition from passband to stopband.

The frequency response shown in Figure 1 is often called the “brick-wall” filter. That’s because the transition from passband to stopband is very abrupt and much sharper than can realistically be achieved. The frequency response also exhibits other “perfect” features, such as no passband ripple and perfect attenuation within the stopband.

If you were to extend this diagram such that it was symmetrical around 0 Hz extending out to both +/- FS Hz (where FS is the sampling frequency), and perform an inverse discrete Fourier transform (IDFT) upon the response, you would obtain the filter’s impulse response, as shown in Figure 2.

**Figure 2. IDFT or impulse response of the perfect low-pass filter.**

This is the time-domain representation of the frequency response of the perfect filter shown in Figure 1, often called the filter kernel. It is from this response that FIR or windowed-sinc filters get their name, as the impulse response is what is achieved if you plot the sinc function:

Combined with the step response of the filter, these three responses – frequency, impulse and step – provide all the information on the filter performance you need to know to demonstrate that the filter under design will meet the requirements placed upon it.

**Frequency response**

The frequency response is the traditional image engineers consider when thinking about a filter. It demonstrates how the filter modifies the frequency-domain information.

The frequency response allows you to observe the cutoff frequency, stopband attenuation and passband ripple. The roll-off between passband and stopband – often called the transition band – is also apparent in this response. Ripples in the passband will affect the signals being filtered. The stopband attenuation demonstrates how much of the unwanted frequencies remain within the filter output. This can be critical in applications where specific frequency rejection is required, for example when filtering one frequency-division multiplexed channel from another in a communications system.

**Impulse response**

It is from the impulse response that the coefficients for your filter are abstracted. However, to achieve the best performance from your filter, the standard practice is to use a windowing function. Windowing is the technique of applying an additional mathematical function to a truncated impulse response to reduce the undesired effects of truncation.

Figure 2 demonstrates the impulse response extending out infinitely with ripples which, though they diminish significantly in amplitude, never settle at zero. Therefore, you must truncate the impulse response to N + 1 coefficients chosen symmetrically around the center main lobe, where N is the desired filter length (please remember that N must be an even number). This truncation affects the filter’s performance in the frequency domain due to the abrupt cutoff of the new, truncated impulse response. If you were to take a discrete Fourier transform (DFT) of this truncated impulse response, you would notice ripples in both the passband and stopband along with reduced roll-off performance. This is why it is common practice to apply a windowing function to improve the performance.

**Step response**

The step response, which is obtained by integrating the impulse response, demonstrates the time-domain performance of the filter and how the filter itself modifies this performance. The three parameters of importance when you are observing the step response are the rise time, overshoot and linearity.

The rise time is the number of samples it takes to rise between 10 percent and 90 percent of the amplitude levels, demonstrating the speed of the filter. To be of use within your final system, the filter must be able to distinguish between events in the input signal; therefore, the step response must be shorter than the spacing of events in the signal.

Overshoot is the distortion that the filter adds to the signal as it is processing it. Reducing the overshoot in the step response allows you to determine if the signal distortion results from either the system or the information that it is measuring. Overshoot reduces the uncertainty of the source of the distortion, degrading the final system performance, and possibly means the system does not meet the desired performance requirements.

If the signal’s upper and lower halves are symmetrical, the phase response of the filter will have a linear phase, which is needed to ensure the rising edge and falling edge of the step response are the same.

It is worth nothing at this point that it is very difficult to optimize a filter for good performance in both the time and frequency domains. Therefore, you must understand which of those domains contains the information you are required to process. For FIR filters, the information required is within the frequency domain. Therefore, the frequency response tends to dominate.

Windowing the filter

Windowing the filter

Using a truncated impulse response will not provide the best-performing digital filter, as it will demonstrate none of the ideal characteristics. For this reason, designers use windowing functions to improve the passband ripple, roll-off and stopband attenuation performance of the filter. There are many window functions that you can apply to the truncated sinc, for example Gaussian, Bartlett, Hamming, Blackman and Kaiser – the list goes on. However, two of the most popular window functions are the Hamming and Blackman. Let’s explore them in more detail.

Both of these windows, when applied, reduce the passband ripple and increase the roll-off and attenuation of the filter. Figure 3 shows the impulse and frequency responses for a truncated sinc, and with Blackman and Hamming windows applied.

**Figure 3. Low-pass filter impulse responses (top chart)**

and frequency responses

and frequency responses

As you can see, both windows significantly improve the passband ripple. The roll-off of the filter is determined not only by the window but by the length of the filter – that is, the number of coefficients, often called filter taps.

Where

**i**runs from 0 to N, providing a total of N + 1 points.

To apply these windows to the truncated impulse response, you must multiply the window coefficients with the truncated impulse response coefficients to produce the desired filter coefficients.

While the window type determines the roll-off frequency, a rule of thumb is that for a desired transition bandwidth the number of taps required is indicated by N = 4 / BW, where BW is the transition bandwidth.

**Figure 4. High-pass filter impulse response (top) and frequency response using spectral**

**inversion, with nonwindowed, and Hamming and Blackman windows applied.**

**Implementing different filter topologies**

No matter what the end type of filter – bandpass, band reject or high pass – all of these start out with the initial design of a low-pass filter. If you know how to create a low-pass filter and a high-pass filter, you can then use combinations of the two to produce band-reject and bandpass filters.

Let’s first examine how to convert a low-pass filter into a high-pass one. The simplest method, called spectral inversion, changes the stopband into the passband and vice versa. You perform spectral inversion by inverting each of the samples while at the same time adding one to the center sample. The second method of converting to a high-pass filter is spectral reversal, which mirrors the frequency response; to perform this operation, simply invert every other coefficient.

Having designed the low- and high-pass filters, it’s easy to make combinations that you can use to generate bandpass and band-reject filters. To generate a band-reject filter, just place a high-pass and a low-pass filter in parallel with each other and sum together the outputs. You can assemble a bandpass filter, meanwhile, by placing a low-pass and a high-pass filter in series with each other.

**And now for the design**

The information we’ve reviewed so far details what windowed-sinc filters are, the importance of windowing and how to generate filters of different topologies. However, before you can implement your filter within an FPGA, you must generate a set of filter coefficients using one of several software tools, such as Octave, MATLAB, or even Excel. Many of these tools provide simplified interfaces and options, allowing you to design the filter with minimal effort, the FDA tool in MATLAB being a prime example.

Having generated a set of coefficients for the desired filter, you are ready to implement your filter within the FPGA. No matter the number of taps you have decided on, the basic structure of each stage of the FIR filter will be the same and will consist of a multiplier, storage and adder.

The method most engineers prefer, and the one that’s by far the simplest, is to use the Xilinx CORE Generator tool’s FIR Compiler, which provides multiple options for customizing and for generating advanced filters. You can import the generated coefficients into the FIR Compiler as a COE file; this file will contain the coefficients for the filter with the radix also being declared.

Once you have loaded these coefficients, FIR Compiler will display the frequency response of the filter for the coefficients provided, along with basic performance characteristics such as stopband attenuation and passband ripple.

Once you have completed your customization of the filter using the FIR Compiler tool, CORE Generator will produce all the necessary files to both implement the design and to simulate it during behavioral simulation prior to implementation, provided the user has access to the correct simulation libraries.

**Figure 5. Xilinx CORE Generator frequency responses:**

From the top: truncated sinc, Blackman window, Hamming

window, and Hamming-windowed high-pass filter

From the top: truncated sinc, Blackman window, Hamming

window, and Hamming-windowed high-pass filter

If you prefer, you can also implement the filter in HDL you have generated yourself. This will often be the choice if your final implementation will be in an ASIC and you are using the FPGA implementation as a prototyping system. In this case, the first step is to quantize the filter coefficients to use a fixed-number representation of the floating-point results. As the filter coefficients will represent positive and negative numbers, it is common practice to represent these in a two’s complement format. Once these coefficients have been quantized, you can use them as constants within the HDL design.

Digital filters find their way into many applications these days, and FPGAs offer a significant advantage to the system designer who needs to use them. Windowed-sinc filters are very simple to design and implement using basic math tools along with either FPGA core-generation tools or directly in HDL.

**About the author**

Adam P. Taylor is a Principal Engineer at

**EADS Astrium**__. You can contact Adam via email at__

**aptaylor@theiet.org**If you found this article to be of interest, visit

**Programmable Logic Designline**where you will find the latest and greatest design, technology, product, and news articles with regard to programmable logic devices of every flavor and size (FPGAs, CPLDs, CSSPs, PSoCs...).

Also, you can obtain a highlights update delivered directly to your inbox by signing up for my weekly newsletter – just

**Click Here**to request this newsletter using the Manage Newsletters tab (if you aren't already a member you'll be asked to register, but it's free and painless so don't let that stop you [grin]).

Author

juergen.schuhmacher_#1 3/3/2012 10:43:20 PM

Author

Adam-Taylor 3/4/2012 5:51:10 PM