# Why could window function help to get more accurate specific frequency amplitude?

In order to calculate amplitude of sinusoidal signal at a frequency around 60 Hz (but may be not 60 Hz), window function is adopted while using DFT.

hk is the coefficient of window function and Kdc is the sum of these coefficients. Np is the number of sample in one period when frequency is 60 Hz. (XL1, XL2, XL3 are time series sample of three phase electrical quantities. Sqrt(2) is due to some electrical reason.)

As far as I know, window function is helpful to reduce discontinuity when frequency deviates a little bit. However, I am really confused why this could help to get a more accurate sinusoidal signal amplitude.

I tried to derive, but after getting the steps below, I don't know how to prove V1 is closer to A than V2.

h1 and h2 are two types of window function. h1 corresponds to rectangular window and h2 represents triangle window.

## 2 Answers

I don't think window functions are very useful. The reason you are seeing a drop in magnitude is that some you your "Height" is losing "leakage" when your frequency frequency goes off bin. Window functions try to "minimize" leakage so that may be the effect you are seeing.

Instead, have a look at my answer here: FFT Phase interpretation of input signal with non-integer number of cycles in FFT window

Particularly point #3 "The magnitude adjustment for being off bin."

If this is an insufficient start for you, let me know in a comment and I can post some further reading for you.

• Thx for your reply. I also believe reducing spectrum leakage could be helpful, but what made me confused is window function will also change original sinusoidal signal, which means it could also cause some side-effect while reducing leakage. The interesting thing is after several times trial, I found this concern never become true. Is there any theoretical explanation for this? – Jacksonlee19910408 Jul 30 '20 at 23:53
• @Jacksonlee19910408 Like I said, I am not a big fan of windows. In the stuff I do, they just obscure the parameters without adding any information. The seminal paper on windows is "On the Use of Windows for Harmonic Analysis with the Discrete Fourier Transform. FREDRIC J. HARRIS" You can find it on the web in several places with various levels of print quality. I do commend you on playing around with it first to get a behavior understanding. That way when you get theoretical the math should make more sense. – Cedron Dawg Jul 31 '20 at 0:11
• In addition there is the more modern en.wikipedia.org/wiki/Window_function – Cedron Dawg Jul 31 '20 at 0:15
• @ Cedron Dawg.Thx very much, Cedron. I appreciate your great help. – Jacksonlee19910408 Jul 31 '20 at 15:12
• @ Cedron Dawg. Haha, cool. Sounds a great fun! :-) – Jacksonlee19910408 Jul 31 '20 at 21:47

As promised, here is a little derivation to give some insight into the effects of windows on DFT values done in reverse.

Suppose that I have a DFT from some signal.

\begin{aligned} X[k] &= \sum\limits_{n=0}^{N-1} x[n] e^{-i\frac{2\pi}{N}kn} \end{aligned}

I look at it, decide it needs a little "smoothing", so I decide to average neighboring DFT values to make a new DFT bin. Let's call it $$Y$$. The weights I'm going to use are just a "twist" of the (rescaled) VonHann values. If you plug in $$\omega=0$$ this becomes clear.

Plug and chug.

\begin{aligned} Y[k] &= ( -e^{i\omega}, e^{i\omega}+ e^{-i\omega},-e^{-i\omega} ) \cdot (X[k-1],X[k],X[k+1]) \\ &= -e^{i\omega} X[k-1] + ( e^{i\omega}+ e^{-i\omega} ) X[k] -e^{-i\omega} X[k+1] \\ &= \sum\limits_{n=0}^{N-1} \left[ -e^{i\omega} e^{i\frac{2\pi}{N}n} + e^{i\omega}+ e^{-i\omega} -e^{-i\omega} e^{-i\frac{2\pi}{N}n} \right] x[n] e^{-i\frac{2\pi}{N}kn} \\ &= \sum\limits_{n=0}^{N-1} 2 \left[ \cos ( \omega) - \cos \left( \frac{2\pi}{N}n + \omega \right) \right] x[n] e^{-i\frac{2\pi}{N}kn} \\ \end{aligned}

Now, my weighted average has all the sudden become a window function. Again plug in $$\omega=0$$ and you can see it is the VonHann.

Time for one of those trig identities.

\begin{aligned} \cos(A) - \cos(B) &= \cos\left( \frac{A+B}{2} + \frac{A-B}{2} \right) - \cos\left( \frac{A+B}{2} - \frac{A-B}{2} \right) \\ &= -2 \sin\left( \frac{A+B}{2} \right) \sin\left( \frac{A-B}{2} \right) \\ \end{aligned}

Substitute it in:

\begin{aligned} Y[k] &= \sum\limits_{n=0}^{N-1} 4 \sin \left( \frac{n}{N}\pi \right) \sin \left( \frac{n}{N}\pi + \frac{\omega}{2} \right) x[n] e^{-i\frac{2\pi}{N}kn} \\ Y[k] &= \sum\limits_{n=0}^{N-1} w_{\omega}[n] x[n] e^{-i\frac{2\pi}{N}kn} \\ \end{aligned}

When you plug in $$\omega=0$$ you see why the VonHann is also called the sine squared window.

So, here is a family of window functions whose base member is the VonHann.

$$$$w_{\omega}[n] = 4 \sin \left( \frac{n}{N}\pi \right) \sin \left( \frac{n}{N}\pi + \frac{\omega}{2} \right)$$$$

Like I said, I'm not a window expert as I don't care for them much, but I don't think you'll find these on the list in the references. Trig equations are slippery though, it could be one of those in different form.

Still it is interesting.

Hope this helps.

For those who say it might be worthless, I say not so fast.

Let $$\omega = \frac{2\pi}{N}$$

$$$$w[n] = 4 \sin \left( \frac{n}{N}\pi \right) \sin \left( \frac{n+1}{N}\pi \right)$$$$

Which means is it zeroes out the last sample as well as the first and shifts the center of the window to $$(N-1)/2$$, the center of the sample set, vs $$N/2$$ which is the center of the repeat frame.

Extra credit:

Which value of $$\omega$$ cancels the "The twisting caused by being off bin." which is point #2 in the reference in my first answer.