# What is a good FFT window function to reject DC?

I'm using an FFT to analyze what is essentially the power envelope of a signal (see here for info on the containing project), and, since power numbers are always positive, to eliminate the DC component I'd like to use a window function that is 50/50 positive and negative, vs the usual all-positive function.

I've taken the "flat top" function, removed the a0 bias and converted it from cosines to sines, but I'm not sure that's optimal (or even meaningful).

Any suggestion?

• just subtract the mean before windowing? – endolith May 3 '12 at 21:42

The 1st derivative of most common continuous window functions (von Hann, etc.) will reject DC, yet will still have a magnitude frequency response similar to that of the original window function; so you can still use your original "goodness" criteria for window selection, if it is not related to phase.

• Although this response in mainly correct, it's more of a comment, so expanding on it would be very useful. – Phonon May 3 '12 at 21:38
• However, it does address my question to a degree. – Daniel R Hicks May 4 '12 at 1:09
• Is there a reason to do this instead of just subtracting the mean before windowing? – nibot May 15 '12 at 16:15
• If JasonR's answer is correct, then this idea of rejecting DC via the window function (and still getting a good spectral estimate) will not work. – nibot May 15 '12 at 16:18
• @nibot : A possible reason might be that a sum plus subtraction isn't possible (not available in some fixed hardware pipeline or latency, for instance.) – hotpaw2 May 15 '12 at 17:54

If you're concerned with doing spectral analysis on a signal with a large DC component, and you want to suppress that DC peak, then a window function is not what you want. As some other answers noted, a highpass filter (or, viewed differently, a notch filter with the notch at zero frequency) is an appropriate solution.

To understand why, you need to think about what applying a window function does to the frequency response of each DFT output. The DFT is defined as:

$$X[k] = \sum_{n=0}^{N-1} x[n] e^{\frac{-j2 \pi n k}{N}}$$

One interpretation of how the DFT works is as a bank of filters at $N$ equally-spaced frequencies between $-\frac{f_s}{2}$ and $\frac{f_s}{2}$. Recast the sum above as follows:

$$X[k] = \sum_{n=0}^{N-1} x_k[n]$$

where:

$$x_k[n] = x[n] e^{\frac{-j2 \pi n k}{N}}$$

So, the $k$-th DFT output is generated by first taking the input signal $x[n]$ and multiplying it by a complex exponential at frequency $\frac{-2\pi k}{N}$ to yield a downconverted signal $x_k[n]$. The resulting signal is then summed over the $N$-sample window to yield the DFT output $X[k]$. This is effectively a moving average filter (sometimes called a boxcar filter), whose impulse response can be described as:

$$b[n] = \begin{cases} 1,\ x = 0, 1, \ldots , N-1 \\ 0,\ \text{otherwise} \end{cases}$$

The magnitude response of the boxcar filter can be found by taking the discrete-time Fourier transform (DTFT) of that impulse response:

$$|H(f)| = \left|\frac{\sin\left(N \pi\frac{f}{f_s}\right)}{\sin\left(\pi\frac{f}{f_s}\right)}\right|$$

This is a Dirichlet kernel, and is sometimes referred to as a "periodic sinc" since it looks a bit like a sinc function but repeats periodically, which a sinc does not. This expression gives the magnitude response of each DFT output, where $f$ is measured as the frequency offset from the center frequency of the respective output bin. This illustrates the spectral leakage effect; each DFT output has a frequency response that covers some continuous swath of the input signal's spectrum, not just the discrete center frequency of each output.

Now consider how things change if you apply a window function to the input signal $x[n]$ before performing the DFT:

\begin{align*} X[k] &= \sum_{n=0}^{N-1} w[n] x[n] e^{\frac{-j2 \pi n k}{N}} \\ &= \sum_{n=0}^{N-1} w[n] x_k[n] \end{align*}

With the window function in place, the downconverted $x_k[n]$ is effectively passing through an FIR filter with an impulse response described by the window function. So, the per-output magnitude response of the DFT is:

$$|H(f)| = |W(f)|$$

where $W(f)$ the DTFT of the window function $w[n]$. Now note that if you chose a window function that had a zero at DC and used it to premultiply $x[n]$ before the DFT, you would actually cause the unintended effect of nulling out not only DC in the resulting spectrum, but the center frequencies of every one of the DFT outputs. This is probably not what you want.

So, if you truly just want to cancel the signal's DC component, removing it via some other type of pre-processing, not time-domain windowing, is the way to go. You could use a linear highpass filter with a very low cutoff frequency or subtract the estimated mean from the signal first, for example. Choosing between these methods should be based upon what other constraints your system has.

I don't think using a window function is a good way to remove DC. As endolith mentioned, a common method is just to subtract the mean before windowing. Another option would be to apply a high-pass filter to your signal prior to analysis, say, with a cutoff frequency of around 10 Hz.

• Applying a high-pass filter is not an option if the signal doesn't exist in analog form. But I believe you (& endolith) are correct that subtracting the mean should work, especially if a window is also used that pulls the endpoints to zero. (And a high pass filter would need a lower cutoff, given that I'm analyzing the signal down to maybe 0.01 Hz.) – Daniel R Hicks May 13 '12 at 0:44
• Why do you think you need an analog signal to apply a highpass filter? It's certainly possible to create a digital HPF. – Jason R May 13 '12 at 14:08
• @JasonR -- I'll admit that I'm pretty ignorant in such things (my signals courses were 40 years ago, pretty much before FFT, et al), but it seems to me that to create a digital high-pass filter I'd first have to produce the Fourier transform of the signal. – Daniel R Hicks May 13 '12 at 22:47
• That's not the case at all; you can generate a highpass filter just as well as a lowpass, bandpass, etc. In fact, there are techniques for taking a lowpass filter prototype and transforming it into a highpass filter that has an analogous response. Most software for filter design (e.g. MATLAB) can be used to make all types of filters. – Jason R May 13 '12 at 23:00
• I'm not sure where you got the impression that implementing a highpass filter requires differentiation. Differentiation is a highpass operation, but is not a suitable implementation for a highpass filter (since its frequency response is a ramp, making it amplify higher frequencies where noise is often present). The Wikipedia article on highpass filters would be a good start. – Jason R May 14 '12 at 12:56