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 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.
- 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
- 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.
- 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.
- 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.
- 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.
- 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 see | What it is | Examples |
|---|---|---|
| A flat horizontal line | A steady tone at one frequency | Mains hum at 50 or 60 Hz, a whistle, a fan or motor running at constant speed |
| A stack of evenly spaced parallel lines | A fundamental frequency and its harmonics, at whole-number multiples of it | A sung or spoken vowel, a violin note, a rotating machine |
| A rising or falling line | A frequency that changes over time: a sweep or chirp | A siren, birdsong, an engine speeding up, a test sweep |
| A dashed line | A tone that switches on and off | An alarm beep, Morse code, the 5,500 Hz tone in the chart above |
| A thin vertical line | A short, sharp sound containing many frequencies at once | A click, knock, drum hit or footstep |
| A speckled haze over many frequencies | Broadband noise | Hiss, wind, rain, air conditioning |
| Broad bands of energy that shift in speech | Formants: resonances of the mouth and throat | Vowels; each vowel has its own formant pattern |
| A gap from top to bottom | Silence or a dropout | A 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.
- Cut the signal into short windows, for example 1,024 samples each, usually overlapping.
- Taper each window with a window function, such as a Hann window, so the cut edges don't add false frequencies.
- 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).
- 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 column | Frequency band width | Good for |
|---|---|---|---|
| 256 samples | about 6 ms | about 172 Hz | Clicks, drum hits and other fast events |
| 1,024 samples | about 23 ms | about 43 Hz | General audio and speech |
| 4,096 samples | about 93 ms | about 11 Hz | Separating 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
| Type | What changes | Typical use |
|---|---|---|
| Linear spectrogram | Frequency axis evenly spaced, as in the chart above | Engineering, vibration, radio |
| Log-frequency spectrogram | Frequency axis on a logarithmic scale, so each octave takes the same height | Music analysis |
| Mel spectrogram | Frequency axis on the mel scale, which spaces frequencies roughly as people hear pitch | Speech recognition and audio machine learning |
| Waterfall display | A spectrogram that scrolls as new data arrives, often from top to bottom | Radio 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.
| Chart | Best for |
|---|---|
| Spectrogram | How 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 density | Noise power per hertz averaged over a long stretch: a steady, comparable level, but no history |
| Heatmap | Any 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:
- JavaScript
- React
- Angular
// 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()
);
import { SciChartReact } from "scichart-react";
import {
SciChartSurface,
NumericAxis,
EAutoRange,
UniformHeatmapRenderableSeries,
UniformHeatmapDataSeries,
HeatmapColorMap,
SciChartJsNavyTheme
} from "scichart";
const BINS = 256; // frequency bands per spectrum
const COLUMNS = 200; // spectra kept on screen
// initChart builds the chart; SciChartReact creates it, sizes it and cleans it up
const initChart = async (rootElement: string | HTMLDivElement) => {
const { wasmContext, sciChartSurface } = await SciChartSurface.create(rootElement, {
theme: new SciChartJsNavyTheme()
});
sciChartSurface.xAxes.add(new NumericAxis(wasmContext, { axisTitle: "Time (s)", autoRange: EAutoRange.Always }));
sciChartSurface.yAxes.add(new NumericAxis(wasmContext, { axisTitle: "Frequency (Hz)" }));
// zValues[frequency band][time column], in dB
const zValues: number[][] = Array.from({ length: BINS }, () => new Array(COLUMNS).fill(-90));
const dataSeries = new UniformHeatmapDataSeries(wasmContext, {
zValues,
xStart: 0,
xStep: 0.05, // seconds per spectrum
yStart: 0,
yStep: 8000 / BINS // Hz per frequency band
});
sciChartSurface.renderableSeries.add(
new UniformHeatmapRenderableSeries(wasmContext, {
dataSeries,
colorMap: new HeatmapColorMap({
minimum: -90,
maximum: -10,
gradientStops: [
{ offset: 0, color: "#000004" },
{ offset: 0.5, color: "#932667" },
{ offset: 1, color: "#FCFFA4" }
]
})
})
);
// Each time a new spectrum arrives, scroll the chart by one column
const timer = setInterval(() => {
const spectrum = getYourNextSpectrum(); // one dB level per frequency band, e.g. from an FFT
spectrum.forEach((level, bin) => {
zValues[bin].shift();
zValues[bin].push(level);
});
dataSeries.xStart += dataSeries.xStep;
dataSeries.setZValues(zValues);
}, 50);
sciChartSurface.addDeletable({ delete: () => clearInterval(timer) });
return { sciChartSurface };
};
export const Spectrogram = () => (
<SciChartReact initChart={initChart} style={{ width: "100%", height: 400 }} />
);
import { Component } from "@angular/core";
import { ScichartAngularComponent } from "scichart-angular";
import {
SciChartSurface,
NumericAxis,
EAutoRange,
UniformHeatmapRenderableSeries,
UniformHeatmapDataSeries,
HeatmapColorMap,
SciChartJsNavyTheme
} from "scichart";
const BINS = 256; // frequency bands per spectrum
const COLUMNS = 200; // spectra kept on screen
@Component({
selector: "app-spectrogram",
standalone: true,
imports: [ScichartAngularComponent],
template: `<scichart-angular [initChart]="initChart" style="display: block; width: 100%; height: 400px"></scichart-angular>`
})
export class SpectrogramComponent {
// initChart builds the chart; scichart-angular creates it, sizes it and cleans it up
initChart = async (rootElement: string | HTMLDivElement) => {
const { wasmContext, sciChartSurface } = await SciChartSurface.create(rootElement, {
theme: new SciChartJsNavyTheme()
});
sciChartSurface.xAxes.add(new NumericAxis(wasmContext, { axisTitle: "Time (s)", autoRange: EAutoRange.Always }));
sciChartSurface.yAxes.add(new NumericAxis(wasmContext, { axisTitle: "Frequency (Hz)" }));
// zValues[frequency band][time column], in dB
const zValues: number[][] = Array.from({ length: BINS }, () => new Array(COLUMNS).fill(-90));
const dataSeries = new UniformHeatmapDataSeries(wasmContext, {
zValues,
xStart: 0,
xStep: 0.05, // seconds per spectrum
yStart: 0,
yStep: 8000 / BINS // Hz per frequency band
});
sciChartSurface.renderableSeries.add(
new UniformHeatmapRenderableSeries(wasmContext, {
dataSeries,
colorMap: new HeatmapColorMap({
minimum: -90,
maximum: -10,
gradientStops: [
{ offset: 0, color: "#000004" },
{ offset: 0.5, color: "#932667" },
{ offset: 1, color: "#FCFFA4" }
]
})
})
);
// Each time a new spectrum arrives, scroll the chart by one column
const timer = setInterval(() => {
const spectrum = getYourNextSpectrum(); // one dB level per frequency band, e.g. from an FFT
spectrum.forEach((level, bin) => {
zValues[bin].shift();
zValues[bin].push(level);
});
dataSeries.xStart += dataSeries.xStep;
dataSeries.setZValues(zValues);
}, 50);
sciChartSurface.addDeletable({ delete: () => clearInterval(timer) });
return { sciChartSurface };
};
}
Key points:
- A UniformHeatmapDataSeries holds the spectrogram as a 2D array,
zValues[frequency band][time column].yStepis the width of each frequency band (sample rate divided by FFT size) andxStepis the time between spectra. - To scroll, drop the oldest column, add the newest, call
setZValues()and movexStarton. An x-axis withautoRange: EAutoRange.Alwaysfollows the newest data. - A HeatmapColorMap with
minimumandmaximumin 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
- Koenig, W., Dunn, H. K. and Lacy, L. Y. (1946), The Sound Spectrograph. The Journal of the Acoustical Society of America, 18(1). The Bell Telephone Laboratories instrument that first made spectrograms practical.
- Harris, F. J. (1978), On the use of windows for harmonic analysis with the discrete Fourier transform. Proceedings of the IEEE, 66(1). Window functions and spectral leakage.
- Stevens, S. S., Volkmann, J. and Newman, E. B. (1937), A Scale for the Measurement of the Psychological Magnitude Pitch. The Journal of the Acoustical Society of America, 8(3). The origin of the mel scale.
- SciPy, scipy.signal.spectrogram. A reference implementation of the STFT spectrogram, with its window, overlap and scaling options.