Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Plot power spectrum of experimental data

import numpy as np
import matplotlib.pylab as p
# u = np.loadtxt('../data/data_for_FFT.txt')
data = np.loadtxt('../data/p40_20.ts')
# data source:
# http://ldvproc.nambis.de/data/ektdata.html 
p.plot(data[:500,0],data[:500,1])
<Figure size 640x480 with 1 Axes>
p.hist(data[:,1],101,density=True);
<Figure size 640x480 with 1 Axes>
u = data[:,1]

meanu = u.mean()
uf = u - meanu
p.plot(uf[:100])
<Figure size 640x480 with 1 Axes>
def powerspectrum(x):
    s = np.fft.fft(x)
    return np.real(s*np.conjugate(s))
specu = powerspectrum(uf)
lenu, = specu.shape
p.plot(specu[2:int(lenu/2)])
<Figure size 640x480 with 1 Axes>