Plot Real FFT
from matplotlib import *
use('Qt4Agg')
from matplotlib.pyplot import *
from numpy import *
def PlotRFFT(x, y):
### PlotRFFT(x, y): plots the FFT of y assuming y is real. Generates one plot with two subfigures: abscissa = frequency and abscissa = period.
f = fft.rfft(y)/len(y)*2
nu = fft.rfftfreq(len(y), x[1]-x[0])
p = 1/nu
amp = abs(f)
subplot(2,1,1)
loglog(nu, amp)
xlabel('Frequency')
ylabel('Amplitude')
subplot(2,1,2)
loglog(p, amp)
xlabel('Period')
ylabel('Amplitude')
show()
if __file__ == '__main__':
x = arange(0,1000, 0.001)
y = sin(2*pi*x/7)
PlotRFFT(x, y)