# Wave Walker DSP

## Trending

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

Digital Signal Processing through the Lens of the FIR Filter
September 1, 2021

#### Introduction

Digital signal processing has two components: signals and filters.

A signal is a time-series which has information (RF vocabulary) and filters are useful in applying a desired affect to a signal. These affects can be:

• enhancing information elements of a signal,
• attenuating or minimizing noise,
• or some other modification.

The following sections will highlight how an FIR filter can be used to minimize noise in a receive signal which enhances the information content. Trade-offs will be discussed between how much noise can be minimized with how much distortion can be applied to the underlying signal.

#### Time Invariant Filters

The introductory type of filter encountered in the undergraduate education is the time-invariant (TI) filter. A TI filter is one whose impulse-response does not change with time. Applying the filter against the same signal a nanosecond from now or 15 years from now will produce the same response. A signal x[n] is related to the filter output y[n] through discrete-time convolution,

(1)

or equivalently,

(2)

Delaying a signal x[n] by k samples, x[n-k], and passing it through a time-invariant filter h[n] results in the same delay of the output with no other modifications,

(3)

#### Moving Average FIR Filters

There are two types of TI filters; infinite impulse response (IIR) filters which have feedback and finite impulse response (FIR) filters which do not have feedback. A moving average (MA) filter is an example of an FIR filter. Consider a length-3 moving average filter

(4)

where x[n] is the input signal and y[n] is the output of the MA filter. Each output is the average of the three last inputs. For example,

(5)

(6)

(7)

Visually the filter can be represented by the blog diagram in Figure 1.

Each of the filter weights are 1/3 and the MA filter can be represented by

(8)

A moving average filter will reduce noise fluctuations in a receive signal. Figure 2 is an example of a pulse train signal. Noise is added to the pulse train and then the length-3 MA filter is applied to reduce the variations in the signal due to noise.

The impact of the MA filter can be seen in the time domain. How does it work in the frequency domain?

#### Moving Average Filter in Frequency Domain

The Z-transform Z{} can be used to translate the difference equation h[n] into the frequency domain H(z),

(9)

(10)

(11)

Substituting (10) and (11) into (9),

(12)

Gathering like terms in X(z)

(13)

allows the transfer function H(z) to be written as

(14)

Substituting

into (14),

(15)

The magnitude-squared response  can by found by

(16)

where * is the conjugation operator. Substituting (15) into (16),

(17)

Substituting (reference)

into (17),

(18)

and converting into dB,

(19)

Figure 4 gives the magnitude-squared response of the filter H(z) in dB

The low-pass nature of the MA filter reduces the impact of high frequency noise, which is the affect seen in Figure 3. The following section will analyze how the MA filter effects the signal and noise in the frequency domain.

#### Analyzing Filter Impact in Frequency Domain

The input signal x[n] contains both signal s[n] and noise w[n],

(20)

The filter h[n] low-pass filters both s[n] and w[n],

(21)

or equivalently in the frequency domain,

(22)

Figure 5 shows how the MA filter reduces the noise at high frequencies in the frequency domain. Similarly Figure 6 shows the frequency response of the pulse train signal is much less effected by the MA filter.

#### Increasing Filter Length

The previous section showed that a length-3 MA filter reduces the impact of noise by filtering out the high frequency content with little impact to the pulse train signal. If 3 filter weights are good, more are better … right? What will happen if we increase to length 63? Will there be any unintended consequences? (Yes.)

Figure 7 gives the output of a length-63 MA filter in the time domain with the same input pulse train signal.

Increasing the filter length from 3 to 63 has created noticeable distortion of the underlying pulse train signal. A period of ramp up and ramp down between pulses can now be seen in the filtered signal as well as a time-shift. Where did this come from? Let’s look to the time domain first.

#### Analyzing Moving Average in Time Domain

An input signal x[n] is defined to have a single cycle of a pulse,

(23)

Figure 8 demonstrates the starting values for all elements in the block diagram.

The first 1 is passed into the filter for x[1] = 1 and Figure 9 shows the state of the filter. Figures 10 and 11 also show the response for x[2] = 1 and x[3] = 1.

Figure 12 gives the output y[n] for all x[n].

#### Correcting for Filter Delay

The input signal x[n] is 6 samples of 1’s. Figure 12 shows y[n] has has 4 samples of 1’s and multiple transition samples. The four 1 values obviously belong to the pulse train, as well as the two adjacent 2/3 samples at n=1 and n=6. The delay due to the filter can be corrected for by removing the first (3-1)/2 = 1 samples from y[n], shown in Figure 13.

Similarly, the delay of the length-63 filter can be corrected by removing the first (63-1)/2 samples from the time-series as shown in Figure 14.

#### Frequency Domain Analysis of Longer MA Filter

The distortion of the underlying pulse train is also due to the much narrower bandwidth of the MA filter. Figure 15 shows the length-63 MA filter has a much narrower bandwidth than the length-3 MA which results in more attenuation of the high frequency components of the pulse train signal. The noise at the output of the MA filter is also significantly reduced, shown in Figure 16. Also note the length-63 MA filter applies about 38 dB worth of attenuation at high frequencies as compared to 9 dB for the length-3 filter.

#### Conclusion

The analysis of the FIR filter was used to highlight major concepts within DSP:

• Noise negatively impacts signals.
• Filtering can be used to minimize noise in a receive signal to enhance the signal.
• Trade-offs must be made to balance noise minimization and signal distortion when applying a filter.
• Longer filters provide tend to provide more attenuation than shorter filters.
• Time domain effects can also be viewed through the frequency domain.

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.