Why is the optimum window length for a discrete fourier transform of a signal less than 100%?

I'm trying to determine the best settings for a discrete Fourier transform on a signal with noise. Now I've stumbled on something that I can't seem to explain, I'm hoping someone can give me some insight.

My signal without noise is made of $$5$$ wavelengths with a frequency of $$5$$ MHz. Before and after the signal there is nothing. It looks like this: When I perform a Fourier transform on it, as expected I get a peak at $$5$$ MHz. Now usually my signal has lots of noise, so I want to apply a window function (rectangular) to get rid of as much noise as possible. To investigate the optimum size of my window, I've plotted the height of the peak ($$5$$ MHz) in the FFT against the width of the window function. In this graph, at $$x=0$$ the window function has no width, so the entire signal is cut off. At $$x=1000$$, the window function is exactly as wide as the signal.

Now it turns out, slightly BEFORE $$x=1000$$ the FFT peak is actually HIGHER than at $$x=1000$$. Meaning that the FFT gives the highest peak when a tiny part of the signal is cut off.

Why is that?

I've tried thinking of possible reasons, but they're all completely guesswork:

1. Maybe it has to do with the difference between a discrete Fourier transform and a continuous Fourier transform. I could see this show up as an artifact of the quantization of the signal.

2. Maybe it cancels out with another property — perhaps the higher peak also becomes wider, making it blend in with noise more. If I'm only looking at my FFT at $$5$$ MHz however, I will still keep my advantage.

Any thoughts are appreciated!

• Most likely if becomes higher because some of the side lobes have the opposite phase to the main lobe, so the main lobe has to "overshoot" to account for all of the signal in the frequency domain. All of this depends on the shape of your window function. Try a Hanning or Hamming window and quite likely (1) this effect will disappear and (2) the FFTs will have significantly smaller side lobes as well. – alephzero Jul 12 at 23:40
• You are right, all of the other window functions that i've tried do not show this behaviour. This is very interesting, basically a slight cutoff from using a rectangular window will prevent most of my sidelobe leakage? – AdaLovelace Jul 18 at 14:06