GestureSynth.me

Music calculator

Spectral Centroid Calculator

Calculate the spectral centroid from bin frequencies and linear magnitudes. Explore how changing one partial shifts the center of a spectrum.

spectral centroid calculator

Spectral Centroid Calculator guide

A spectral centroid describes the frequency around which a frame's magnitude is balanced. Enter a short list of frequency coordinates and a matching list of linear magnitudes. It can describe a set of measured partials or selected bins from a uniformly spaced spectrum.

Play the instrument ↑
Default result
525 Hz spectral centroid

Calculation and units

Multiply each frequency by its weight, add those products and divide by the sum of all weights. The normalization leaves the result in hertz. A zero weight ignores one bin while retaining its position in the list. With nonnegative weights, the result falls between the outermost active frequencies.

Worked examples

Select a named case in the Worked example control to load these values. You can then edit any input to compare the result.

Three-bin mixture

Bin frequencies (Hz) = 100 500 1000 · Linear magnitude weights = 1 2 1.

525 Hz spectral centroid. 3 bins · sum of magnitude weights 4. The centroid is the first moment of the normalized magnitude spectrum.

The middle bin has the greatest weight, yet the higher component pulls the average above its frequency. This separates a spectral center from a peak detector.

One active bin

Bin frequencies (Hz) = 100 500 1000 · Linear magnitude weights = 0 1 0.

500 Hz spectral centroid. 3 bins · sum of magnitude weights 1. The centroid is the first moment of the normalized magnitude spectrum.

Only the middle component contributes to the numerator and denominator. A nonzero level scale would give the same frequency for this one-bin spectrum.

Equal components

Bin frequencies (Hz) = 100 500 1000 · Linear magnitude weights = 1 1 1.

533.333333 Hz spectral centroid. 3 bins · sum of magnitude weights 3. The centroid is the first moment of the normalized magnitude spectrum.

Identical magnitudes yield the arithmetic mean of the three coordinates. The frequencies can be unevenly spaced when they describe separate spectral lines.

Brighter blend

Bin frequencies (Hz) = 100 500 1000 · Linear magnitude weights = 1 2 4.

728.571429 Hz spectral centroid. 3 bins · sum of magnitude weights 7. The centroid is the first moment of the normalized magnitude spectrum.

Increasing the highest component moves the center upward. This supplies a reproducible comparison for a gesture that opens a filter across a held note.

Scale every magnitude

Bin frequencies (Hz) = 100 500 1000 · Linear magnitude weights = 10 20 10.

525 Hz spectral centroid. 3 bins · sum of magnitude weights 40. The centroid is the first moment of the normalized magnitude spectrum.

Multiplying every magnitude by ten preserves their proportions. Compare against the first case to see why uniform gain alone leaves the answer unchanged.

Include DC deliberately

Bin frequencies (Hz) = 0 200 400 · Linear magnitude weights = 3 1 1.

120 Hz spectral centroid. 3 bins · sum of magnitude weights 5. The centroid is the first moment of the normalized magnitude spectrum.

A DC component contributes weight at zero hertz. Remove DC before analysis if the goal is a descriptor of audible timbre alone.

Interpreting the result

To compare a brighter and darker synth setting, use the same window, frequency coverage and magnitude convention for both. Scaling every partial by the same factor leaves the answer fixed. Redistributing energy toward upper partials can move it even when the fundamental stays put.

Measurement and model limits

This tool uses discrete magnitude weights. A power-weighted center is a different descriptor. If you sample a continuous density at uneven intervals, convert each sample to an appropriate integrated bin weight first. An entirely silent frame has no defined centroid.

Answers before you play

Common questions

Can I paste decibels into the weights field?

Convert magnitude decibels to a positive amplitude ratio with ten raised to dB divided by twenty. Negative values cannot serve as magnitude weights.

Is the centroid the perceived pitch?

A fundamental frequency marks a repetition rate. The centroid instead summarizes spectral balance and can lie between components.

Can I enter a DC component?

Yes. Include frequency zero with its measured magnitude when DC belongs in the descriptor. It can pull the average down substantially.

What separates frequencies and weights?

Use spaces or commas within each box and keep both lists in the same order. Enter ascending frequencies so each weight has an unambiguous coordinate.