# Signal values explode when filtering with bandpass and wiener in Python

I have a five second audio (speech with background noise), which I want to process first with bandpass filter and then with wiener filter to reduce noise. Audio is normalized between [-1, 1] and I expect the result to stay in this range also. It does when I do high or low pass filtering, but with a bandpass filtering, the values of the wiener filter explodes (they are approximately in range [-1500, 1500]. Can anybody tell me why?

Here's the Python code. I've tried both butterworth and elliptic filters, different cutoff frequencies and different parts of the audio sample, but all leads to the same result. So does the concatenation of high and low pass filters.

from scipy.io import wavfile
from scipy.signal import sosfilt, butter, wiener, stft, istft
import numpy as np

# bandpass filter
sos = butter(5, [400, 4000], btype='band', output='sos', fs=fs)
filtered = sosfilt(sos, sample, axis=0)

# wiener filter
f, t, fourier = stft(filtered, fs=fs)
y = wiener(fourier)
y = np.asarray(istft(y))
y = y[1, :]


• Hi, Xarzaloxa, and welcome to DSP.SE. Shouldn't the value of the btype parameter be "bandpass" (instead of "band" - see here)? Oct 12, 2021 at 12:18
• ... and the wiener function assumes a time-domain signal for input (see here). Oct 12, 2021 at 12:22

Just do:

# wiener filter
#f, t, fourier = stft(filtered, fs=fs)
#yw = wiener(fourier)
#y = np.asarray(istft(yw))
#y = y[1, :]
y = wiener(filtered)


and it appears to work for me.

This is the absolute value of the FFT of the resulting signal:

and this is the Wiener filtered signal:

Otherwise, you're doing a Wiener filter on the STFT of the signal which will be doing something completely different from what you expect.

• Thank you, this explained my error! Oct 18, 2021 at 8:56
• @Xarzaloxa Cool! Please select this as the accepted answer if this fixes the issue.
– Peter K.
Oct 18, 2021 at 11:45