Spectral Features
Spectral features are computed directly from the magnitude or power spectrum. They describe the shape, distribution, and energy concentration of the spectrum without attempting to model its finer structure. These are among the most intuitive and widely used descriptors in DSP.
All formulas below use the following notation:
- X(k) — complex spectrum at frequency bin k
- P(k) — power spectrum: P(k) = |X(k)|²
- fk — frequency corresponding to bin k: fk = k · Fs / N
- N — FFT size (number of samples in the window)
- Fs — sampling rate in Hz
- k — frequency bin index, ranging from 0 to N/2
All sums are taken over k = 0 to k = N/2, covering the full usable frequency range for real-valued signals.
Spectral Centroid
The spectral centroid is the center of gravity of the spectrum. It indicates where the "mass" of the spectrum lies in terms of frequency.
A higher centroid means the spectrum is shifted toward higher frequencies — the sound is "brighter" or "sharper." A lower centroid indicates more energy in the lower frequencies — the sound is "darker" or "warmer." This feature is commonly used in music genre classification, timbre analysis, and distinguishing vowel sounds in speech.
Spectral Spread (Bandwidth)
The spectral spread is the standard deviation of the spectrum around the centroid. It measures how wide the spectral distribution is.
A small spread indicates a tonal signal — energy is concentrated around a single frequency (e.g., a pure tone). A large spread suggests a noisy signal or one with a broad frequency range. This feature is useful for distinguishing tonal from noisy signals and for vibration analysis.
Spectral Skewness
Spectral skewness is the third central moment of the spectrum, normalized by the spread. It measures the asymmetry of the spectral distribution.
A positive skewness indicates that the spectrum is asymmetric toward higher frequencies — the tail extends toward the high end. A negative skewness means the opposite — the spectrum leans toward lower frequencies. This feature is used in musical timbre analysis and mechanical diagnostics, where changes in asymmetry can indicate wear or damage.
Spectral Kurtosis
Spectral kurtosis is the fourth central moment, normalized by the spread and shifted by 3 so that a normal distribution gives zero.
A positive kurtosis means the spectrum has a sharp, narrow peak — energy is highly concentrated. A negative kurtosis means the spectrum is flat or has multiple peaks. This feature is used for detecting impulsive noise and analyzing machine vibrations, where impacts or sudden events produce high kurtosis values.
Spectral Roll-off
The spectral roll-off is the frequency below which a certain percentage R (typically 85% or 95%) of the total spectral energy is contained. In other words, it is the lowest frequency f such that the cumulative energy up to f reaches at least R% of the total energy.
This feature distinguishes signals with rich high-frequency content (e.g., music) from those with limited frequency range (e.g., speech). A high roll-off frequency means significant energy extends to high frequencies; a low roll-off means the signal is mostly low-frequency. It is widely used in speech recognition and audio content classification.
Spectral Flux
The spectral flux measures the change in the spectrum between two consecutive frames. It is defined as the squared difference between the magnitude spectra of adjacent frames.
High flux values indicate rapid changes in the spectrum — onsets of notes, percussive attacks, or fast transients. Low flux means the spectrum is stable over time. This feature is used for onset detection, audio segmentation, and rhythm analysis.
Spectral Entropy
Spectral entropy measures the "flatness" or "spread" of the spectrum using Shannon's information entropy. The power spectrum is first normalized to a probability distribution.
A high entropy indicates a flat, noise-like spectrum where energy is distributed evenly across all frequencies. A low entropy indicates a tonal, peaked spectrum where energy is concentrated in a few bins. This feature is used to distinguish between tonal and noisy signals, and in speech/music discrimination.
Spectral Flatness
Spectral flatness is the ratio of the geometric mean to the arithmetic mean of the power spectrum. It is often expressed in decibels.
where K = N/2 + 1 is the number of frequency bins.
A flatness close to 1 (0 dB) means the spectrum is flat — characteristic of white noise. A flatness close to 0 (very negative dB) means the spectrum is highly peaked — characteristic of a pure tone or a highly harmonic signal. This feature is closely related to spectral entropy but is computationally simpler.
Relative Energy in Frequency Bands
Instead of a single number, this feature provides a vector of values. The spectrum is divided into several frequency bands (e.g., 0–250 Hz, 250–1000 Hz, 1000–4000 Hz, 4000–Nyquist), and for each band we compute the ratio of energy in that band to the total spectral energy.
This describes the spectral balance of the signal — how energy is distributed across the frequency range. It is used in instrument classification, environmental sound analysis, and equalization applications.
Harmonic Features
Harmonic features go beyond the simple spectral shape descriptors above. They attempt to model the harmonic structure of the signal — the presence of multiples of a fundamental frequency. These features include:
- Harmonic-to-Noise Ratio (HNR) — the ratio of periodic (harmonic) energy to noise energy.
- Inharmonicity — the degree to which overtones deviate from exact multiples of the fundamental.
- Odd-to-Even Harmonic Ratio — the ratio of energy in odd harmonics to even harmonics, used in instrument classification (e.g., clarinet vs. violin).
These features are more complex to compute, as they require pitch detection and harmonic tracking. They are covered separately in a dedicated article on harmonic analysis.