Skip to main content

Spectrogram

What is a spectrogram?​

A spectrogram (also called a sonogram or voiceprint) is a chart of how the frequencies in a signal change over time. Time runs along the horizontal axis and frequency up the vertical axis. The colour of each point shows how strong that frequency was at that moment, usually in decibels (dB).

A spectrogram of a test signal: two steady horizontal lines at 1,000 Hz and 3,000 Hz, a dashed line at 5,500 Hz, and bright diagonal lines sweeping up from 500 Hz to 7,000 Hz, over a dark speckled background of noise

A live spectrogram of a test signal (sample data): two steady tones, a tone that pulses on and off, and a sweep that repeats every four seconds, over background noise. Try the interactive version.

Key takeaways
  • A spectrogram shows frequency against time, with colour for strength, usually in decibels.
  • Each shape has a meaning. Flat lines are steady tones, stacked lines are harmonics, slopes are changing pitch, vertical lines are clicks, and speckle is noise.
  • It is built from many short Fourier transforms (the short-time Fourier transform, or STFT). The window length trades detail in time against detail in frequency.
  • The highest frequency it can show is half the sample rate (the Nyquist frequency).
  • It is used in audio, speech, wildlife sound, machine monitoring, radar, sonar, radio and medicine.

How to read a spectrogram​

Anatomy of a spectrogram: time on the horizontal axis, frequency on the vertical axis, colour from quiet (black) to loud (pale yellow), with a steady tone as a horizontal line, a sweep as a rising line and a click as a vertical line

  1. Check the colour scale. It tells you which colours are loud and which are quiet. Levels are usually in decibels, a logarithmic scale, so quiet detail and loud tones fit on one chart. The darkest colour is usually the noise floor: the level of the background when nothing else is happening.
  2. Check the axes. Time usually runs left to right; in a scrolling waterfall display it may run top to bottom. Note whether the frequency axis is evenly spaced (linear) or squeezed at the top (logarithmic or mel), and where it stops.
  3. Read one vertical slice. A slice is one moment in time. Reading up it tells you which frequencies were present then, and how strong each one was.
  4. Follow the shapes across time. Lines and patches that persist, move or repeat are the sounds or signals. The table below says what each shape usually is.
  5. Compare against the noise floor. Anything only slightly brighter than the background may be noise; a feature well above it is a real signal.

Spectrogram patterns: what each shape means​

What you seeWhat it isExamples
A flat horizontal lineA steady tone at one frequencyMains hum at 50 or 60 Hz, a whistle, a fan or motor running at constant speed
A stack of evenly spaced parallel linesA fundamental frequency and its harmonics, at whole-number multiples of itA sung or spoken vowel, a violin note, a rotating machine
A rising or falling lineA frequency that changes over time: a sweep or chirpA siren, birdsong, an engine speeding up, a test sweep
A dashed lineA tone that switches on and offAn alarm beep, Morse code, the 5,500 Hz tone in the chart above
A thin vertical lineA short, sharp sound containing many frequencies at onceA click, knock, drum hit or footstep
A speckled haze over many frequenciesBroadband noiseHiss, wind, rain, air conditioning
Broad bands of energy that shift in speechFormants: resonances of the mouth and throatVowels; each vowel has its own formant pattern
A gap from top to bottomSilence or a dropoutA pause in speech, a break in a recording

How to describe a spectrogram​

To write up what a spectrogram shows, describe each feature in turn with this template:

There is [a steady tone / harmonics / a sweep / a burst / noise] at [frequency or range], at about [level] dB, which [lasts throughout / repeats every … / rises from … to …].

For example, using the chart above: "There is a noise floor of about −80 dB across the whole band. Two steady tones last throughout: a strong one at 1,000 Hz, at about −25 dB, and a weaker one at 3,000 Hz, at about −40 dB. A third tone at 5,500 Hz switches on for one second in every two. A sweep rises from 500 Hz to 7,000 Hz every four seconds, then jumps back down and starts again."

How a spectrogram is made​

You don't need the maths to read a spectrogram, but knowing how it is made explains what it can and can't show.

  1. Cut the signal into short windows, for example 1,024 samples each, usually overlapping.
  2. Taper each window with a window function, such as a Hann window, so the cut edges don't add false frequencies.
  3. Take a Fourier transform of each window. In practice this is a fast Fourier transform (FFT). It measures how strong each frequency is in that window. Together, these steps are the short-time Fourier transform (STFT).
  4. Convert to decibels and colour it. Each window's result becomes one column of the spectrogram, and each frequency band becomes one row.

The highest frequency a spectrogram can show is half the signal's sample rate, the Nyquist frequency: 22,050 Hz for audio sampled at 44,100 Hz. Before computers, spectrograms were drawn by an analogue machine, the sound spectrograph, described by researchers at Bell Telephone Laboratories in 1946.

Window length: time detail against frequency detail​

A long window separates close frequencies but blurs when things happened; a short window shows timing sharply but merges nearby frequencies.

Window (at 44,100 samples per second)Time per columnFrequency band widthGood for
256 samplesabout 6 msabout 172 HzClicks, drum hits and other fast events
1,024 samplesabout 23 msabout 43 HzGeneral audio and speech
4,096 samplesabout 93 msabout 11 HzSeparating close musical notes or steady machine tones

Band width is the sample rate divided by the window length; time per column is the window length divided by the sample rate. Overlapping windows add columns more often, but they don't sharpen the time detail.

Types of spectrogram​

TypeWhat changesTypical use
Linear spectrogramFrequency axis evenly spaced, as in the chart aboveEngineering, vibration, radio
Log-frequency spectrogramFrequency axis on a logarithmic scale, so each octave takes the same heightMusic analysis
Mel spectrogramFrequency axis on the mel scale, which spaces frequencies roughly as people hear pitchSpeech recognition and audio machine learning
Waterfall displayA spectrogram that scrolls as new data arrives, often from top to bottomRadio and software-defined radio (SDR), sonar

When to use a spectrogram​

Use a spectrogram when the frequencies in a signal change over time and you need to see when each one starts, stops or moves. Common uses:

  • audio and music: finding hum, clicks, noise and clipping, checking mixes, and analysing notes and harmonics;
  • speech: phonetics and voice analysis, where vowels show as formant bands;
  • wildlife sound: identifying birdsong and bat, whale and dolphin calls;
  • vibration and condition monitoring: spotting a bearing or gear fault as a new tone appearing or drifting;
  • radar and sonar: detecting targets and how they move;
  • medicine: time-frequency analysis of EEG (brain wave) signals;
  • radio: watching which channels are busy, on spectrum analysers and SDR waterfall displays.
ChartBest for
SpectrogramHow the frequencies in a signal change over time
Waveform (line chart)The raw signal, amplitude against time: good for loudness and timing, poor for pitch
Spectrum (FFT plot)Level against frequency at one moment: precise levels, but no history
Power spectral densityNoise power per hertz averaged over a long stretch: a steady, comparable level, but no history
HeatmapAny grid of values. A spectrogram is a heatmap whose axes are time and frequency

Many tools show a waveform, a spectrum and a spectrogram together, as in the SciChart audio analyser demo linked below.

Common spectrogram mistakes​

  • Skipping the window function. Without tapering, energy from a strong tone leaks into the bands either side of it, which can hide quieter signals nearby.
  • Plotting raw amplitude instead of decibels. On a linear scale only the loudest sounds show; everything else is lost in the darkest colour.
  • Setting the colour range badly. Set the bottom of the range near the noise floor and the top just above the loudest signal. Too wide a range makes everything look dark; too narrow a range turns noise into false detail and flattens the loud parts.
  • Ignoring the Nyquist limit. Frequencies above half the sample rate don't vanish: they fold back down as false lines (aliasing). Filter out high frequencies before sampling.
  • Using a linear frequency axis for music or speech. Most of the interest is in the low frequencies, which a linear axis squeezes into the bottom of the chart. Use a logarithmic or mel axis.
  • Comparing spectrograms made with different settings. A different window length, colour range or decibel reference can make the same signal look different. Keep the settings the same when you compare.

How to create a spectrogram in JavaScript, React or Angular​

In SciChart.js a spectrogram is a real-time, scrolling heatmap. You compute each new spectrum, for example with an FFT of the latest samples, and SciChart.js draws it with WebGL and WebGPU, so the chart keeps up with live data. The spectrogram below is generated live: scroll to zoom into a frequency band, drag up or down to pan, double-click to reset, and hover to read the level.

Here is the code for this chart:

// Create a real-time JavaScript spectrogram with SciChart.js
const {
SciChartSurface,
HeatmapLegend,
NumericAxis,
NumberRange,
EAutoRange,
EXyDirection,
UniformHeatmapRenderableSeries,
UniformHeatmapDataSeries,
HeatmapColorMap,
SciChartJsNavyTheme,
CursorModifier,
MouseWheelZoomModifier,
ZoomPanModifier,
ZoomExtentsModifier
} = SciChart;
// or, for npm, import { SciChartSurface, ... } from "scichart"

const { wasmContext, sciChartSurface } = await SciChartSurface.create(chartDiv, {
theme: new SciChartJsNavyTheme()
});

// x: time. AutoRange "Always" keeps the newest data in view as the chart scrolls
sciChartSurface.xAxes.add(
new NumericAxis(wasmContext, { axisTitle: "Time (s)", autoRange: EAutoRange.Always, labelPrecision: 0 })
);
// y: frequency
sciChartSurface.yAxes.add(
new NumericAxis(wasmContext, {
axisTitle: "Frequency (Hz)",
visibleRange: new NumberRange(0, MAX_FREQUENCY),
labelPrecision: 0
})
);

// The colour map: quiet (-90 dB) is black, loud (-10 dB) is pale yellow
const colorMap = new HeatmapColorMap({
minimum: -90,
maximum: -10,
gradientStops: [
{ offset: 0, color: "#000004" },
{ offset: 0.2, color: "#420A68" },
{ offset: 0.4, color: "#932667" },
{ offset: 0.6, color: "#DD513A" },
{ offset: 0.8, color: "#FCA50A" },
{ offset: 1, color: "#FCFFA4" }
]
});

// Your data: zValues[frequency band][time column], in dB. Fill the first 10 seconds
const zValues = Array.from({ length: FREQUENCY_BINS }, () => []);
let time = 0;
for (let i = 0; i < TIME_COLUMNS; i++, time += SECONDS_PER_COLUMN) {
spectrumAt(time).forEach((level, bin) => zValues[bin].push(level));
}

const dataSeries = new UniformHeatmapDataSeries(wasmContext, {
zValues,
xStart: 0,
xStep: SECONDS_PER_COLUMN, // each column is 50 ms of time
yStart: 0,
yStep: MAX_FREQUENCY / FREQUENCY_BINS // each row is one frequency band
});
sciChartSurface.renderableSeries.add(new UniformHeatmapRenderableSeries(wasmContext, { dataSeries, colorMap }));

await HeatmapLegend.create(legendDiv, {
theme: new SciChartJsNavyTheme(),
colorMap,
yAxisOptions: { axisTitle: "Level (dB)" }
});

// Every 50 ms: drop the oldest column, add the newest, and move the start time on
const timer = setInterval(() => {
spectrumAt(time).forEach((level, bin) => {
zValues[bin].shift();
zValues[bin].push(level);
});
time += SECONDS_PER_COLUMN;
dataSeries.xStart = time - TIME_COLUMNS * SECONDS_PER_COLUMN;
dataSeries.setZValues(zValues);
}, SECONDS_PER_COLUMN * 1000);
// Stop the timer when the chart is deleted
sciChartSurface.addDeletable({ delete: () => clearInterval(timer) });

// Zoom into a frequency band with the mouse wheel, drag up and down to pan,
// double-click to reset, and hover to read the level
sciChartSurface.chartModifiers.add(
new CursorModifier({
showTooltip: true,
showAxisLabels: false,
tooltipDataTemplate: (seriesInfos) =>
seriesInfos
.filter((info) => info.isHit)
.map((info) => {
const bin = Math.floor(info.yValue / dataSeries.yStep);
const column = Math.floor((info.xValue - dataSeries.xStart) / dataSeries.xStep);
const level = zValues[bin]?.[column];
return `${Math.round(info.yValue)} Hz: ${level === undefined ? "-" : level.toFixed(0)} dB`;
})
}),
new MouseWheelZoomModifier({ xyDirection: EXyDirection.YDirection }),
new ZoomPanModifier({ xyDirection: EXyDirection.YDirection }),
new ZoomExtentsModifier()
);

Key points:

  • A UniformHeatmapDataSeries holds the spectrogram as a 2D array, zValues[frequency band][time column]. yStep is the width of each frequency band (sample rate divided by FFT size) and xStep is the time between spectra.
  • To scroll, drop the oldest column, add the newest, call setZValues() and move xStart on. An x-axis with autoRange: EAutoRange.Always follows the newest data.
  • A HeatmapColorMap with minimum and maximum in decibels sets the colour scale; a HeatmapLegend shows it.
  • SciChart.js draws the chart; the FFT is up to you. The audio analyser in the demo app includes an FFT, a microphone input, a waveform and a spectrum alongside its spectrogram.

See it in the demo app: JavaScript spectrogram · React spectrogram · Angular spectrogram

Go deeper: SciChart.js spectrogram documentation, including updating a heatmap in real time and colour maps and legends. New to heatmaps? Read our heatmap guide.

Frequently asked questions​

What is a spectrogram used for?​

A spectrogram is used to see how the frequencies in a signal change over time. Audio engineers use it to find hum, clicks and noise; speech scientists to study voices; biologists to identify bird, bat and whale calls; engineers to spot machine faults from vibration; and radio, radar and sonar operators to watch signals and targets.

How do you read a spectrogram?​

Check the colour scale first, so you know which colours are loud and which are quiet. Then read left to right through time: a horizontal line is a steady tone, stacked parallel lines are a sound and its harmonics, a rising or falling line is a changing pitch, a vertical line is a click or other short sound, and a speckled background is noise.

How does a spectrogram work?​

The signal is cut into short, usually overlapping windows. A Fourier transform (in practice, an FFT) of each window measures how strong each frequency is in it, and the result becomes one column of the spectrogram. This is called the short-time Fourier transform (STFT).

What is a mel spectrogram?​

A mel spectrogram is a spectrogram whose frequency axis uses the mel scale, which spaces frequencies roughly the way people hear pitch: more detail at low frequencies, less at high ones. Mel spectrograms are widely used as the input to speech recognition and other audio machine-learning models.

What is the difference between a spectrogram, a spectrum and a spectrograph?​

A spectrum shows the strength of each frequency at one moment, as a line of level against frequency. A spectrogram stacks many spectra side by side over time and shows level as colour. A spectrograph is an instrument that produces a spectrum or spectrogram, such as the sound spectrograph used for speech or an optical spectrograph that splits light.

How do I make a spectrogram in JavaScript?​

Compute a spectrum (for example with an FFT) for each new block of samples. With SciChart.js, put the spectra in a UniformHeatmapDataSeries, one column per time step and one row per frequency band, draw it with a UniformHeatmapRenderableSeries and a HeatmapColorMap in decibels, and call setZValues() as new columns arrive so the chart scrolls. The same chart works in React with scichart-react and in Angular with scichart-angular.

Sources​