title: Scaling Amplitude After Windowing FFT to Recover Correct Amplitude
body: <p>I am trying to apply a Hann window to a sinusoidal signal with the idea of applying an FFT to recover the frequency and the amplitude.  This is a canonical case I have created to increase my understanding before I move onto my data (real time signal where I want to accurately determine the frequency content and amplitude).  In the code below I need to multiple by an additional factor of 2.0 to recover the amplitudes.  I understand multiplying by 2/N but now I am multiplying by 4/N.  Has anyone come across this or can anyone provide an explanation to why this is?  Here is my code:</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  
  # first create the time signal, which has two frequencies 13.2 hz and 43.9 hz
  f_s = 100.0 # Hz  sampling frequency
  f = 1.0 # Hz
  time = np.arange(0.0, 10.0, 1/f_s)
  x = 5 * np.sin(13.2 * 2 * np.pi * f * time) + 3 * np.sin(43.9 * 2 * np.pi * f * time)
  x = x + np.random.randn(len(time)) #inject some noise
  
  # apply hann window and take the FFT
  win = np.hanning(len(x))
  FFT = np.fft.fft(win * x) * 2.0  # IT SEEMS I NEED AN ADDITIONAL FACTOR OF 2 TO RECOVER THE AMPLITUDES
  n = len(FFT)
  freq_hanned = np.fft.fftfreq(n, 1/f_s)  
  half_n = np.ceil(n/2.0)
  fft_hanned_half = (2.0 / n) * FFT[:half_n]
  freq_hanned_half = freq_hanned[:half_n]
  
  # and plot
  plt.plot(freq_hanned_half, np.abs(fft_hanned_half))
  plt.xlabel("Frequency (Hz)")
  plt.ylabel("Amplitude")
  </code></pre>