# Zero STFT bins (and not FFT bins)

Filtering by taking FFT, zeroing bins, and inverse FFT is a bad idea, as discussed here.

• take a STFT, (i.e. multiply the input signal by moving window function, and take FFT)

• zero some bins in the STFT matrix

?

I've tried it, it's not bad, but I've got horizontal ripples in the spectrogram:

from perso import stft
from scipy.io import wavfile
import numpy as np
s = stft.stft(x, fftsize = 4096)
s[:,0:11] = 0
s[:,13:] = 0
z = stft.istft(s)
z = np.float32(z)
wavfile.write('out.wav', sr, z)


Important note: why do I absolutely want to do the filter in the frequency domain? Because I want to do a filter that evolves over time... With a STFT, it would be super simple to make the filter evolve for each time frame...

for k in s.shape[0]:
s[k,f(k):0] = 0       # where  f(k) varies over time (k)


Is there a way to make a good-working STFT filtering in the frequency domain?

• better reconstruction with this trick You can just use the sym=False parameter, that's what it's for. Note that stft/istft will be built into scipy soon: github.com/scipy/scipy/issues/6058 and yes, with windowed overlap the effects are not as bad as just zeroing out bins – endolith Dec 15 '16 at 19:16
• I've been playing with this the whole day, and it seems that filtering with STFT is not that bad (even by zeroing things in the STFT matrix). Would you like to post an answer @endolith ? – Basj Dec 15 '16 at 19:18
• I agree it's "not that bad" and I believe it's used often, but I'm not sure how to quantify "badness" in this case. – endolith Dec 15 '16 at 19:38
• Converting my bad answer to a comment: Each column of the STFT is a DFT. So the same drawbacks discussed in dsp.stackexchange.com/questions/6220/… apply to your method as well. You can try designing a time varying filter and filter each column of the STFT with a different $H(\omega)$ and then invert the modified STFT. See section 2.2 here, for instance: recherche.ircam.fr/anasyn/roebel/amt_audiosignale/VL3.pdf – Atul Ingle Dec 29 '16 at 18:29
• Basj 's reply: I don't think the problems mentioned in this linked question apply because when doing STFT, we already have a windowing that limits the problem: pastebin.com/TyEjDh1w. Don't you think so? – Atul Ingle Dec 29 '16 at 18:29