spectral bandwidth calculator
Spectral Bandwidth Calculator for Audio guide
Spectral bandwidth here describes the spread of a single audio frame around its weighted frequency center. Supply a list of nonnegative magnitudes or powers and keep that convention consistent between frames. Enter the frequency of the first bin center and the fixed step between adjacent centers in hertz.
Play the instrument ↑- Default result
- 100 Hz spectral bandwidth
Calculation and units
Divide each weight by the sum of all weights. The centroid is the sum of the bin frequencies multiplied by those normalized weights. Square each frequency's distance from the centroid, average those squares with the same weights and take the square root. This second-order spectral moment has units of hertz.
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.
Two equal edges
Nonnegative bin weights = 1 0 1 · Bin spacing (Hz) = 100 · First bin center (Hz) = 0.
100 Hz spectral bandwidth. Weighted centroid 100 Hz. Sum of weights 2 across 3 bins. Second-order spread uses each weight divided by the total.
The populated bins lie the same distance either side of their weighted mean. That distance is also the reported root mean square spread.
Shift the frequency origin
Nonnegative bin weights = 1 0 1 · Bin spacing (Hz) = 100 · First bin center (Hz) = 500.
100 Hz spectral bandwidth. Weighted centroid 600 Hz. Sum of weights 2 across 3 bins. Second-order spread uses each weight divided by the total.
Shifting every frequency by a common amount moves the centroid by exactly that amount. The spread about the new center remains unchanged.
Energy in a single bin
Nonnegative bin weights = 0 0 2 0 · Bin spacing (Hz) = 100 · First bin center (Hz) = 0.
0 Hz spectral bandwidth. Weighted centroid 200 Hz. Sum of weights 2 across 4 bins. Second-order spread uses each weight divided by the total.
One occupied location has no deviation from its own center. Its bandwidth is zero even though its center frequency is positive.
Unequal edges
Nonnegative bin weights = 1 0 3 · Bin spacing (Hz) = 100 · First bin center (Hz) = 0.
86.60254 Hz spectral bandwidth. Weighted centroid 150 Hz. Sum of weights 4 across 3 bins. Second-order spread uses each weight divided by the total.
The stronger upper component pulls the centroid upward. The same two endpoint frequencies can therefore give a different weighted width.
Wider bin spacing
Nonnegative bin weights = 1 0 1 · Bin spacing (Hz) = 200 · First bin center (Hz) = 0.
200 Hz spectral bandwidth. Weighted centroid 200 Hz. Sum of weights 2 across 3 bins. Second-order spread uses each weight divided by the total.
Stretching the frequency grid doubles the distance of each occupied bin from the mean. The index positions of the components remain the same.
Uniform narrow band
Nonnegative bin weights = 1 1 1 1 1 · Bin spacing (Hz) = 25 · First bin center (Hz) = 200.
35.355339 Hz spectral bandwidth. Weighted centroid 250 Hz. Sum of weights 5 across 5 bins. Second-order spread uses each weight divided by the total.
A central bin has zero deviation, while the outer symmetric pairs contribute increasingly large squared deviations.
Interpreting the result
An isolated occupied bin has zero width under this definition. Two equal components at opposite ends of a range have a width equal to half their separation. Moving every component up by the same number of hertz translates the centroid and leaves the bandwidth unchanged. Changing the frequency step stretches the entire distribution.
Measurement and model limits
The weights determine the result. Squaring magnitudes into power emphasizes stronger components. Frequency bins from a logarithmic filter bank are generally unevenly spaced and cannot be represented by one fixed step. A filter passband measured between two attenuation points or an optical wavelength range uses a different definition of width.
Music theory tools → · Spectral Centroid Calculator → · librosa spectral bandwidth definition →
Answers before you play
Common questions
Can I paste a spectrum in decibels?
Convert levels back to linear weights before entry. Use the power or amplitude conversion matching your reference and the desired weighting convention.
Should empty bins be removed?
Keep interior zeros so that the remaining weights retain the correct separation. If you trim the start, move the first-bin frequency to its new location.
What if the total weight is zero?
There is no distribution from which to calculate a centroid. An entirely silent spectrum is rejected instead of producing an apparent zero-width tone.
How does FFT leakage affect the answer?
A tone between bin centers can spread its energy over neighboring bins. A nonzero width can therefore reflect record length and window choice as well as source bandwidth.