File Exchange

image thumbnail

Perceptual spectral centroid

version (715 KB) by Christopher Hummersone
Perceptually-informed spectral centroid.


Updated 05 May 2018

View Version History

GitHub view license on GitHub

NOTE: this function is now available from the IoSR Matlab Toolbox as iosr.auditory.perceptualCentroid.
PCMEAN = PERCEPTUALCENTROID(X,FS) calculates the spectral centroid of
signal X, sampled at FS, with respect to mel-frequency.
The algorithm first calculates the spectrogram of X; each segment has
the maximum of length(X)/8 or 2048 samples, calculated with 50% overlap
and windowed with a hamming window. The spectrogram function is the
built-in Matlab function SPECTROGRAM. The centroid is calculated with
respect to mels by converting the FFT bin frequencies to mels. PCMEAN
is the mean of the perceptual spectral centroids calculated for each
segment. The perceptual spectral centroid can also be calculated using
ERBs, cents, or hertz (see below).

X can be a vector, matrix, or multidimensional array;
PERCEPTUALCENTROID will operate along the first non-signleton
dimension, and return a value for each corresponding row/column/etc.

PCmean = perceptualCentroid(x,fs,'parameter',value) allows numerous
parameters to be specified. These parameters are:-
'cref' : {27.5} | scalar
Specifies the reference frequency when calulating the centroid
in terms of cents.
'dim' : {first non-singleton dimension} | integer
Specify the dimension over which to calculate the perceptual
spectral centroid.
'loudness' : {'none'} | 'A' | 'B' | 'C' | 'D' | 'ISO-226'
Specifies whether loudness weighting is applied to the spectrum
prior to the centroid calculation. The default is for no
weighting to be applied. 'A', 'B', 'C', and 'D' correspond to
frequency weighting curves defined in IEC 61672:2003; 'ISO-226'
applies loudness weighting derived from ISO 226:2003.
'nfft' : {max([length(x)/2, 2048])} | integer
Specifies SPECTROGRAM's FFT size.
'noverlap' : {nfft/2} | integer
Specifies the number of samples over which SPECTROGRAM's
segments overlap.
'output' : {'units'} | 'hz'
Specifies whether the output data are in Hz ('hz') or in units
determined by the 'scale' option ('units') (default).
'phon' : {65} | scalar
Specifies the loudness level if using ISO 226:2003-based
loudness weighting.
'scale' : {'mel'} | 'linear' | 'erb' | 'cents'
Specifies frequency scale use to calculate the centroid. 'mel'
uses the mel-frequency scale, 'linear' uses a linear frequency
scale (corresponding to the traditional spectral centroid
measure), 'erb' uses the equivalent-rectangular-bandwidth-rate
scale, and cents uses a scale based on musical cents with
respect to A-1 (27.5 Hz).
'window' : {hamming(nfft)} | vector
Specifies the window applied to each SPECTROGRAM segment.

[PCmean,PCstd,PCmax,PCmin,N] = ... returns additional information:-
PCmean : as described above.
PCstd : the standard deviation of the perceptual spectral
PCmax : the maximum of the perceptual spectral centroids.
PCmin : the minimum of the perceptual spectral centroids.
N : the sample size for each statistic.

For more information about the FFT calculation and its options, consult
the SPECTROGRAM documentation.


Example 1: Calculate the mel-frequency spectral centroid of random

fs = 44100;
x = randn(fs,1);
PC = perceptualCentroid(x,fs);

Example 2: Calculate the ERB-spaced spectral centroid of random
noise with the output in Hertz:

PC = perceptualCentroid(x,fs,'scale','erb','output','hz');

Example 3: Calculate the musically-spaced spectral centroid of
random noise using a 4096-point Hann window:

PC = perceptualCentroid(x,fs,'scale','cents',...

Authors: Chris Hummersone & Kirsten Hermes, 2014

Cite As

Christopher Hummersone (2020). Perceptual spectral centroid (, GitHub. Retrieved .

Comments and Ratings (0)

MATLAB Release Compatibility
Created with R2014a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!