# Creating Triangle Filters for Smoothing using Python

The 'binning' process consists in summing the energies (squared magnitude) within groups of adjacent FFT values. This will give you the total energy in a set of disjoint frequency bands.

A more elaborate form consists in using overlapping triangle filter banks - you compute a weighted sum of the energy in a range of FFT bins to get a number which can be interpreted as the energy measured at the output of a band-pass filter of a given center frequency/width.

Can anybody help in generating such overlapping filter banks as I am new to signal processing and having hard time creating such a filter.

• This answer should help. Oct 15, 2022 at 21:07

Let's say we have spectrum $$X[k]$$ and it's power spectrum $$P[k]=|X[k]|^2$$. Smoothing can we written as

$$S[k] = \sum_n W[n+k]P[n+k]$$

where $$W[k]$$ is a the smoothing window. For a rectangular window of length $$2N+1$$ this simply turns into.

$$S[k] = \frac{1}{2N+1}\sum_{n=k-N}^{k+N} P[n+k]$$

An efficient way to calculate this is to simply calculate the integral $$Q[k] = \sum_0^kP[k]$$ and this simply becomes

$$S[k] = Q[k+N]-Q[k-N]$$

To get a triangular window, you can simply apply rectangular smoothing twice. The effective window of consecutive smoothing operation is the convolution of all individual smoothing windows. The convolution of two rectangles is a triangle.

CAVEAT: I have been intentionally sloppy with the summation indices at the edges of the spectrum. What you want to do for $$n<0$$ and $$n > K$$ depends on the specific application. I have also assumed that the window is symmetric.

• Thank you so much for your response. So, you are saying that I need to convolve my power spectrum twice with the Rectangle window in order to get the triangular filter affect? Oct 16, 2022 at 12:49
• Yes. That's correct Oct 16, 2022 at 13:26