# IIR bandpass filter attenuates frequencies within the pass band

I applied Butterworth filters (order=5) that have different cutoff frequencies to a simple signal composed of four sinusoidal oscillations and computed its PSD.

% Simulated signal
data = np.zeros((27000, 62))
t = np.arange(data.shape)
for ch in range(62):
for f in [1.2, 12, 24, 36]:
data[:, ch] += np.sin(2*np.pi*t*f/2500)


However, I noticed that the spectral power changes depending on how I set the cutoff frequencies. Here, the spectral power values at 12 and 24 Hz decreases if I use a filter with the low and high cutoffs of 0.25 and 125 Hz (compared to a bandpass filter of 1-45 Hz). I understand that power at 1.2 and 36 Hz can be affected by the transition band but am confused why there are differences in 12 and 24 Hz. It seems like the amount of power decreased at 1.2 and 36 Hz moved to the power values at 12 and 24 Hz.

Is there any mathematical reason behind this phenomenon? Without frequencies near transition band, two filters give a near-identical result. The filter profile of the Butterworth filter is as below: Do not use a power spectral density measurement to measure the power of sinusoidal tones, but instead use a power spectrum (this may have been done, incorrectly, as I can’t see the code actually used- but this is an important point). A spectral density is used for signals that have power distributed over a wide bandwidth. In this case if used to measure single tones, the resolution bandwidth of the measurement will effect the power displayed as the power measured will be divided by the resolution bandwidth to plot the density in terms of power/Hz (as is typical for a PSD). If the PSD is done properly, the power in each tone will still be the same but the value incorrect due to the averaging over the resolution bandwidth (and incomplete information if the resolution bandwidth, RBW, used is not provided— the RBW is set by the capture duration in time along with any windowing which may be used).

The correct approach to accurately capture the level of each tone is to window the waveform, significantly zero pad the waveform to interpolate the spectrum, and then take the FFT. The result will have the same level for each tone other than the actual passband ripple of the filters as given by their frequency response. The results can then be scaled to account for the coherent gain on the window and additional scaling factors as needed depending on the units desired for the vertical axis.

• Thanks for the answer. I have used Welch's PSD to compute the power, but if I understood correctly, you are suggesting that I use power spectrum to compare the power, since PSD is used for signals that have power distributed over a wide bandwidth.
– scho
Mar 7 at 14:42
• However, when I tried the same PSD calculation on a real neural EEG data (that has power distributed over wider band), the same phenomenon occurred where powers in 15-30 Hz were different between two filters with different cutoff frequencies.
– scho
Mar 7 at 14:42
• Use a PSD absolutely when the power is distributed but know that this will not reflect the power of spurious (single tone) elements in the signal. In practice we look at both for example when reviewing phase noise (with a PSD) and spurs on the same waveform we use two plots Mar 7 at 14:47
• Also be careful that your signal is actually stationary over your observation interval otherwise the PSD isn’t meaningful. Sufficient stationarity can be tested with the “Allan deviation” plot - you can search on that here for other posts related to that, but it will readily tell you the maximum observation time over which stationarity can be assumed Mar 7 at 14:48
• To @DanBoschen’s point: see this
– Jdip
Mar 7 at 16:02