# Valid approach to implementing a band pass filter

Suppose I want to perform Spectral shaping on a signal, i.e, modify the gains in a band of frequencies. Would there be any difference if I do that using the following two methods? -

1. Use a band pass filter to apply the gain in the band.
2. Calculate the bin numbers corresponding to the band, and apply the gain in those bins.

I'm interested to know if the second method is a valid approach, if not, why is it discouraged?

• sounds like 2. is an FFT. is your entire signal being read into the FFT or are you putting blocks of your signal into the FFT? Commented Apr 30, 2019 at 5:26
• Yes, 2. is an FFT. I will be putting blocks of the signal into the FFT. Commented Apr 30, 2019 at 5:31

The second method is the "Frequency Sampling" method of filter design, where the filter coefficients (the impulse response) are determined using the Inverse Discrete Fourier Transform of the sampled frequency response desired. It is extremely simple to implement but for most cases it is a poor choice as the result will be an exact match at the frequency bins selected, but excessive ripple in between (compared to other filter design algorithms such as Windowing, or Parks-McLellan and Least-Squares). Therefore much longer filter lengths are required over those optimized approaches mentioned.

The Frequency Sampling approach can be compared to (preferred) windowing design approaches in that for windowing approaches, the desired impulse response is determined from the Inverse Discrete Time Fourier Transform (IDTFT) in contrast to the Inverse Discrete Fourier Transform (IDFT) for Frequency Sampling. The IDTFT has a time domain that extends to infinity, while the IDFT is time limited and thus an aliasing of the coefficient values results for filters with long impulse responses (time aliasing when the desired frequency response is under-sampled).

Below compares the DTFT and DFT for an arbitrary waveform of the same time duration for non-zero values, but shows in this case that the DTFT has specific zeros assumed for time extending to infinity (and is therefore aperiodic), and results in a continuous function in frequency (we can approximate the DTFT by zero-padding the FFT for example). In contrast the DFT is time limited to N samples; I show it as periodic as we could get the same result if we continued time to infinity but repeated the waveform in each time slot (similar to the Fourier Series Expansion, where the time domain waveform from 0 to T is reconstructed from integer multiples of frequency harmonics--- if you continued the waveform beyond the time 0 to T, the waveform would be periodic in time). The key point is we see that the DFT is sampled in frequency while the DTFT is continuous. Sampling in one domain causes aliasing in the other when the number of samples over the duration is not sufficient. This is what drives a longer filter length than what we could achieve with the other approaches to meet similar performance.

For additional information on windowing vs frequency sampling, see this post:

Difference between frequency sampling and windowing method

My go-to approach for designing bandpass digital filters prototypes would be the least-squares (firls in Matlab/Octave, scipy.signal.firls in Python) and Parks-McClellan (firpm in Matlab, remez in Octave, scipy.signal.remez in Python) algorithms.

Matt L had great comments at this post FIR Filter design: Window vs Parks-McClellan and Least-Squares on the continued merits of Windowing design approaches when resources for filter computation are limited (such as possible beamforming applications where the coefficients may need to be computed on the fly).

• this is a better answer than mine. Commented Apr 30, 2019 at 18:55