# integratedLoudness

Measure integrated loudness and loudness range

## Syntax

## Description

specifies
the channel weights used to compute the integrated loudness. `loudness`

= integratedLoudness(`audioIn`

,`Fs`

,`channelWeights`

)`channelWeights`

must
be a row vector with the same number of elements as the number of
channels in `audioIn`

.

`[`

returns the loudness
range of the audio signal using either of the previous syntaxes. The
EBU R 128 Tech 3342 standard defines the loudness range computation.`loudness`

,`loudnessRange`

]
= integratedLoudness(___)

## Examples

### Determine Integrated Loudness

Determine the integrated loudness of an audio signal.

Create a two-second sine wave with a 0 dB amplitude, a 1 kHz frequency, and a 48 kHz sample rate.

sampleRate = 48e3; increment = sampleRate*2; amplitude = 10^(0/20); frequency = 1e3; sineGenerator = audioOscillator( ... 'SampleRate',sampleRate, ... 'SamplesPerFrame',increment, ... 'Amplitude',amplitude, ... 'Frequency',frequency); signal = sineGenerator();

Calculate the integrated loudness of the audio signal at the specified sample rate.

loudness = integratedLoudness(signal,sampleRate)

loudness = -3.0036

### Specify Nondefault Channel Weights

Read in a four-channel audio signal. Specify a nondefault weighting vector with four elements.

```
[signal,fs] = audioread('AudioArray-16-16-4channels-20secs.wav');
weightingVector = [1,0.8,0.8,1.2];
```

Calculate the integrated loudness with the default channel weighting and the nondefault channel weighting vector.

standardLoudness = integratedLoudness(signal,fs,weightingVector)

standardLoudness = -11.6825

nonStandardLoudness = integratedLoudness(signal,fs)

nonStandardLoudness = -11.0121

### Determine Loudness Range

Read in an audio signal. Clip 3 five-second intervals out of the signal.

```
[x,fs] = audioread('FunkyDrums-44p1-stereo-25secs.mp3');
x1 = x(1:fs*5,:);
x2 = x(5e5:5e5+5*fs,:);
x3 = x(end-5*fs:end,:);
```

Calculate the loudness and loudness range of the total signal and of each interval.

[L,LRA] = integratedLoudness(x,fs); [L1,LRA1] = integratedLoudness(x1,fs); [L2,LRA2] = integratedLoudness(x2,fs); [L3,LRA3] = integratedLoudness(x3,fs); fprintf(['Loudness: %0.2f\n', ... 'Loudness range: %0.2f\n\n', ... 'Beginning loudness: %0.2f\n', ... 'Beginning loudness range: %0.2f\n\n', ... 'Middle loudness: %0.2f\n', ... 'Middle loudness range: %0.2f\n\n', ... 'End loudness: %0.2f\n', ... 'End loudness range: %0.2f\n'], ... L,LRA,L1,LRA1,L2,LRA2,L3,LRA3);

Loudness: -22.93 Loudness range: 1.50 Beginning loudness: -23.29 Beginning loudness range: 1.17 Middle loudness: -22.99 Middle loudness range: 1.12 End loudness: -22.09 End loudness range: 1.82

## Input Arguments

`audioIn`

— Input signal

matrix

Input signal, specified as a matrix. The columns of the matrix are treated as audio channels.

The maximum number of columns of the input signal depends on
your `channelWeights`

specification:

If you use the default

`channelWeights`

, the input signal has a maximum of five channels. Specify the channels in this order: [Left, Right, Center, Left surround, Right surround].If you specify nondefault

`channelWeights`

, the input signal must have the same number of columns as the number of elements in the`channelWeights`

vector.

**Data Types: **`single`

| `double`

`Fs`

— Sample rate (Hz)

positive scalar

Sample rate of the input signal in Hz, specified as a positive scalar.

**Data Types: **`single`

| `double`

`channelWeights`

— Linear weighting applied to each input channel

`[1.0, 1,0, 1.0, 1.41, 1.41]`

(default) | nonnegative row vector

Linear weighting applied to each input channel, specified as a row vector of nonnegative values. The number of elements in the row vector must be equal to or greater than the number of input channels. Excess values in the vector are ignored.

The default channel weights follow the ITU-R BS.1170-4 standard.
To use the default channel weights, specify the channels of the `audioIn`

matrix
in this order: [Left, Right, Center, Left surround, Right surround].

It is a best practice to specify the `channelWeights`

vector
in order: [Left, Right, Center, Left surround, Right surround].

**Data Types: **`single`

| `double`

## Output Arguments

`loudness`

— Integrated loudness (LUFS)

scalar

Integrated loudness in loudness units relative to full scale (LUFS), returned as a scalar.

The ITU-R BS.1770-4 and EBU R 128 standards define the integrated
loudness. The algorithm computes the loudness by breaking down the
audio signal into 0.4-second segments with 75% overlap. If the input
signal is less than 0.4 seconds, `loudness`

is
returned empty.

**Data Types: **`single`

| `double`

`loudnessRange`

— Loudness range (LU)

scalar

Loudness range in loudness units (LU), returned as a scalar.

The EBU R 128 Tech 3342 standard defines the loudness range.
The algorithm computes the loudness range by breaking down the audio
into 3-second segments with 2.9-second overlap. If the input signal
is less than three seconds, `loudnessRange`

is
returned empty.

**Data Types: **`single`

| `double`

## Algorithms

The `integratedLoudness`

function returns
the integrated loudness and loudness range (LRA) of an audio signal.
You can specify any number of channels and nondefault channel weights
used for loudness measurements. The `integratedLoudness`

algorithm
is described for the general case of *n* channels.

### Integrated Loudness and Loudness Range

The input channels, *x*, pass through a K-weighted `weightingFilter`

.
The K-weighted filter shapes the frequency spectrum to reflect perceived
loudness.

**Integrated Loudness**

The K-weighted channels,

*y*, are divided into 0.4-second segments with 0.3-second overlap. The power (mean square) of each segment of the K-weighted channels is calculated:$$m{P}_{i}=\frac{1}{w}{\displaystyle \sum _{k=1}^{w}{y}_{i}^{2}[k]}$$

*mP*is the momentary power of the_{i}*i*th segment of a channel.*w*is the segment length in samples.

The momentary loudness,

*mL*, is computed for each segment:$$m{L}_{i}=-0.691+10\text{\hspace{0.17em}}{\mathrm{log}}_{10}\left({\displaystyle \sum _{c=1}^{n}{G}_{c}\times m{P}_{\left(i,c\right)}}\right)\text{\hspace{1em}}LUFS$$

*G*is the weighting for channel_{c}*c*.

The momentary power is gated using the momentary loudness calculation:

$$m{P}_{i}\to m{P}_{j}$$

$$j=\left\{\text{\hspace{0.17em}}i\text{\hspace{0.17em}}|\text{\hspace{0.17em}}\text{\hspace{0.17em}}m{L}_{i}\ge -70\text{\hspace{0.17em}}\right\}\text{\hspace{0.17em}}$$

The relative threshold,

*Γ*, is computed:$$\Gamma =-0.691+10{\mathrm{log}}_{10}\left({\displaystyle \sum _{c=1}^{n}{G}_{c}\times {l}_{c}}\right)-10$$

*l*is the mean momentary power of channel_{c}*c*:$${l}_{c}=\frac{1}{\left|j\right|}{\displaystyle \sum _{j}^{}m{P}_{\left(j,c\right)}}$$

The momentary power subset,

*mP*, is gated using the relative threshold:_{j}$$m{P}_{j}\to m{P}_{k}$$

$$k=\left\{\text{\hspace{0.17em}}j\text{\hspace{0.17em}}|\text{\hspace{0.17em}}\text{\hspace{0.17em}}m{P}_{j}\ge \Gamma \text{\hspace{0.17em}}\right\}\text{\hspace{0.17em}}$$

The momentary power segments are averaged:

$$P=\frac{1}{\left|k\right|}{\displaystyle \sum _{k}m{P}_{k}}$$

The integrated loudness is computed by passing the mean momentary power subset,

*P*, through the Compute Loudness system:$$\text{Integrated}\text{\hspace{0.17em}}\text{\hspace{0.17em}}\text{Loudness}\text{\hspace{0.17em}}\text{\hspace{0.17em}}=\text{\hspace{0.17em}}-0.691+10{\mathrm{log}}_{10}\left({\displaystyle \sum _{c=1}^{n}{G}_{c}\times {P}_{c}}\right)\text{\hspace{1em}}LUFS$$

**Loudness Range**

The K-weighted channels,

*y*, are divided into 3-second segments with 2.9-second overlap. The power (mean square) of each segment of the K-weighted channels is calculated:$$s{P}_{i}=\frac{1}{w}{\displaystyle \sum _{k=1}^{w}{y}_{i}^{2}[k]}$$

*sP*is the short-term power of the_{i}*i*th segment of a channel.*w*is the segment length in samples.

The short-term loudness,

*sL*, is computed for each segment:$$s{L}_{i}=-0.691+10\text{\hspace{0.17em}}{\mathrm{log}}_{10}\left({\displaystyle \sum _{c=1}^{n}{G}_{c}\times s{P}_{\left(i,c\right)}}\right)$$

*G*is the weighting for channel_{c}*c*.

The short-term loudness is gated using an absolute threshold:

$$s{L}_{i}\to s{L}_{j}$$

$$j=\left\{\text{\hspace{0.17em}}i\text{\hspace{0.17em}}|\text{\hspace{0.17em}}\text{\hspace{0.17em}}s{L}_{i}\ge -70\text{\hspace{0.17em}}\right\}\text{\hspace{0.17em}}$$

The gated short-term loudness is converted back to linear, and then the mean is taken:

$$s{P}_{j}=\frac{1}{\left|j\right|}{\displaystyle \sum _{j}{10}^{\left(\raisebox{1ex}{$s{L}_{j}$}\!\left/ \!\raisebox{-1ex}{$10$}\right.\right)}}$$

The relative threshold,

*K*, is computed:$$K=-20+10{\mathrm{log}}_{10}\left(s{P}_{j}\right)$$

The short-term loudness subset,

*sL*, is gated using the relative threshold:_{j}$$s{L}_{j}\to s{L}_{k}$$

$$k=\left\{\text{\hspace{0.17em}}j\text{\hspace{0.17em}}|\text{\hspace{0.17em}}s{L}_{j}\ge K\text{\hspace{0.17em}}\right\}\text{\hspace{0.17em}}$$

The short-term loudness subset,

*sL*, is sorted. The loudness range is calculated as between the 10th and 95th percentiles of the distribution, and is returned in loudness units (LU)._{k}

## References

[1] International Telecommunication Union;
Radiocommunication Sector. *Algorithms to Measure Audio
Programme Loudness and True-Peak Audio Level.* ITU-R BS.1770-4.
2015.

[2] European Broadcasting Union. *Loudness
Normalisation and Permitted Maximum Level of Audio Signals.* EBU
R 128. 2014.

[3] European Broadcasting Union. *Loudness
Metering: 'EBU Mode' Metering to Supplement EBU R 128 Loudness Normalization.* EBU
R 128 Tech 3341. 2014.

[4] European Broadcasting Union. *Loudness
Range: A Measure to Supplement EBU R 128 Loudness Normalization.* EBU
R 128 Tech 3342. 2016.

## Extended Capabilities

### C/C++ Code Generation

Generate C and C++ code using MATLAB® Coder™.

## Version History

**Introduced in R2016b**

## See Also

## Open Example

You have a modified version of this example. Do you want to open this example with your edits?

## MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)