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 0x76cf6a9b6e10>]
../_images/225ef4f09f2d0f64078c636f9002dd2c8275bd5ff0fa52a0cf379350ca78411c.png
p.hist(data[:,1],101,density=True);
../_images/bf442f7036d43b5bbbf46f07a8e177dc043d15de0a6f56767a61053f8630192d.png
u = data[:,1]

meanu = u.mean()
uf = u - meanu
p.plot(uf[:100])
[<matplotlib.lines.Line2D at 0x76cf6a545710>]
../_images/336f4e6bd55ce7a1df83de8cf25aefd47d3263e5a2f0fe12e0d100e629ba10d9.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 ~/miniforge3/envs/book/lib/python3.11/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