Audio Spectrogram
Operator: Abdulla Al Fahad. How tools are built and checked
A waveform shows how loud a sound is; a spectrogram shows what it is made of. Time runs left to right, frequency bottom to top, and colour gives the level at each point, so a steady hum is a horizontal line, a whistle a rising curve, a drum hit a vertical stripe and the high-frequency cut-off of a low-bitrate MP3 a sharp ceiling.
This page draws one from any audio file your browser can decode, with the controls used in audio work: FFT size, window shape, a linear, logarithmic or mel frequency axis, the range of dB shown and the colour map. Hover over it to read the time, frequency and level of any point, save the picture as a PNG with its axes, or save a table of the strongest peaks as a CSV. The LUFS Loudness Meter and BPM and Key Detector measure single numbers; this tool is for looking.
Key features
- FFT sizes from 256 to 8192 and four windows
- Linear, logarithmic (from 20 Hz) or mel frequency axes
- Four colour maps: viridis, magma, inferno and grayscale, with a colour bar
- A movable dB window, so quiet detail or loud detail can be brought out
- A readout of time, frequency and level under the pointer or finger
- PNG export including the axes and colour bar, and a peak list as CSV
FFT size, windows, axes and how levels are calibrated
Input is any audio the browser can decode, up to 60 minutes. Stereo is mixed to mono for the picture. The FFT size can be 256, 512, 1024, 2048, 4096 or 8192; the selector shows the window length and the width of a bin for the file's sample rate, for example 2048 samples at 44.1 kHz is 46 ms with 21.5 Hz per bin. A longer window separates close frequencies better and blurs timing; a shorter one does the reverse.
The window can be Hann, Hamming, Blackman or rectangular. Hann is the general choice; Blackman has the lowest side lobes, which helps to see weak components next to strong ones; rectangular has the narrowest peak but leaks energy everywhere.
The plot area is 1000 by 512 pixels (the whole image, with axes and colour bar, is 1150 by 564), and the transform is computed at the smaller of 2000 time columns and one per quarter-window hop, which are then scaled to that width. A long file is therefore not sampled at isolated instants: when columns are further apart than a quarter window, up to four frames inside each column's time slice are averaged as power. Levels are dB relative to a full-scale sine, with the range shown set by two sliders (quietest from -140 to -30 dB, loudest from -60 to +6 dB, at least 10 dB apart).
How it works
Each column is a windowed FFT of the mono signal. The magnitude of each bin is divided by half the sum of the window's samples, which calibrates it so that a full-scale sine reads 0 dB. A sine of amplitude 0.5 reads -6.02 dB where its frequency falls exactly on a bin, and a little less between bins; scalloping can cost up to 1.4 dB with a Hann window.
To draw rows, each of the 512 picture rows is given a frequency by the chosen axis. Linear spreads 0 to the Nyquist frequency evenly. Logarithmic runs from 20 Hz to Nyquist with equal height per octave. Mel uses the HTK formula, 2595 times log10 of 1 plus the frequency over 700, which is roughly linear below 1 kHz and logarithmic above. Where one row covers more than one bin, as at the top of the log and mel axes, the loudest bin in the row is shown so narrow peaks do not vanish; where a row falls between bins, the two are interpolated.
The peak list works from separate FFTs at evenly spaced times. At each time the local maxima above -90 dB are ranked by level and the best are refined by a parabola through the dB values of the peak bin and its two neighbours, which locates a peak much more finely than the bin width.
Common use cases
- Checking whether an MP3 that claims 320 kbps has content above 16 kHz or was made from a lower-quality source
- Locating a 50 or 60 Hz hum and its harmonics in a recording before filtering them out
- Looking at a bird call or a whistle over time on a mel axis to identify the pattern
- Seeing where a vocal's sibilance sits, around 5 to 9 kHz, before deciding on a de-esser setting
How to use this tool
- Drop in an audio file and wait for the picture.
- Choose an FFT size: 2048 for a general view, 8192 to separate close tones, 512 for transients.
- Pick the frequency axis: log or mel for music and speech, linear for hum and harmonics.
- Adjust the dB sliders until the detail you care about stands out.
- Move over the picture to read values, then click Save PNG.
- Set the peak options and download the CSV if you need numbers.
Example
A 3 second 1 kHz sine of amplitude 0.5 at 44.1 kHz, FFT 4096, Hann window
FFT size 4096 (93 ms, 10.77 Hz bins)
Window Hann
Peak list 1 peak per step, step 0.5 sWhat it reports
Peak row time 0.250 s, rank 1, 999.90 Hz, -6.00 dB
On the picture a single horizontal line at 1 kHz at about -6 dB (the nearest bin reads slightly lower)
Axis check the same line sits at the 1000 Hz row on linear, log and mel axesTips for best results
- A cut-off line that sits flat at 16 kHz or 19 kHz across the whole track is the mark of a lossy encode. Use the logarithmic axis and a dB window of -100 to -20 to see it.
- To see harmonics of a low note, use a long window (8192) and a linear axis up to a few kHz; on a log axis they bunch together at the top.
- To see timing detail, such as the onset of a drum hit, drop to 512 or 256. A hit then shows as a thin vertical line instead of a smear.
- If the picture looks mostly black, raise the quietest level to -80 or -60; a recording with a noise floor at -70 dB wastes most of a -140 dB range on nothing.
Common pitfalls
The picture is at most 2000 columns wide. A 30 minute file puts about a second in each column, so short events inside a column are averaged with the rest.
The levels are dB of FFT magnitude, not loudness. A bin reading -20 dB is not 20 dB quieter in loudness terms than a full-scale sine; use the LUFS meter for that.
A mono mix of two out-of-phase channels can cancel. A stereo recording with opposite-phase content will look quieter than it sounds.
Common errors and how to fix them
- The loudest level must be at least 10 dB above the quietest.
- Move one of the two dB sliders until the window is 10 dB or more wide.
- No spectral peaks above -90 dB were found in that range.
- Widen the frequency range, or check that the file is not silent.
Best practices
- Export the PNG with the same settings every time when comparing recordings, so the pictures can be compared by eye.
- State the FFT size and window next to any spectrogram you publish, since they change how it looks.
- Use the same dB window for before and after pictures of an edit.
Reading the three axes
On a linear axis every kilohertz gets the same height, so most of a speech or music picture is crowded into the bottom fifth while the top is mostly empty. It suits hum, harmonics and the cut-off of a lossy codec. A logarithmic axis gives every octave equal height, which matches how pitch is heard and puts an octave from 100 to 200 Hz as tall as one from 5 to 10 kHz. The mel axis is a compromise measured from listening tests: nearly linear to 1 kHz and then compressing, widely used for speech and in machine learning.
The frequency under the pointer is computed by inverting the axis, so the readout is right on all three.
Frequently asked questions
Why does my pure tone not read exactly 0 dB?
Only a full-scale sine centred on a bin reads 0 dB. A quieter tone reads lower by its level, and a frequency between two bins loses up to about 1.4 dB with a Hann window.
Can I export the data behind the picture?
The CSV holds the strongest peaks at regular times (time, rank, frequency and level), not every cell of the picture.