Compute Power Spectrogram in Python – Python Tutorial

By | August 30, 2023

Power spectrogram is also can be called magnitude spectrogram, here is the tutorial:

Understand the Difference Between Amplitude Spectrogram and Magnitude Spectrogram

We can compute it by square the amplitude spectrogram.

How to compute it in python?

It is easy to get power spectrogram, here are some steps.

Step 1. compute the audio amplitude spectrogram

We can refer to this tutorial to get amplitude spectrogram.

Understand Audio Amplitude Spectrogram and Compute it in Python – Python Tutorial

Step 2: compute the power spectrogram

power  = amp**2

Here power is the power spectrogram, and the amp is the amplitude spectrogram.

Step 3: display power spectrogram

Here is the example code:

import matplotlib.pyplot as plt
import librosa.display
plt.figure(figsize=(12, 4))
librosa.display.specshow(librosa.power_to_db(power, ref=np.max), sr=sr, x_axis='time', y_axis='log')
plt.colorbar(format='%+2.0f dB')
plt.title('Power Spectrogram')

Run this code, we will see:

display power spectrogram