O'Reilly logo

Python Data Analysis by Ivan Idris

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Spectral analysis

In the previous section, we charted the amplitude spectrum of the dataset. The power spectrum of a physical signal visualizes the energy distribution of the signal. We can modify the code easily to plot the power spectrum, just by squaring the values as follows:

plt.plot(transformed ** 2, label="Power Spectrum")

The phase spectrum visualizes the phase (the initial angle of a sine function) and can be plotted as follows:

plt.plot(np.angle(transformed), label="Phase Spectrum")

Refer to the following graph for the end result:

Spectral analysis

Please refer to the spectrum.py file in this book's code bundle for the complete code.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required