title: Numerical differentiation via numpy FFT
body: <p>I am learning how to use numpy for Fast Fourier transform differentiation. In the code below, I create a simple sine function and try to get the cosine. The result is shown in the image, there seems to be a normalization factor which I do not understand despite reading the documentation and which prevents me from getting the correct results.</p>
  
  <p><strong>Can you tell me how to get rid of the normalization factor or if I am failing in a different way?
  Also please explain why the Nyquist frequency is not present when the array is length is odd.</strong></p>
  
  <pre><code>x = np.arange(start=-300., stop=300.1, step=0.1)
  sine = np.sin(x)
  
  Y = np.fft.rfft(a=sine, n=len(x))
  L = 2.*np.pi #period
  N = size(Y)
  
  for k, y in enumerate(Y):
      Y[k] *= 2.*np.pi*1j*k/L
  
  # if N is even, the last entry is the Nyquist frequency.
  #if N is odd, there it is not there.
  if N%2 == 0:
      Y[-1] *= 0.
  
  cosine = np.fft.irfft(a=Y, n=len(x))
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/bFuhB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bFuhB.png" alt="Code output"></a></p>