Here explains how to do frequency analysis, but frequency analysis requires the number of signals to be 2n, which is treated as a single segment of signals, so even if a signal is actually continuous, depending on the number of data selected, it will be treated as a periodic function in which the data changes suddenly, as shown below.
To prevent this, you can bring both ends of the sample interval closer to 0, which will make it continuous, and the process is called a window function. The image is below.
■Example of window function①
The following shows the results of comparing frequency analysis of 256 samples of a 1Hz periodic signal at 0.01 second intervals with frequency analysis of the signal with and without a window function.
The original signal without a window function has a shape like the foot of a mountain. This is called leakage error.
On the other hand, you can see that the foot of the signal with the window function added sharply converges to 0. However, the absolute value of the intensity is smaller than the signal without a window function.
■Types of window functions
Hann window
It is called this because it was invented by someone named Han. It is also sometimes called the "Hanning window" after the Hamming window described below. The formula is as follows.
Its characteristic is that both ends are 0, so it can be treated as a continuous function and there is little leakage error. However, there is a lot of attenuation, and it may attenuate up to the characteristic frequency.
Hamming window
This was invented by Hamming. Since both ends are not completely 0, it is slightly discontinuous and the leakage error is large, but the amount of attenuation is less than that of the Hann window, so the frequency resolution is good.
Comparing the Hann window and the Hamming window, we get the following.
■Example of window function②
Below is a comparison of the results using the Hann window and the Hamming window. Looking at the results, the Hamming window has a stronger amplitude at the target frequency and appears to have less leakage.
This shows that there are windows that are better suited to certain signals to be analyzed.
If you zoom in and look closely, you'll see that the Hann window has smaller amplitude at other frequencies, and depending on how you look at it, you could say that the Hann window has less leakage.