# integratedLoudness

Measure integrated loudness and loudness range

## Syntax

``loudness = integratedLoudness(audioIn,Fs)``
``loudness = integratedLoudness(audioIn,Fs,channelWeights)``
``````[loudness,loudnessRange] = integratedLoudness(___)``````

## Description

example

````loudness = integratedLoudness(audioIn,Fs)` returns the integrated loudness of an audio signal, `audioIn`, with sample rate `Fs`. The ITU-R BS.1770-4 and EBU R 128 standards define the algorithms to calculate integrated loudness.```

example

````loudness = integratedLoudness(audioIn,Fs,channelWeights)` specifies the channel weights used to compute the integrated loudness. `channelWeights` must be a row vector with the same number of elements as the number of channels in `audioIn`.```

example

``````[loudness,loudnessRange] = integratedLoudness(___)``` 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.```

## Examples

collapse all

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 ```

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 ```

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

collapse all

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`

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

Data Types: `single` | `double`

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

collapse all

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`

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

collapse all

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
1. 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}\sum _{k=1}^{w}{y}_{i}^{2}\left[k\right]$`

• mPi is the momentary power of the ith segment of a channel.

• w is the segment length in samples.

2. The momentary loudness, mL, is computed for each segment:

`$m{L}_{i}=-0.691+10\text{\hspace{0.17em}}{\mathrm{log}}_{10}\left(\sum _{c=1}^{n}{G}_{c}×m{P}_{\left(i,c\right)}\right)\text{ }LUFS$`

• Gc is the weighting for channel c.

3. 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}}$`

4. The relative threshold, Γ, is computed:

`$\Gamma =-0.691+10{\mathrm{log}}_{10}\left(\sum _{c=1}^{n}{G}_{c}×{l}_{c}\right)-10$`

lc is the mean momentary power of channel c:

`${l}_{c}=\frac{1}{|j|}\sum _{j}^{}m{P}_{\left(j,c\right)}$`

5. The momentary power subset, mPj, is gated using the relative threshold:

`$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}}$`

6. The momentary power segments are averaged:

`$P=\frac{1}{|k|}\sum _{k}m{P}_{k}$`

7. 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(\sum _{c=1}^{n}{G}_{c}×{P}_{c}\right)\text{ }LUFS$`

Loudness Range
1. 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}\sum _{k=1}^{w}{y}_{i}^{2}\left[k\right]$`

• sPi is the short-term power of the ith segment of a channel.

• w is the segment length in samples.

2. The short-term loudness, sL, is computed for each segment:

`$s{L}_{i}=-0.691+10\text{\hspace{0.17em}}{\mathrm{log}}_{10}\left(\sum _{c=1}^{n}{G}_{c}×s{P}_{\left(i,c\right)}\right)$`

• Gc is the weighting for channel c.

3. 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}}$`

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

`$s{P}_{j}=\frac{1}{|j|}\sum _{j}{10}^{\left(s{L}_{j}}{10}\right)}$`

The relative threshold, K, is computed:

`$K=-20+10{\mathrm{log}}_{10}\left(s{P}_{j}\right)$`

5. The short-term loudness subset, sLj, is gated using the relative threshold:

`$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}}$`

6. The short-term loudness subset, sLk, is sorted. The loudness range is calculated as between the 10th and 95th percentiles of the distribution, and is returned in loudness units (LU).

## 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.