Skip to content

Instantly share code, notes, and snippets.

@ZGainsforth
Created May 21, 2014 02:23
Show Gist options
  • Save ZGainsforth/a006077ee753d677cb6e to your computer and use it in GitHub Desktop.
Save ZGainsforth/a006077ee753d677cb6e to your computer and use it in GitHub Desktop.
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment