DSP Algorithms for RF Systems

Buy the Book!

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

Half Band Filter Design: Exceptional Filtering Efficiency!
September 27, 2021

Table of Contents

Introduction

The half band filter (HBF) is an incredibly efficient filtering structure when designed correctly! In this blog I will discuss how to design half band filter weights with the NumPy function remez(), how to select the parameters to maximize the efficiency, and how a folded FIR filter structure can increase the efficiency further.

See other posts in the half band filter series:

Half Band Filter Background

The HBF is fast! For a HBF with an odd filter length N,

  • every other weight is 0 (leads to (N-1)/2 multiplies per input sample),
  • can be folded due to even symmetry (N/4 multiplies per input sample) [lyons2011, p.493, p.702],
  • can be reduced to N/8 multiples per input sample (!!!) using a polyphase structure [harris2021, p.221].

Not only is the HBF efficient, it has a ton of applications including:

  • Efficient filtering [harris2021, p.107],
  • Large sample rate change [harris2021, p.234],
  • Logarithmic Frequency Processing (Wavelet Transforms) [vaidyanathan1993, p.491],
  • Hilbert Transform [carrick2011],
  • Perfect Reconstruction and Quadrature Mirror Filter (QMF) banks [harris2021, p.110].

Designing HBF Weights with Remez

Eagle-eyed readers might recognize that the example LPF filter from this blog was a half band filter although the design will be covered again in this blog post.

The cut-off frequency for a half-band filter is at a quarter of the sampling rate f_s/4 or in normalized units f/f_s = 0.25. The code to design an example half band filter is given below:

filterLength = 21
cutoff = 0.25
transBand = 0.1 
fPass = cutoff - (transBand/2)
fStop = cutoff + (transBand/2)
fVec = [0, fPass, fStop, 0.5]
aVec = [1, 0]
HBFWeights = scipy.signal.remez(filterLength,fVec,aVec)

Figure 1 gives the impulse response for the length N=21 filter and the frequency response in Figure 2. Notice from Figure 2 that the magnitude is 0.5 which in log units is 20\text{log}_{10}(0.5) = -6 ~ dB at frequency f/f_s = 0.25.

Figure 1: The impulse response for a length N=21 half band filter.
Figure 1: The impulse response for a length N=21 half band filter.
Figure 2: The linear magnitude of the frequency response of an example half band filter.
Figure 2: The linear magnitude of the frequency response of an example half band filter.

Odd Length Half Band Filter

The filter length N=21 was assumed for Figure 1. What happens for other values of filter length N? The impulse for the same HBF with filter length N=19 is given in Figure 3 and it’s frequency response in Figure 4.

Figure 3: The impulse responses for length N=21 and N=19 half band filters.
Figure 3: The impulse responses for length N=21 and N=19 half band filters.
Figure 4: The frequency responses for length N=21 and N=19 half band filters.
Figure 4: The frequency responses for length N=21 and N=19 half band filters.

Notice from Figure 3 that although the second filter N=19 is shorter by 2 weights it still has the same linear magnitude frequency response as the N=21 filter in Figure 4. Why?

From Figure 3 it can be seen that the filter weights at n=-10 and n=10 are close to zero. Figure 5 zooms into the filter weights and shows that the even filter weights, with the exception of n=0, are all effectively zero

(1)   \begin{equation*}h[n] = 0 ~ \text{for} ~ n \neq 0.\end{equation*}

The Remez design algorithm may not force them to zero exactly but can be set that way by a couple of lines of code.

Figure 5: The even filter weights, with the exception of n=0, for odd length half band filters are zero.
Figure 5: The even filter weights, with the exception of n=0, for odd length half band filters are zero.

Because the filter weights at n=-10 and n=10 are zero they do not contribute anything to the frequency response and thus are wasted computation. Odd length filters should be designed to have filter lengths

(2)   \begin{equation*}N-1 ~\% ~4 = 2\end{equation*}

where % is the modulo operator. For N=21,

(3)   \begin{equation*}21-1 ~\%~ 4 = 20 ~\%~ 4 = 0,\end{equation*}

which is not desirable for a HBF however for N=19

(4)   \begin{equation*}19-1 ~\%~ 4 = 18 ~\%~ 4 = 2\end{equation*}

which is an appropriate filter length.

Having zero-weight weights is computationally efficient if implemented correctly. Multiplying by zero always results in zero therefore for filter length N an odd-length HBF can require (N-1)/2 multiplies to implement the filter.

Even Length Half Band Filter

What happens when an even length half band filter is designed? Figure 6 gives the impulse response of an even length N=20 half band filter and its frequency response in Figure 7.

Figure 6: The impulse response for an even length N=20 half band filter.
Figure 6: The impulse response for an even length N=20 half band filter.
Figure 7: The linear magnitude frequency response of the even length N=20 and odd-length N=19 half band filters.
Figure 7: The linear magnitude frequency response of the even length N=20 and odd-length N=19 half band filters.

Even length HBF filters do not possess even-symmetry in time (ironic?) and even time index weights are non-zero. The lack of even-symmetry in time will introduce a 1/2 sample delay at the output of the filter and the non-zero weights will require a full N multiplies to implement as compared to (N-1)/2 for an odd-length filter. In general an odd-length HBF is a better choice than an even length filter unless there are extenuating circumstances otherwise.

Folding the Half Band Filter Weights

Notice from Figure 3 that the filter weights are even symmetric across n=0 such that

(5)   \begin{equation*}h[-n] = h[n] ~ \text{for} ~ n \neq 0.\end{equation*}

An even-symmetric filter can be “folded” so that only one multiplication is done for each unique filter weight. Figure 8 is the block diagram of a generic length N=7 FIR filter, Figure 9 is after the zero-weight have been removed and Figure 10 is the folded implementation of a HBF filter.

Figure 8: The block diagram for a generic FIR filter before the half band filter optimizations have been applied.
Figure 8: The block diagram for a generic FIR filter before the half band filter optimizations have been applied.
Figure 9: The block diagram for the HBF after all of the zero weights have been removed.
Figure 9: The block diagram for the HBF after all of the zero weights have been removed.
Figure 10: The block diagram for a half band filter after the zero weights have been removed and the even-symmetric weights have been folded.
Figure 10: The block diagram for a half band filter after the zero weights have been removed and the even-symmetric weights have been folded.

For a length N=7 filter the filter output is

(6)   \begin{equation*}y[n] = \sum_{k} x[k-n] \cdot h[k]\end{equation*}

which can be expanded to

(7)   \begin{equation*}\begin{split}y[n] & = x[-3-n]h[-3] + x[-2-n]h[-2] + x[-1-n]h[-1] \\& + x[-n]h[0] + x[1-n]h[1] + x[2-n]h[2] + x[3-n]h[3].\end{split}\end{equation*}

Note that (7) has time-reversed the input signal x[n] for clarity in the math, where as Figure 8 – Figure 10 have time-reversed the filter weights h[n] for graphical clarity. Both representations are valid although Figure 8 – Figure 10 is how the filtering would be implemented in a real world system.

From (1) the zero-weights of h[n] at even indices except for n=0 can be removed from the summation,

(8)   \begin{equation*}\begin{split}y[n] & = x[-3-n]h[-3] + x[-1-n]h[-1] + x[-n]h[0] \\& + x[1-n]h[1] + x[3-n]h[3],\end{split}\end{equation*}

which reduces the computations from the filter length N=7 to now 5 multiplies. Furthermore due to (5) a pre-addition can be performed to reduce multiplications. For example h[3] = h[-3] therefore

(9)   \begin{equation*}x[-3-n]h[-3] + x[3-n]h[3] = h[3] (x[-3-n] + x[3-n]).\end{equation*}

The filter output (8) can be further simplified to

(10)   \begin{equation*}\begin{split}y[n] & = h[3] (x[-3-n] + x[3-n]) \\& + h[1] ( x[-1-n] + x[1-n]) \\& + x[-n]h[0].\end{split}\end{equation*}

From (10) the multiplications have been reduced from N=7 to 3!

Conclusion

The half band filter is an effective tool to have in your kit as it’s computationally efficient and broadly applicable. The HBF is a great foundation understanding more advanced concepts such as the Hilbert transform, performing large sample rate change and near perfect reconstruction filter banks.

Have you seen the other posts on the half band filter?

One Response

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