title: FFT derivatives using Numpy and the Nyquist frequency
body: <p>I am having trouble understanding Numpy's behavior regarding the Nyquist frequency. Consider the following example:</p>
  
  <pre><code>import numpy as np
  x=np.linspace(0, 2*np.pi, 21)[:-1]
  k=np.fft.rfftfreq(len(x), d=x[1]-x[0])
  
  FFT=np.fft.rfft(x)
  
  x1=np.fft.irfft(1j*k*FFT)
  FFT[-1]+=1e5
  x2=np.fft.irfft(1j*k*FFT)
  
  print(np.allclose(x1,x2))
  </code></pre>
  
  <p>Prints <code>True</code>. So apparently it doesn't matter what I do with the Nyquist frequency in <code>FFT</code>, the result is always the same and the change is ignored. Curiously, this does not happen when trying to just recover the function (no derivation):</p>
  
  <pre><code>x1=np.fft.irfft(FFT)
  FFT[-1]+=1e5
  x2=np.fft.irfft(FFT)
  
  print(np.allclose(x1,x2))
  </code></pre>
  
  <p>prints <code>False</code>.</p>
  
  <p>I may be misunderstanding what the Nyquist frequency is here (Wikipedia and other sources weren't very helpful) but aren't both results supposed to be affected by a change in the Nyquist frequency? The closest explanation I can find is that the Nyquist frequency is supposed to be a real number, but still doesn't seem to explain both behaviors.</p>
  
  <p>The reason I'm asking this is because I'm trying to reproduce results that I know are correct from a <a href="http://www.fftw.org" rel="nofollow noreferrer">Fortran code</a> that does do some stuff with the Nyquist frequency wen differentiating. My results are always about 1% off and I'm guessing this is the culprit.</p>