Live data from Hacker News

Why is it a bad idea to filter by zeroing out FFT bins? (2020)

dsp.stackexchange.com

21–30 of 43 posts

Re: Why is it a bad idea to filter by zeroing out FFT bins? (2020)

#21
post #16

This is indeed an excellent way of filtering if your audio is cyclic and fits into a single FFT, like a periodic waveform, a drum loop or an Optigan track. Just make sure not to apply any window.

You also need to make sure that the gibbs phenomena does not cause the filtered signal to leave the range of the representation. So a prefiltered signal is less than 1, but the post filtered signal wont be. Meaning if 1 is the cap for your audio output, then enjoy a brand new category of distortion. But its a terrible way in general ofc, just optimize an appropriate, zero phase filter with an unaffected passband and minimum distortion. Its trivially easy, and there is no excuse to just use the terribly shitty short "classic" filters common in audio processing or graphics as implemented by skilled programmers who dont know the difference between dft and fft. (which is always easy to tell as they use the term fft as if it was synonymous with frequency transform estimates)

Re: Why is it a bad idea to filter by zeroing out FFT bins? (2020)

#22

I disagree that it's always a bad idea. If you didn't have real data in those bins to begin with, then the absence of ringing was never real either. You're just choosing between interpolation strategies to fill in the data you deleted. You have to realize that whatever you do, you're making up data. One could say that you're taking out your dry erase marker and writing in your priors. For image processing, you probab…

Thats not how the frequency transform works. Its more likely to have more signal than noise in higher frequencies iif the signal is smooth and the noise white. But real relevant signals often have discontinuities.

Re: Why is it a bad idea to filter by zeroing out FFT bins? (2020)

#23
post #19

as mentioned, worth pointing out that most practical digital filters don't have that many taps so unless you have other reasons to go to the frequency domain, time domain filtering can be faster... but yeah, the implicit boxcar is a sinc. sometimes it's used for image data as 2d convolutions can be expensive though...

Most used digital filters are small this is true. But that is an error caused by legacy solutions which required filters to be exceedingly short beeing inappropriately applied to modern systems and problem. The most egregious examples are from videogames, where several different short classic filters are usually applied in series in order to deal with e.g. aliasing. The problem is twofold, it effectively makes a larger filter, and that larger filter is terrible at its job. The effect of using a single appropriately designed large filter is astonishing.

Re: Why is it a bad idea to filter by zeroing out FFT bins? (2020)

#24
https://github.com/pmarks-net/chromadoze multiplies white noise by a stairstep shape (rectangles of various heights), then runs an IDCT to generate colored noise.

I wonder if this actually has subtle artifacts, or if it doesn't matter because the input is noise?

Re: Why is it a bad idea to filter by zeroing out FFT bins? (2020)

#25

Why use an FFT at all? Yes it's easy but you'll almost always get a better result with a lot less computation by building an actual digital filter.

An IIR filter will always beat an FFT, but the most efficient way to implement longer FIR kernels is often with a WOLA or similar "streaming" FFT filter implementation. At some point, it takes fewer cycles to do N*log(N) multiplication in the frequency domain than to do N^2 multiplications to convolve in the time domain.

The crossover point will be system-dependent and heavily influenced by overhead, but a crude WAG might be in the vicinity of 64- to 128-wide kernels. There is no question of one implementation being "better" than the other, they are capable of identical results if implemented accordingly.

Re: Why is it a bad idea to filter by zeroing out FFT bins? (2020)

#26
post #21
post #16

This is indeed an excellent way of filtering if your audio is cyclic and fits into a single FFT, like a periodic waveform, a drum loop or an Optigan track. Just make sure not to apply any window.

You also need to make sure that the gibbs phenomena does not cause the filtered signal to leave the range of the representation. So a prefiltered signal is less than 1, but the post filtered signal wont be. Meaning if 1 is the cap for your audio output, then enjoy a brand new category of distortion. But its a terrible way in general ofc, just optimize an appropriate, zero phase filter with an unaffected passband and…

Your proposed zero phase filter won't work in realtime, and there are many use cases for what you consider shitty.

Re: Why is it a bad idea to filter by zeroing out FFT bins? (2020)

#27
post #23
post #19

as mentioned, worth pointing out that most practical digital filters don't have that many taps so unless you have other reasons to go to the frequency domain, time domain filtering can be faster... but yeah, the implicit boxcar is a sinc. sometimes it's used for image data as 2d convolutions can be expensive though...

Most used digital filters are small this is true. But that is an error caused by legacy solutions which required filters to be exceedingly short beeing inappropriately applied to modern systems and problem. The most egregious examples are from videogames, where several different short classic filters are usually applied in series in order to deal with e.g. aliasing. The problem is twofold, it effectively makes a larg…

i'm guessing you're talking about things like og 4 tap biquads and the like.

in the time domain, you're looking at what... for each sample a pointwise multiply for each tap and then a sum, right? i'm guessing for most audio applications at commonly used sample rates, you're rarely going to have more than 24 taps at the very most? (with most only really needed 8 to 16?)

with the fft, unless you're using super exotic multiwindow schemes, you're looking at a pointwise multiply just to do the windowing before the fft. then you're looking at n log n to compute the fft itself, then zeroing or applying an envelope (pointwise multiply), then another n log n back to the frequency domain.

i think with simd you're way faster to just stay in the time domain.

would be interesting to bench for sure though... small ffts and simd may be super fast and not that many instructions.

Re: Why is it a bad idea to filter by zeroing out FFT bins? (2020)

#28
post #27
post #23

Earlier quoted context omitted.

Most used digital filters are small this is true. But that is an error caused by legacy solutions which required filters to be exceedingly short beeing inappropriately applied to modern systems and problem. The most egregious examples are from videogames, where several different short classic filters are usually applied in series in order to deal with e.g. aliasing. The problem is twofold, it effectively makes a larg…

i'm guessing you're talking about things like og 4 tap biquads and the like. in the time domain, you're looking at what... for each sample a pointwise multiply for each tap and then a sum, right? i'm guessing for most audio applications at commonly used sample rates, you're rarely going to have more than 24 taps at the very most? (with most only really needed 8 to 16?) with the fft, unless you're using super exotic m…

It's not unusual to use hundreds of taps for a clean linear phase filter with a sharp slope. Discrete convolution reverb would need hundreds of thousands - which is why you use an FFT for that.

Re: Why is it a bad idea to filter by zeroing out FFT bins? (2020)

#29
post #16

This is indeed an excellent way of filtering if your audio is cyclic and fits into a single FFT, like a periodic waveform, a drum loop or an Optigan track. Just make sure not to apply any window.

It is possible to get around the cyclic properties of convolution via FFT by zero padding your array prior to transforming though.

Re: Why is it a bad idea to filter by zeroing out FFT bins? (2020)

#30
post #27

Earlier quoted context omitted.

i'm guessing you're talking about things like og 4 tap biquads and the like. in the time domain, you're looking at what... for each sample a pointwise multiply for each tap and then a sum, right? i'm guessing for most audio applications at commonly used sample rates, you're rarely going to have more than 24 taps at the very most? (with most only really needed 8 to 16?) with the fft, unless you're using super exotic m…

It's not unusual to use hundreds of taps for a clean linear phase filter with a sharp slope. Discrete convolution reverb would need hundreds of thousands - which is why you use an FFT for that.

interesting. just looked at a datasheet for a modern audio dsp and they set aside memory for ~256 coefficients per 48k channel. i guess big filters are a thing.

still, you're looking at applying a window before the fft in most applications. that's a full pointwise multiply before even stepping into the fft (and back).

reverbs have delay lines, right? what does that look like in the spectral domain? some shift of the phases?

Post reply on HN