How would I make a spectrogram?

Asked on 07/30/2024

1 search

To create a spectrogram, you can follow the steps outlined in the session "Accelerate machine learning with Metal" from WWDC 2024. Here’s a summary of the process:

  1. Short Time Fourier Transform (STFT):

    • Divide the Input Waveform: Split the input waveform into multiple shorter windows, which may overlap. Each window is treated as an independent signal.
    • Apply Window Function: To reduce spectral leakage, multiply each window by a window function, such as the Han window or a Gaussian window.
    • Compute FFT: Use a batched one-dimensional Fast Fourier Transform (FFT) operation to compute the STFT for each window.
  2. Implementation Steps:

    • Create Strided View: Set up the shape and stride for the windowed view. For example, a window width of 512 elements and a stride of 256 elements.
    • Multiply by Window Function: Use a constant tensor for the window function.
    • Compute FFT: Create the FFT tensor operation to compute the STFT for each window.

For more detailed information, you can refer to the session Accelerate machine learning with Metal (14:19).

Relevant Sessions

  1. Accelerate machine learning with Metal
  2. Support real-time ML inference on the CPU

These sessions provide insights into using Metal and BNNS Graph for efficient machine learning and audio processing, which are relevant to creating a spectrogram.