Plot power spectrum of experimental data

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>]
../_images/7489721e4d174c11061a8cb36166ee218b11bded0816bc4e2b226bdc653f16cd.png
p.hist(data[:,1],101,density=True);
../_images/f330ad2d9987ee02d4186097958bdd6c7cad61deed265e1ca8edfac854921d2c.png
u = data[:,1]

meanu = u.mean()
uf = u - meanu
p.plot(uf[:100])
[<matplotlib.lines.Line2D at 0x7f07cc9c08f0>]
../_images/a9c43399df137845756b0c733cd74e2ee80d430d7f20d4fb2b4bc15d86b2ea8b.png
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