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 0x73c852e711f0>]
../_images/3b311ebe3e8866885772e03491f25d47806ff0589e6f93ec5ffe8f5a5a8e3b9d.png
p.hist(data[:,1],101,density=True);
../_images/1121856b1da91c2338d92e7103f2c914dbeef93123d12ccb31a84d7e0944f648.png
u = data[:,1]

meanu = u.mean()
uf = u - meanu
p.plot(uf[:100])
[<matplotlib.lines.Line2D at 0x73c852ebc740>]
../_images/806b66f903e1170e845f63cc69e9ced4bbd129fff0482f4d5a9719748f595c47.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/GitHub/mechanical-engineering-metrology-and-measurements/.venv/lib/python3.12/site-packages/numpy/__init__.py:778, in __getattr__(attr)
    773     warnings.warn(
    774         f"In the future `np.{attr}` will be defined as the "
    775         "corresponding NumPy scalar.", FutureWarning, stacklevel=2)
    777 if attr in __former_attrs__:
--> 778     raise AttributeError(__former_attrs__[attr], name=None)
    780 if attr in __expired_attributes__:
    781     raise AttributeError(
    782         f"`np.{attr}` was removed in the NumPy 2.0 release. "
    783         f"{__expired_attributes__[attr]}",
    784         name=None
    785     )

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