# Zeroing bins before IFFT

Endolith's recent question on zeroing FFT bins got me thinking about a possible error in my workflow and I'd like to double check.

Consider a signal $x_i[m],\ m\in\{1,\ldots,M\}$, i.e. $M$ samples sampled at $f_s$ and the subscript denotes the $i^{th}$ such signal segment. I then filter this with a bandpass filter to between $0.1 f_s$ and $0.3f_s$ (at this stage, I was careful to not do a zero-the-bins kind of filtering) and Fourier transform it with an $N>2M$ long FFT. Let $X_i[k],\ k\in\{0,\ldots,N-1\}$ denote the Fourier coefficients and the filtered portion (including the roll-off frequencies on both ends) be the indices $0< k_l,...,k_u< N-1$.

My application now involves applying some function, $g$ to the Fourier coefficients $X_i[k_l],\ldots,X_i[k_u]$, averaging across the different segments ($i$) and inverse Fourier transforming the resulting vector. In math, I compute

$$X_{avg}[k]=\left\langle g(X_i[k])\right\rangle_i,\ k\in\{k_l,\ldots,k_u\}$$

where $\langle\cdot\rangle_i$ denotes averaging over the different segments. So far, so good.

Now, I didn't know what to do with the remaining Fourier coefficients $X_i[k'],\ k'\in\{0,\ldots,N-1\}\backslash \{k_l,\ldots,k_u\}$ before taking the IFFT. These coefficients are theoretically insignificant, since I've already filtered out content in them. So I went ahead and set $X_{avg}[k']=0$ and then computed the IFFT of $X_{avg}$. The results were along the lines of what I expected, but I didn't think of the aforementioned filtering issue, although I was aware of it (this is the same situation, with a bit of twists at places).

My question then is: Is it still a problem in this case i.e., when the bins that I "zeroed out" were technically low/insignificant? If so, how should I have handled it?

-

Filtering a signal by modifying the Fourier coefficients and then inverse Fourier-transforming it is a filter design method known as the "frequency-sampling" method.

Many research works on source separation for instance consider such filters because they are convenient (working on spectral characteristics to separate the signals - e.g. the fact that the frequency support of 2 sources is different) easy to implement and still lead to very convincing results (even the infamous "binary masks" :D).

You could compare this method to others, for instance FIR filter design by the window method : compute the ideal IIR impulse response and crop it or window it with a Hann/Hamming/your-preferred-window function. The window method corresponds to multiplying your impulse response by a window, in the time domain. It therefore results in a convolution between the involved Fourier transforms, leading to the well-known Gibbs effect.

For the frequency sampling method, you don't need to find the impulse response, but this comes at the cost that you do not control much of what is happening /between/ the frequency bins: in your example, that would correspond to the frequencies $\frac{\nu}{N} f_s$ where $\nu \notin \{0,1, 2,..., N-1\}$. The actual frequency response of such a filtering process is then an interpolation between the sampled points of the desired frequency response. This issue is not often discussed in the literature, but could lead to big cripples in the resulting frequency response.

There are other methods for designing filters, for instance for designing low/high pass or band-pass filters, but I have less practical experience there. I guess those are anyway not what you are looking for. I mentioned the window method only as a way of comparing what's happening: with the window method, you have trouble with the Gibbs effect, and with the frequency sampling method, you don't really know what's happening between the sampled frequency bins.

This said, for your practical problem, from my own experience, zeroing frequency bins is usually fine. Assuming the way you decide how to enhance this or that frequency bin makes sense (avoiding too many "jumps" in the frequency response, for instance), the result should not exhibit too many artifacts from that process. Note that setting the low values to zeros, instead of keeping the original ones, may however deteriorate what is happening in the frequency region of interest. In source separation as I have experience it, we usually try to minimize some criterion (e.g. mean squared estimation errors), and that can provide us with an optimal way of setting all the values of the Fourier transform. I would argue that this is a better way of dealing with the matter, instead of trying all sort of values for the "missing" ones until the result is acceptable (a method which is most likely to depend on the test signal, hence poorly generalizing to other signals).

-

The FFT operation is linear. Thus any FFT bin that is in the noise floor relative to the sum magnitude of the spectrum of your signal of interest in the frequency domain will likely still be in the noise floor in the time domain, and thus so will the "noise" generated by zeroing that bin.

-