Main Content

# spectralRolloffPoint

Spectral rolloff point for audio signals and auditory spectrograms

## Syntax

``rolloffPoint = spectralRolloffPoint(x,f)``
``rolloffPoint = spectralRolloffPoint(x,f,Name,Value)``

## Description

example

````rolloffPoint = spectralRolloffPoint(x,f)` returns the spectral rolloff point of the signal, `x`, over time. How the function interprets `x` depends on the shape of `f`.```

example

````rolloffPoint = spectralRolloffPoint(x,f,Name,Value)` specifies options using one or more `Name,Value` pair arguments.```

## Examples

collapse all

Read in an audio file, calculate the rolloff point using default parameters, and then plot the results.

```[audioIn,fs] = audioread('Counting-16-44p1-mono-15secs.wav'); rolloffPoint = spectralRolloffPoint(audioIn,fs); t = linspace(0,size(audioIn,1)/fs,size(rolloffPoint,1)); plot(t,rolloffPoint) xlabel('Time (s)') ylabel('Rolloff Point (Hz)')``` Read in an audio file and then calculate the mel spectrogram using the `melSpectrogram` function. Calculate the rolloff point of the mel spectrogram over time. Plot the results.

```[audioIn,fs] = audioread('Counting-16-44p1-mono-15secs.wav'); [s,cf,t] = melSpectrogram(audioIn,fs); rolloffPoint = spectralRolloffPoint(s,cf); plot(t,rolloffPoint) xlabel('Time (s)') ylabel('Rolloff Point (Hz)')``` Read in an audio file.

`[audioIn,fs] = audioread('Counting-16-44p1-mono-15secs.wav');`

Calculate the rolloff point of the power spectrum over time. Calculate the rolloff point for 50 ms Hamming windows of data with 25 ms overlap. Use the range from 62.5 Hz to `fs`/2 for the rolloff point calculation. Plot the results.

```rolloffPoint = spectralRolloffPoint(audioIn,fs, ... 'Window',hamming(round(0.05*fs)), ... 'OverlapLength',round(0.025*fs), ... 'Range',[62.5,fs/2]); t = linspace(0,size(audioIn,1)/fs,size(rolloffPoint,1)); plot(t,rolloffPoint) xlabel('Time (s)') ylabel('Rolloff Point (Hz)')``` Create a `dsp.AudioFileReader` object to read in audio data frame-by-frame. Create a `dsp.SignalSink` to log the spectral rolloff point calculation.

```fileReader = dsp.AudioFileReader('Counting-16-44p1-mono-15secs.wav'); logger = dsp.SignalSink;```

In an audio stream loop:

1. Read in a frame of audio data.

2. Calculate the spectral rolloff point for the frame of audio.

3. Log the spectral rolloff point for later plotting.

To calculate the spectral rolloff point for only a given input frame, specify a window with the same number of samples as the input, and set the overlap length to zero. Plot the logged data.

```win = hamming(fileReader.SamplesPerFrame); while ~isDone(fileReader) audioIn = fileReader(); rolloffPoint = spectralRolloffPoint(audioIn,fileReader.SampleRate, ... 'Window',win, ... 'OverlapLength',0); logger(rolloffPoint) end plot(logger.Buffer) ylabel('Rolloff Point (Hz)')``` Use `dsp.AsyncBuffer` if

• The input to your audio stream loop has a variable samples-per-frame.

• The input to your audio stream loop has an inconsistent samples-per-frame with the analysis window of `spectralRolloffPoint`.

• You want to calculate the spectral rolloff point for overlapped data.

Create a `dsp.AsyncBuffer` object, reset the logger, and release the file reader.

```buff = dsp.AsyncBuffer; reset(logger) release(fileReader)```

Specify that the spectral rolloff point is calculated for 50 ms frames with a 25 ms overlap.

```fs = fileReader.SampleRate; samplesPerFrame = round(fs*0.05); samplesOverlap = round(fs*0.025); samplesPerHop = samplesPerFrame - samplesOverlap; win = hamming(samplesPerFrame); while ~isDone(fileReader) audioIn = fileReader(); write(buff,audioIn); while buff.NumUnreadSamples >= samplesPerHop audioBuffered = read(buff,samplesPerFrame,samplesOverlap); rolloffPoint = spectralRolloffPoint(audioBuffered,fs, ... 'Window',win, ... 'OverlapLength',0); logger(rolloffPoint) end end release(fileReader)```

Plot the logged data.

```plot(logger.Buffer) ylabel('Rolloff Point (Hz)')``` ## Input Arguments

collapse all

Input signal, specified as a vector, matrix, or 3-D array. How the function interprets `x` depends on the shape of `f`.

Data Types: `single` | `double`

Sample rate or frequency vector in Hz, specified as a scalar or vector, respectively. How the function interprets `x` depends on the shape of `f`:

• If `f` is a scalar, `x` is interpreted as a time-domain signal, and `f` is interpreted as the sample rate. In this case, `x` must be a real vector or matrix. If `x` is specified as a matrix, the columns are interpreted as individual channels.

• If `f` is a vector, `x` is interpreted as a frequency-domain signal, and `f` is interpreted as the frequencies, in Hz, corresponding to the rows of `x`. In this case, `x` must be a real L-by-M-by-N array, where L is the number of spectral values at given frequencies of `f`, M is the number of individual spectrums, and N is the number of channels.

• The number of rows of `x`, L, must be equal to the number of elements of `f`.

Data Types: `single` | `double`

### Name-Value Pair Arguments

Specify optional comma-separated pairs of `Name,Value` arguments. `Name` is the argument name and `Value` is the corresponding value. `Name` must appear inside quotes. You can specify several name and value pair arguments in any order as `Name1,Value1,...,NameN,ValueN`.

Example: `'Window',hamming(256)`

Threshold of rolloff point, specified as the comma-separated pair consisting of `'Threshold'` and a scalar between zero and one, exclusive.

Data Types: `single` | `double`

Note

The following name-value pair arguments apply if `x` is a time-domain signal. If `x` is a frequency-domain signal, name-value pair arguments are ignored.

Window applied in the time domain, specified as the comma-separated pair consisting of `'Window'` and a real vector. The number of elements in the vector must be in the range [1, `size(x,1)`]. The number of elements in the vector must also be greater than `OverlapLength`.

Data Types: `single` | `double`

Number of samples overlapped between adjacent windows, specified as the comma-separated pair consisting of `'OverlapLength'` and an integer in the range [0, `size(Window,1)`).

Data Types: `single` | `double`

Number of bins used to calculate the DFT of windowed input samples, specified as the comma-separated pair consisting of `'FFTLength'` and a positive scalar integer. If unspecified, `FFTLength` defaults to the number of elements in the `Window`.

Data Types: `single` | `double`

Frequency range in Hz, specified as the comma-separated pair consisting of `'Range'` and a two-element row vector of increasing real values in the range [0, `f`/2].

Data Types: `single` | `double`

Spectrum type, specified as the comma-separated pair consisting of `'SpectrumType'` and `'power'` or `'magnitude'`:

• `'power'` –– The spectral rolloff point is calculated for the one-sided power spectrum.

• `'magnitude'` –– The spectral rolloff point is calculated for the one-sided magnitude spectrum.

Data Types: `char` | `string`

## Output Arguments

collapse all

Spectral rolloff point in Hz, returned as a scalar, vector, or matrix. Each row of `rolloffPoint` corresponds to the spectral rolloff point of a window of `x`. Each column of `rolloffPoint` corresponds to an independent channel.

## Algorithms

The spectral rolloff point is calculated as described in :

`$\text{rolloffPoint}=i$`

such that

`$\sum _{k={b}_{1}}^{i}{s}_{k}=\kappa \sum _{k={b}_{1}}^{{b}_{2}}{s}_{k}$`

where

• sk is the spectral value at bin k.

• b1 and b2 are the band edges, in bins, over which to calculate the spectral spread.

• κ is the percentage of total energy contained between b1 and i. You can set κ using `Threshold`.

 Scheirer, E., and M. Slaney, "Construction and Evaluation of a Robust Multifeature Speech/Music Discriminator," IEEE International Conference on Acoustics, Speech, and Signal Processing. Volume 2, 1997, pp. 1221–1224.

## Support Get trial now