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])
[<matplotlib.lines.Line2D at 0x7f07ccb965d0>]
p.hist(data[:,1],101,density=True);
u = data[:,1]
meanu = u.mean()
uf = u - meanu
p.plot(uf[:100])
[<matplotlib.lines.Line2D at 0x7f07cc9c08f0>]
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:np.int(lenu/2)])
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[9], line 1
----> 1 p.plot(specu[2:np.int(lenu/2)])
File ~/Documents/repos/engineering_experiments_measurements_course/.conda/lib/python3.12/site-packages/numpy/__init__.py:397, in __getattr__(attr)
392 warnings.warn(
393 f"In the future `np.{attr}` will be defined as the "
394 "corresponding NumPy scalar.", FutureWarning, stacklevel=2)
396 if attr in __former_attrs__:
--> 397 raise AttributeError(__former_attrs__[attr], name=None)
399 if attr in __expired_attributes__:
400 raise AttributeError(
401 f"`np.{attr}` was removed in the NumPy 2.0 release. "
402 f"{__expired_attributes__[attr]}",
403 name=None
404 )
AttributeError: module 'numpy' has no attribute 'int'.
`np.int` was a deprecated alias for the builtin `int`. To avoid this error in existing code, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations