Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Spectrograms

  • Rich time series like sound recordings can be converted to spectrograms, e.g., ussing FFT methods.

    • Spectrograms show the distribution in the frequency domain as a function of time.

    • In practice this is implemented by a moving window technique with local FFT computations (overlapping windows) called Short-time Fourier transform.

  • Some limitations:

    • The decomposition is dependent on the sampling frequency, fsf_s (samples per second), and time window length TT seconds.

    • The highest frequency that can be resolved is called the Nyquist frequency =fs/2= f_s/2 Hz, i.e., 22050 Hz for a 44.1 kHz sampling (due to the Fourier transform).

    • The lowest frequency that can be resolved is the Rayleigh frequency =1/T= 1/T Hz, i.e., for a window of length 1152 samples (MP3) and 44.1 kHz, this results in a minimum frequency of 1115244100Hz=126.1ms=38.3Hz\frac{1}{\frac{1152}{44100 Hz}} = \frac{1}{26.1 ms} = 38.3 Hz.

    • Too short windows will give a “smearing effect” on the extracted frequencies (see Wikipedia article) where precision is low on the extracted frequencies.

    • For time series, this means we have an upper bound (often of less interest) and a lower bound of the frequencies that can be resolved. The lower bound being “waves in the signal” ≤\leq “length of the window”.

<Figure size 1200x300 with 1 Axes>

Spectrogram computation

<Figure size 640x480 with 1 Axes>
<Figure size 640x480 with 2 Axes>
/Users/kristian/Documents/GitHub/IND320/.venv/lib/python3.12/site-packages/pydub/utils.py:300: SyntaxWarning: invalid escape sequence '\('
  m = re.match('([su]([0-9]{1,2})p?) \(([0-9]{1,2}) bit\)$', token)
/Users/kristian/Documents/GitHub/IND320/.venv/lib/python3.12/site-packages/pydub/utils.py:301: SyntaxWarning: invalid escape sequence '\('
  m2 = re.match('([su]([0-9]{1,2})p?)( \(default\))?$', token)
/Users/kristian/Documents/GitHub/IND320/.venv/lib/python3.12/site-packages/pydub/utils.py:310: SyntaxWarning: invalid escape sequence '\('
  elif re.match('(flt)p?( \(default\))?$', token):
/Users/kristian/Documents/GitHub/IND320/.venv/lib/python3.12/site-packages/pydub/utils.py:314: SyntaxWarning: invalid escape sequence '\('
  elif re.match('(dbl)p?( \(default\))?$', token):
<Figure size 640x480 with 1 Axes>

Spectrogram on time series

  • Here, we show a random series of data and its spectrogram.

  • An abrupt change in the frequency domain will show up in the spectrogram, maybe indicating a change in the underlying process.

<Figure size 640x480 with 2 Axes>