0
0
Signal Processingdata~10 mins

Spectrogram visualization in Signal Processing - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Spectrogram visualization
Input Signal
Windowing: Split signal into chunks
Apply FFT on each chunk
Calculate magnitude (power) spectrum
Stack spectra over time
Display as 2D image: Time vs Frequency vs Intensity
The signal is split into small time windows, each window is transformed to frequency data, then all frequency data are combined over time to form the spectrogram image.
Execution Sample
Signal Processing
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import spectrogram

f, t, Sxx = spectrogram(signal, fs=fs)
plt.pcolormesh(t, f, 10 * np.log10(Sxx))
plt.ylabel('Frequency [Hz]')
plt.xlabel('Time [sec]')
plt.title('Spectrogram')
plt.colorbar(label='Intensity [dB]')
plt.show()
This code computes and plots the spectrogram of a signal showing how frequency content changes over time.
Execution Table
StepActionInput/VariableOutput/Result
1Receive input signalsignal (array), fs (sampling rate)signal array ready
2Split signal into windowssignal arraywindows (chunks of signal)
3Apply FFT on each windowwindowsfrequency spectra per window
4Calculate power spectrumfrequency spectramagnitude squared spectra (Sxx)
5Stack spectra over timeSxx2D array (frequency x time)
6Convert power to dB scaleSxx10 * log10(Sxx)
7Plot spectrogramtime (t), frequency (f), power dBcolor mesh image showing intensity
8Show plotplot objectvisual spectrogram displayed
9EndN/ASpectrogram visualization complete
💡 All windows processed and spectrogram displayed
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4After Step 5After Step 6Final
signalraw inputunchangedunchangedunchangedunchangedunchangedunchanged
windowsN/Aarray of chunksunchangedunchangedunchangedunchangedunchanged
frequency spectraN/AN/AFFT results per windowunchangedunchangedunchangedunchanged
Sxx (power spectrum)N/AN/AN/Amagnitude squaredstacked 2D arrayunchangedunchanged
Sxx dBN/AN/AN/AN/AN/A10 * log10(Sxx)unchanged
plotN/AN/AN/AN/AN/Acreateddisplayed
Key Moments - 3 Insights
Why do we split the signal into windows before applying FFT?
Splitting into windows lets us see how frequencies change over time. The execution_table step 2 shows signal split into chunks, enabling time-local frequency analysis.
Why convert power spectrum to decibels (dB)?
Decibels make it easier to see differences in power on a logarithmic scale. Step 6 in execution_table shows this conversion for better visualization contrast.
What does the color in the spectrogram represent?
Color shows the intensity (power) of frequencies at each time window. Step 7 shows plotting with power in dB mapped to color.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step is the signal split into smaller chunks?
AStep 2
BStep 3
CStep 4
DStep 5
💡 Hint
Check the 'Action' column for 'Split signal into windows'
According to variable_tracker, what is the state of 'Sxx' after Step 5?
ARaw input signal
BStacked 2D array of power spectra
CFFT results per window
DPower spectrum converted to dB
💡 Hint
Look at the 'Sxx (power spectrum)' row under 'After Step 5'
If we skip converting power to dB (Step 6), how would the spectrogram plot change?
APlot would be identical
BPlot would not show any frequencies
CColors would represent raw power, possibly less contrast
DPlot would show time on y-axis instead
💡 Hint
Refer to Step 6 and 7 in execution_table about power conversion and plotting
Concept Snapshot
Spectrogram visualization:
- Split signal into short windows
- Apply FFT to each window
- Compute power spectrum (magnitude squared)
- Stack spectra over time to form 2D array
- Convert power to dB scale for better contrast
- Plot time vs frequency with color showing intensity
Full Transcript
Spectrogram visualization breaks a signal into small time windows. Each window is transformed using FFT to get frequency content. The power spectrum is calculated by squaring the magnitude of FFT results. These spectra are stacked over time to form a 2D array showing frequency vs time. The power values are converted to decibels to improve visual contrast. Finally, the spectrogram is displayed as a color image where colors represent intensity of frequencies at each time window. This helps us see how frequencies in the signal change over time.