DSP Algorithms for RF Systems

Trending

Buy the Book!

DSP for Beginners: Simple Explanations for Complex Numbers! The second edition includes a new chapter on complex sinusoids.

FIR Low Pass Filter Design with Remez
September 22, 2021

Table of Contents

Introduction

The focus of this blog is to describe the low pass filter design process with the remez() function, which is one of many ways to create FIR filter weights. The filter parameters of:

  • filter length,
  • pass-band,
  • stop-band,
  • cut-off frequency,
  • transition bandwidth,
  • and sidelobe attenuation

will be discussed, including their impact on the frequency response and how their trade-offs effect the design.

I’d also suggest taking a look at fred harris’ Multirate Signal Processing text [harris2021, p.55-82] which has a great chapter on the Remez algorithm.

More blog posts on filter design:

scipy.signal.remez()

The Remez design function can be found in the Python scipy package. The description can be found here: https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.remez.html

The function call is

scipy.signal.remez(numtaps, bands, desired, weight=None, Hz=None, type='bandpass', maxiter=25, grid_density=16, fs=None)

The three parameters of interest for now are numtaps, bands and desired. The parameter numtaps is simply the length of the filter.

The bands parameter and desired parameter work together to describe the frequencies and amplitudes of the filter’s magnitude response. Figure 1 gives an example of how the bands and desired parameters can be set for a low-pass filter. For the low-pass case, the values bands[1] is referred to as the pass-band frequency and bands[2] as the stop-band frequency.

The focus of this blog is to describe the low pass filter design process with the remez() function, which is one of many ways to create FIR filter weights. The filter parameters of:

  • filter length,
  • pass-band,
  • stop-band,
  • cut-off frequency,
  • transition bandwidth,
  • and sidelobe attenuation

will be discussed, including their impact on the frequency response and how their trade-offs effect the design.

I’d also suggest taking a look at fred harris’ Multirate Signal Processing text [harris2021, p.55-82] which has a great chapter on the Remez algorithm.

More blog posts on filter design:

Figure 1: An example of how to set the bands and desired parameters when designing a LPF in remez().

The bands define the edges of the response as a frequency vector, named freqVec below and where desired sets the amplitude of the response, named ampVec. The code for the filter parameters in Figure 1 is as follows:

import scipy.signal
filterLength = 21
fPass = 0.2
fStop = 0.3
freqVector = [0, fPass, fStop, 0.5]
ampVector = [1, 0]
remezFilter = scipy.signal.remez(filterLength,freqVector,ampVector)

Example FIR Low Pass Filter Design

Starting with a filter length (numtaps) of 21 will make it easier to see how the other parameters effect the filter frequency response. Running the code creates a filter with the impulse response in Figure 2 and frequency response in Figure 3. The impulse response in Figure 2 correctly shows 21 total weights which is the desired length of the filter numtaps.

Figure 2: The impulse response of the remez() designed FIR filter.
Figure 2: The impulse response of the remez() designed FIR filter.
Figure 3: The freqVector and ampVector points overlaid on the magnitude of the frequency response of the remez() designed FIR low pass filter.
Figure 3: The freqVector and ampVector points overlaid on the magnitude of the frequency response of the remez() designed FIR low pass filter.

As expected the designed magnitude response in Figure 3 goes approximately through the locations defined by both freqVec and ampVec. The magnitude of a frequency response is typically viewed in decibels, through the relationship

(1)   \begin{equation*}10\text{log}_{10} ( |X[k]|^2 ) = 20\text{log}_{10}( |X[k]| ),\end{equation*}

where X[k] is the frequency response. Note that when the magnitude in the frequency domain is displayed it is most commonly the magnitude-squared as in (1), as in Figure 4.

Figure 4: The magnitude of the frequency response from Figure 2 plotted in dB.
Figure 4: The magnitude of the frequency response from Figure 2 plotted in dB.

Designing with Cut-off Frequency and Transition Bandwidth

An alternative to designing the filter based on the pass-band and stop-band frequencies is defining a cut-off frequency and a transition bandwidth. The transition bandwidth is the difference between the stop-band frequency and the pass-band frequency. The cut-off frequency is typically designed to be at a magnitude of (equivalently) 0.5 in linear magnitude, 3 dB in dB-magnitude, or 6 dB in dB-magnitude squared. Note that the filter frequency response passes through each of these points in Figure 1, Figure 3 and Figure 4.

The code for designing based on the cutoff frequency is as follows:

import scipy.signal
filterLength = 21
fCutoff = 0.25
fTransitionBandwidth = 0.1
fPass = fCutoff - (fTransitionBandwidth/2)
fStop = fCutoff + (fTransitionBandwidth/2)
freqVector = [0, fPass, fStop, 0.5]
ampVector = [1, 0]
remezFilter = scipy.signal.remez(filterLength,freqVector,ampVector)

Effects of Low Pass Filter Parameters

What happens when the cut-off frequency is changed? Figure 5 gives three examples for different cutoff frequencies with the same transition bandwidth and filter length. Figure 6 zooms into the pass-band of the same filters.

Figure 5: All of the filters have the same stop-band attenuation even when the cut-off frequency is changed.
Figure 6: A zoom to the pass-band for Figure 5. All of the filters have the same pass-band ripple when the cut-off frequency is changed.
Figure 6: A zoom to the pass-band for Figure 5. All of the filters have the same pass-band ripple when the cut-off frequency is changed.

Figure 5 and Figure 6 shows changing the cut-off frequency changes the relative proportion of the pass-band and the stop-band of the filter but has no impact on either the pass-band ripple or stop-band attenuation.

However, holding the cut-off frequency constant and changing the transition bandwidth will impact the pass-band ripple and stop-band attenuation as seen in Figure 6 and Figure 7.

Figure 7: Changing the transition bandwidth while holding the filter length and cut-off frequency constant will have impacts on the stop-band attenuation.
Figure 7: Changing the transition bandwidth while holding the filter length and cut-off frequency constant will have impacts on the stop-band attenuation.
Figure 8: A zoom to the pass-band of Figure 7.
Figure 8: A zoom to the pass-band of Figure 7.

From Figure 7 and Figure 8 it can be seen that a larger transition bandwidth results in both smaller pass-band ripple as well as larger stop-band attenuation. Why?

Low Pass Filter Length Estimate

fred harris’ filter length approximation [harris2021, p.59] is

(2)   \begin{equation*}L = \frac{A_{dB} \cdot f_s}{22 \cdot \Delta f},\end{equation*}

where \Delta f is the transition bandwidth, f_s is the sampling frequency and A_{dB} is the sidelobe attenuation in dB. The frequencies \Delta f and f_s can be in any units as long as they are consistent.

The approximation in (2) shows that changes to the transition bandwidth will directly impact the sidelobe attenuation when the filter length is held constant. However the cut-off frequency has no impact which reinforces the earlier filters from Figures 4 – 8.

Using the parameters from Figure 7, A_{dB}=39 and f_s=1, the filter length for a transition bandwidth of \Delta f = 0.1 is approximated to be

(3)   \begin{equation*}\frac{39 \cdot 1}{22 \cdot 0.1} \approx 17.\end{equation*}

Similarly from Figure 7, the second filter with \Delta f = 0.15 and A_{dB} = 54 gives a filter length approximation of

(4)   \begin{equation*}\frac{54 \cdot 1}{22 \cdot 0.15} \approx 16,\end{equation*}

and the second filter with \Delta f = 0.2 and A_{dB} = 70 gives a filter length approximation of

(5)   \begin{equation*}\frac{70 \cdot 1}{22 \cdot 0.2} \approx 16.\end{equation*}

The filter lengths are not exact but are reasonably close to the length L=21 the filter was designed with. It is typical for filter design to be an iterative “guess and check” process until the exact desired weights or frequency response is obtained.

Increasing Filter Length

More sidelobe attenuation can be obtained by increasing the filter length. Figure 9 and Figure 10 show the magnitudes of the frequency responses for filters with multiple lengths.

Figure 9: Increasing the filter length results in more sidelobe attenuation at the cost of more computation.
Figure 9: Increasing the filter length results in more sidelobe attenuation at the cost of more computation.
Figure 10: A zoom of Figure 9. Increasing the filter length results in more less pass-band ripple at the cost of more computation.
Figure 10: A zoom of Figure 9. Increasing the filter length results in more less pass-band ripple at the cost of more computation.

Trade-Offs

A great filter will have:

  • a short length to reduce computation,
  • a small transition band to maximize the amount of pass-band and stop-band,
  • small pass-band ripple and large stop-band attenuation.

However, due to (2) a filter cannot have all three of these attributes and design trade-offs must be made. Figure 11 and Figure 12 show the example filter with L=21 and \Delta f = 0.1 which has sidelobes at -39 dB and a pass-band ripple of 0.2 dB. The two other filters increase the sidelobe attenuation to about -70 dB by two different methods: doubling the transition bandwidth and doubling the filter length.

Figure 11: The sidelobe attenuation can be increased by increasing the transition bandwidth, increasing the filter length, or both.
Figure 11: The sidelobe attenuation can be increased by increasing the transition bandwidth, increasing the filter length, or both.
Figure 12: The pass-band ripple can be decreased by increasing the transition bandwidth, increasing the filter length, or both.
Figure 12: The pass-band ripple can be decreased by increasing the transition bandwidth, increasing the filter length, or both.

Increasing the filter length comes with the cost of more computation required to operate the filter which translates into:

  • faster processor or FPGA,
  • more heat,
  • more cost,
  • or lower system sampling rate.

Alternatively, increasing the transition bandwidth translates into:

a smaller pass-band,
a smaller stop-band,
and thus more undesired high-frequency content at the output of the filter.

Designing the filter weights requires balancing all of the different parameters in order to meet the specifications or application needs. For example some real-time applications may require a a smaller filter and can allow for worse sidelobes in order to operate at a high sampling rate, whereas other off-line applications can allow for longer filters to get the best possible sidelobe levels and small transition bandwidth.

Conclusion

Remez is a powerful tool for quickly designing FIR filter weights. A low-pass filter is designed by remez() by specifying the filter length, stop-band and pass-band frequencies as well as the amplitudes for the pass-band and stop-band. Alternatively, the cut-off frequency and transition bandwidth can be specified in the design. Increasing the transition bandwidth is an effective way for reducing the filter length or increasing the sidelobe attenuation. Similarly, a longer filter will require more computation but will have better attenuation or a smaller transition bandwidth. Trade-offs between all of the parameters will have to be made in order to make the best design that fits the application.

Be sure to check out these other posts on filter design!

Leave a Reply

For everything there is a season, and a time for every matter under heaven. A time to cast away stones, and a time to gather stones together. A time to embrace, and a time to refrain from embracing. Ecclesiastes 3:1,5
The earth was without form and void, and darkness was over the face of the deep. And the Spirit of God was hovering over the face of the waters. Genesis 1:2
Behold, I am toward God as you are; I too was pinched off from a piece of clay. Job 33:6
Enter His gates with thanksgiving, and His courts with praise! Give thanks to Him; bless His name! Psalm 100:4
Lift up your hands to the holy place and bless the Lord! Psalm 134:2
Blessed is the man who trusts in the Lord, whose trust is the Lord. He is like a tree planted by water, that sends out its roots by the stream, and does not fear when heat comes, for its leaves remain green, and is not anxious in the year of drought, for it does not cease to bear fruit. Jeremiah 17:7-8
He said to him, “You shall love the Lord your God with all your heart and with all your soul and with all your mind. This is the great and first commandment. And a second is like it: You shall love your neighbor as yourself. On these two commandments depend all the Law and the Prophets.” Matthew 22:37-39
Then He said to me, “Prophesy over these bones, and say to them, O dry bones, hear the word of the Lord. Thus says the Lord God to these bones: Behold, I will cause breath to enter you, and you shall live." Ezekiel 37:4-5
Riches do not profit in the day of wrath, but righteousness delivers from death. Proverbs 11:4
The angel of the Lord appeared to him in a flame of fire out of the midst of a bush. He looked, and behold, the bush was burning, yet it was not consumed. And Moses said, “I will turn aside to see this great sight, why the bush is not burned.” When the Lord saw that he turned aside to see, God called to him out of the bush, “Moses, Moses!” And he said, “Here I am.” Exodus 3:2-3
Daniel answered and said: “Blessed be the name of God forever and ever, to whom belong wisdom and might. He changes times and seasons; He removes kings and sets up kings; He gives wisdom to the wise and knowledge to those who have understanding." Daniel 2:20-21
Now the Lord is the Spirit, and where the Spirit of the Lord is, there is freedom. 2 Corinthians 3:17
Previous slide
Next slide

This website participates in the Amazon Associates program. As an Amazon Associate I earn from qualifying purchases.

© 2021-2024 Wave Walker DSP