Getting a DC Component in Frequency Domain Windowed Spectrum
Started by 4 weeks ago●7 replies●latest reply 3 weeks ago●198 viewsI'm playing around with frequency domain windowing (just because that is where my brain wanted to go, and not for any real reason). I've created a short Octave / Matlab script to create a complex sinusoid, calculate it's spectrum via FFT, then window it in the frequency domain by convolving with the spectrum of a window (Blackman-harris minimum 4-term, aka "BH92"). Here is how the spectra looks for both the time-domain windowed spectrum and frequency-domain windowed spectrum:

As you can see in the frequency domain windowed spectrum, there's a spike at DC. I'm trying to understand why that is. In case its an issue with my code, I'm linking to my code: freqDomainWindow.m
TIA!
P.S. Note to Dan Boschen: I'm still watching your videos! I'm not ignoring my homework! PROMISE! My brain just went down this rabbit hole and... here we are!

If you used an actual convolution process and convolved the unwindowed spectrum with the spectrum of the window function, that process may add a DC term to the result. The conv2 function doesn't give a ton of details about the how the convolution is computed, but if the coefficients of the window function spectrum have a large DC gain it may be adding or amplifying a DC component. Since conv2 chops out potentially half of the computation with the 'same' setting, the part that's left may even have more DC than the rest. There's kinda no way of knowing until you get the results.
FWIW, many practitioners just see something like that and say, "Oh, it added some DC, I'll take that back out..." and subtract the mean from the output vector. In other words, unless you want to take apart the window spectrum coefficients, which is easy enough to test for a DC component, or for the sum of the coefficient, and look at what conv2 actually does with the, I wouldn't worry about it too much other than understand that some algorithms do stuff like this. Maybe the thing to be learned is that you had better control of the results when you applied the window in the time domain.

"Maybe the thing to be learned is that you had better control of the results when you applied the window in the time domain."
I was thinking the same thing. Plus, correct me if I'm wrong, but windowing in the time domain requires one multiply per sample, while convolving in the frequency domain require 2N-1 (where N = number of window "taps") multiplies PLUS adds.
Mind you, I saw Rick Lyons' article on frequency domain windowing, and perhaps its still less processing IF you need to both create a spectral display AND do other processing on the spectrum, as well.

That's correct. Multiplication (element by element) in one domain is convolution in the other. The convolution (which can be done by a variety of means or algorithms) offers more opportunities to introduce a new DC offset than the element-by-element multiplication, aka one-multiply-per-sample.

I think I figured it out. It's not really a "DC" component (though that is where it lies on the spectrum); it's due to the ends of the original spectrum not lying at 0. As the convolution "filter" starts at the beginning and finishes at the end, it's dealing with a not-insignificant step between 0 and the ends of the unwindowed spectrum. That creates a large impulse, which when I use the "fftshift" moves it from the ends to the middle.
As you said, just easier to do it in the time domain and be done with it.
I'll cheat, and post AI's response :) (I was curious enough also, to check)
Regards,
Robert
---------------------------
"Yes, seeing a DC component after convolving a complex sinusoid with a Blackman-Harris window in the frequency domain is entirely expected.
While it might seem counterintuitive if your original sinusoid was at a high frequency (like 500 Hz), the "DC component" appears because of how convolution works in the frequency domain.
The Mechanics of Why This Happens
- Multiplication in Time = Convolution in Frequency:In most signal processing workflows, you aren't "convolving" the sinusoid and the window in the time domain; you are multiplying them. According to the Dual Convolution Theorem:$$\mathcal{F}\{x(t) \cdot w(t)\} = X(f) * W(f)$$The spectrum of your final signal is the convolution of the sinusoid's spectrum (a single delta function at $f_0$) and the window's spectrum.
- The Window's "Footprint":A Blackman-Harris window is a summation of cosine terms. Its frequency response $W(f)$ has a very large main lobe at 0 Hz (DC) and several side lobes.
- The DC value of the window's spectrum ($W(0)$) is simply the sum of all the window coefficients in the time domain.
- Since all coefficients in a Blackman-Harris window are positive, this sum is always a large, non-zero number.
- The Frequency Shift:When you convolve the sinusoid's delta function $\delta(f - f_0)$ with the window's spectrum $W(f)$, you are essentially shifting the entire window spectrum so that its center (the 0 Hz peak) is now at $f_0$.$$X(f) * W(f) = W(f - f_0)$$
So, where does the DC come from?
If you see a peak at 0 Hz (DC) in your final frequency plot, it usually happens for one of two reasons:
- Spectral Leakage: Because the Blackman-Harris window has a wide main lobe and side lobes that extend across the entire spectrum, a portion of the "energy" from your shifted window centered at $f_0$ actually "leaks" all the way back to the 0 Hz bin.
- Window Symmetry/Offset: If you applied the window and then performed an FFT, the "DC" you see is the average value of your windowed signal. Since a Blackman-Harris window is all positive, it effectively adds a "hump" to the data. If the sinusoid doesn't complete an integer number of cycles within the window, the average value of the windowed segments won't be zero, resulting in a DC offset.
Is it a problem?
Usually, no. It is simply a mathematical artifact of the windowing process. However, if that DC spike is interfering with your analysis:
- Check your normalization: Ensure you are dividing by the sum of the window weights ($S = \sum w_i$) rather than just $N$.
- Mean Removal: You can subtract the mean of the signal after windowing if you need to strictly ignore the DC component."

if you do fft of (window) and convolve result with fft of signal then do some index rearrangement and scaling you get same single tone
Each would be 8192 samples and conv will be 2*8192 - 1
I don't know why you use 2D conv

Have you tried the very simple idea of simply summing all the sample data points and seeing if it is zero. Then asking why you thought it would, or wouldn't, be zero.
[usually you don't have complete cycles of all the frequency components.. you have some signal frequency (period) which is not an integer divisor of the number of samples]
Fourier guarantees that all components, that _it_ represents, are always 1,2,3,4,5,.. cycles of the sample length. There shall be NO non-integer frequencies present in the FFT results (there is no array location 1000.5 to contain that frequency).
Plenty of fun to be had with digital simulations of analog expectations :smiley:
The imperfect sampling produces aliasing and modulations with a variety of equivalent, but different explanations.






