# Wave Walker DSP

## Trending

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

Why an FIR Filter Should Have an Odd Length
December 29, 2021

#### Introduction

Today’s DSP Wisdom: odd-lengths are preferable to even-lengths in an FIR filter.

Powers of 2 are ubiquitous in DSP: binary number representations are in base-2, 3 dB is , and modulations are powers of 2 (BPSK, QPSK, 8-PSK, 16-QAM). The radix-2 FFT is decomposed into 2-input, 2-output butterflies. Upsampling or decimation by 2 can be done efficiently with a half band filter.

I’ve been allured many times by the siren song of choosing DSP parameters solely because they are powers of 2. A natural fallout is I have typically chosen even parameters for things such as filter lengths because they divide cleanly by a power of 2. The downside is that selecting parameters based on ease of coding results can result in unintended consequences in the DSP.

In this example choosing an even length filter incorporates a fractional time delay at the output of the filter which can negatively effect systems which require precise sampling such as sampling symbols from a demodulator or synchronizing a correlation peak to reference signal.

More blogs on FIR Filters:

## Odd Length FIR Filter

A motivating example on the usefulness of odd-length FIR filters is taking a 3-point moving average over a sequence of integers from 0 to 16. The 3-point moving average filter is defined by

(1)

and the integer sequence

(2)

Figure 1 is the result of the convolution

(3)

Figure 1 shows a delay of 1 sample in the convolution output. The convolution takes a certain number of samples before it starts producing valid outputs due to the time it takes to ramp up and store enough samples in the tapped delay line. The output delay for an even-symmetric FIR filter can be calculated by [lyons2011, p.212]

(4)

where is the filter length. For a 3-point moving average filter the output delay is

(5)

which is the same delay as in Figure 1.

#### Ramp Up Delay

The tapped delay line is initialized with all zeros,

(6)

The multiplication of with the filter weights initially results in zero,

(7)

The first input sample x[0] is added to the delay line

(8)

and the filter output is

(9)

The second input sample x[1] is added to the delay line

(10)

and the filter output is

(11)

The third input sample x[2] is added to the delay line

(12)

and the filter output is

(13)

After a delay of 1 sample the filter produces valid outputs, for , as shown in (11) and (13).

#### Ramp Down Delay

Just as the convolution has a number of samples associated with ramp up it will have a similar ramp down. The delay (4) at the start of the input sequence came from samples needing to ramp up in the tapped delay line. Similarly a ramp down occurs as input samples are leaving the tapped delay line and being replaced with zeros.

It takes samples for the tapped delay line to be flushed and from (4) samples can be removed from the head of convolution leaving

(14)

samples to be removed from the tail end of the convolution.

#### Correcting for FIR Filter Delay

From the example in Figure 1, , the head delay from (4) is

(15)

and the tail delay from (14) is

(16)

Therefore the first sample and last two samples are removed from resulting in as displayed in Figure 2.

#### Even Length FIR Filter

A 4-point moving average filter is convolved with the integer sequence x[n],

(17)

which is displayed in Figure 3.

A delay is seen in the filter output in Figure 3 similar to the 3-point moving average in Figure 2. However from (4) the delay is

(18)

which is not an integer number of samples. Figure 4 shows the filter output after removing delays by 1 and 2 samples, and .

Where the delay-corrected 3-point moving average filter in Figure 2 overlaps perfectly with the input sequence the 4-point moving average filter in Figure 4 has introduced a non-integer sample delay as in (18) that can’t be corrected by removing 1 or 2 samples. Figure 4 shows that and straddle the input x[n] due to the non-integer sample delay.

The non-integer sample delay may become a problem in some applications.

#### Square Root Raised Cosine Filter

A filter with an integer sample delay is particularly important when the output needs to be precisely sampled. An example is a radio receiver sampling symbols at the output of a matched filter. Figure 5 gives the impulse responses for an even and odd length square root raised cosine filter.

The SRRC parameters between the even and odd length SRRC in Figure 5 are identical except that for the time-indexing: the even length filter is designed with non-integer time values. The even length filter does not have the same peak at as the odd length filter at n=0. The result is that the receiver with an even length SRRC filter in it will always have a non-optimal sampling time because it cannot sample the peak at n=0.

You may have noticed that MATLAB’s rcosdesign() function will always give you an odd length. This is why!

#### Polyphase Filterbanks

In the past I had designed my polyphase filter banks to always have an even number of filter weights because I was overly concerned with computational efficiency. My blindspot was that while I was gaining efficiency I was throwing away fractions of a dB in signal processing gain. This is called “missing the forest for the trees”.

Knowing what I know now I am much more comfortable investing in my signal processing gain by having a handful of zero-weights in my polyphase filterbank coefficients.

#### Conclusion

Is being off by a 1/2 sample delay a huge deal? No. But consider that the difference between making good systems and GREAT systems is a thousand minuscule tweaks like using odd length filters appropriately.

Here’s an example: one of the most attractive points for getting your algorithm sold, adopted and used is being able to operate at a lower SNR than your competition. Getting down to lower SNR values means saving fractions of a dB everywhere you can and this is one of those tricks that helps get you there. I’ll be sharing more of these tips I’ve learned the hard way in future blog posts.

Resist the urge to make all things, including filter lengths, divisible by 2.

Have you seen the posts on low pass filter design and the half band filter? Ever wondered why their filter lengths are odd? Now you know!

More blogs on FIR Filters:

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

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