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:
-
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.
-
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
These sessions provide insights into using Metal and BNNS Graph for efficient machine learning and audio processing, which are relevant to creating a spectrogram.

Swift Charts: Vectorized and function plots
The plot thickens! Learn how to render beautiful charts representing math functions and extensive datasets using function and vectorized plots in your app. Whether you’re looking to display functions common in aerodynamics, magnetism, and higher order field theory, or create large interactive heat maps, Swift Charts has you covered.

Support real-time ML inference on the CPU
Discover how you can use BNNSGraph to accelerate the execution of your machine learning model on the CPU. We will show you how to use BNNSGraph to compile and execute a machine learning model on the CPU and share how it provides real-time guarantees such as no runtime memory allocation and single-threaded running for audio or signal processing models.

Accelerate machine learning with Metal
Learn how to accelerate your machine learning transformer models with new features in Metal Performance Shaders Graph. We’ll also cover how to improve your model’s compute bandwidth and quality, and visualize it in the all new MPSGraph viewer.