Book Image

Python Data Analysis

By : Ivan Idris
Book Image

Python Data Analysis

By: Ivan Idris

Overview of this book

Table of Contents (22 chapters)
Python Data Analysis
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Key Concepts
Online Resources
Index

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:

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