AI Logic

Audio Features and Front-ends

Per-Channel Energy Normalization (PCEN)

Updated:

Diagram of PCEN. The left side shows the overall pipeline: an audio waveform goes through framing and windowing, FFT, a mel filterbank, PCEN, and an acoustic model to detect a keyword. The right side shows the inside of PCEN: the filterbank energy E is divided by the smoothed recent magnitude M raised to the power α (automatic gain control), then root compression is applied to produce the PCEN output

Background and Overview

PCEN (Per-Channel Energy Normalization) is a process that divides mel filterbank outputs by the recent magnitude of each channel and then applies root compression. It replaces the log compression used in log mel spectrograms. Wang et al. at Google proposed it in 2017 for keyword spotting, the mechanism that listens for keywords such as "OK Google" on smartphones and other devices.

In deep-learning speech recognition, the standard input is a log mel spectrogram, obtained by applying a log to mel filterbank energies. However, the original paper points out three problems with log compression.

  • It diverges at 0: the logarithm of 0 is undefined, so a small value must be added or the input clipped at a floor, and there is no principled way to choose that value.
  • It spends much of its range on quiet parts: it greatly magnifies differences among small, nearly uninformative values such as silence.
  • Its values change with loudness: even for the same words, a speaker far from the microphone is recorded more quietly, and the entire log output shifts downward.

PCEN cancels loudness changes by dividing by the recent magnitude (automatic gain control), then narrows the value range with root compression. Its main benefit is that it becomes robust to speech spoken from far away and speech in noisy places. In addition, every computation is differentiable, so its parameters can be learned together with the acoustic model.

Computation Steps

Let E(t,f)E(t, f) be the filterbank energy at time tt and channel (frequency) ff. PCEN is computed per channel in the following steps (right side of the diagram at the top of the article).

  1. Compute the recent magnitude: smooth EE over time with a first-order IIR filter to get M(t,f)M(t, f) (Eq. 2). ss is the smoothing coefficient; the smaller it is, the more slowly it changes.
  2. Divide by the recent magnitude (automatic gain control): divide E(t,f)E(t, f) by (ϵ+M(t,f))α(\epsilon + M(t, f))^{\alpha}. α∈[0,1]\alpha \in [0, 1] is the normalization strength; the closer it is to 1, the more strongly loudness differences are canceled. ϵ\epsilon is a small value that prevents division by 0.
  3. Apply root compression: add δ\delta, raise to the power rr, and finally subtract δr\delta^r so that the output is 0 when the input is 0.
M(t,f)=(1−s) M(t−1,f)+s E(t,f)M(t, f) = (1 - s)\, M(t-1, f) + s\, E(t, f) PCEN(t,f)=(E(t,f)(ϵ+M(t,f))α+δ)r−δr\mathrm{PCEN}(t, f) = \left( \frac{E(t, f)}{(\epsilon + M(t, f))^{\alpha}} + \delta \right)^{r} - \delta^{r}

The fixed PCEN in the original paper uses s=0.025s = 0.025, α=0.98\alpha = 0.98, δ=2\delta = 2, r=0.5r = 0.5, and ϵ=10−6\epsilon = 10^{-6}. With frames every 10 ms, s=0.025s = 0.025 corresponds to a time constant of about 40 frames (0.4 seconds). The smoothing uses only past frames and is independent per channel, so it can be computed on the fly while listening.

Automatic gain control is like a microphone knob that turns itself to match the speaker's loudness. If a quiet voice continues, it raises the sensitivity; if a loud voice continues, it lowers it. How fast the knob turns is ss, and how completely it compensates is α\alpha.

Trainable PCEN

With fixed PCEN, the parameters must be tuned by hand, and with many combinations they cannot all be tuned. The original paper also proposed writing PCEN as a neural network layer and learning it by backpropagation together with the acoustic model.

  1. Make α, δ, and r per-channel parameters: values that were shared across all channels are learned as α(f)\alpha(f), δ(f)\delta(f), and r(f)r(f) for each channel ff. To keep them positive, their logarithms are updated by gradient descent and mapped back with an exponential.
  2. Learn the smoothing coefficient as a weighted combination of several smoothers: the MkM_k smoothed with KK predetermined coefficients are mixed with per-channel weights wk(f)w_k(f) (positive and summing to 1 via softmax).
M(f)=∑k=1Kwk(f) Mk(f),wk(f)=exp⁡(zk(f))∑jexp⁡(zj(f))M(f) = \sum_{k=1}^{K} w_k(f)\, M_k(f), \qquad w_k(f) = \frac{\exp(z_k(f))}{\sum_{j} \exp(z_j(f))}

The learned parameters are input-independent constants, so after training their values can be frozen and baked in. The inference cost is the same as fixed PCEN.

In the original paper, when four coefficients (0.015, 0.02, 0.04, 0.08) were tried, the weights concentrated almost entirely on the slowest (0.015) and the fastest (0.08). Moreover, an alternating pattern emerged: even-numbered channels chose the slow one and odd-numbered channels the fast one. Training with a single smoother that simply alternates the two coefficients across channels then gave almost the same accuracy.

The later LEAF uses a form that learns the smoothing coefficient ss directly per channel as well (sPCEN).

Results in the Original Paper

The original paper compared log mel spectrograms and PCEN with a small CNN model that detects "OK Google." Both inputs are 40-channel mel filterbanks (25 ms window, 10 ms hop). The log mel baseline is already strong, with an optimized spectral subtraction step added.

The evaluation uses curves of miss rate versus false alarms per hour (the number of times the model wrongly fires).

ComparisonEvaluation dataResult
Fixed PCEN vs. log mel (trained with loudness variation)Far-field speech re-recorded in a moving carAt 0.1 false alarms per hour, PCEN lowered the miss rate by about 14 points
Fixed PCEN vs. log mel (trained without loudness variation)Same as aboveLog mel was the worst; PCEN trained without loudness variation was still better than log mel trained with it
Trainable PCEN vs. fixed PCENNoisy speech re-recorded at 0.8 m and 5 mTrainable PCEN was consistently better at both distances
Fixed and trainable PCEN vs. log melClean near-field speechBoth PCENs were better than log mel, with no degradation on near-field speech

The original paper also compared against RASTA filtering, a standard channel normalization method, and reports that it performed worse than PCEN (no numbers are given).

The original paper offers two views on why it works.

  • It flattens quiet parts: small differences in silent regions, which the log greatly magnified, become inconspicuous with PCEN.
  • It emphasizes onsets: rewriting E/(ϵ+M)α=exp⁡(log⁡E−αlog⁡(ϵ+M))E / (\epsilon + M)^{\alpha} = \exp\left(\log E - \alpha \log(\epsilon + M)\right) shows that it applies a highpass filter in the log domain that "subtracts the recent average from the current value." Slow changes (room reverberation and loudness) disappear, while sudden changes (the start of speech) remain.

Practical Considerations

Suitable parameter values depend on the scale of the input magnitude. According to the librosa pcen documentation, the original paper's values (δ=2\delta = 2 and so on) are tuned for filterbanks computed from waveforms in the 32-bit integer range (−231-2^{31} to 2312^{31}). Applying them as-is to waveforms in the commonly used −1-1 to 11 range makes PCEN behave differently than intended. If the waveform scale changes, retune the parameters or learn them.

Keep the following points in mind as well.

  • Train on data with varied loudness: the original paper reports that training data with varied loudness (rescaled to −45-45 to −15-15 dBFS) was important for training PCEN successfully. Without loudness variation in the data, the model cannot learn the importance of normalization.
  • The input is filterbank energy (before the log): PCEN replaces the log, so it must not be applied to a log mel spectrogram.
  • Start-up of the smoothing: since MM is computed recursively from past values, the first few dozen frames of the audio are affected by the initial value of the smoother.
  • Match the temporal smoothing to the data: ss and α\alpha are the main parameters, and suitable values depend on the loudness distribution of the data.

Comparison with Other Compression and Normalization Methods

Methods for conditioning the range of filterbank outputs compare as follows.

MethodWhat it doesRobustness to loudness changesStrengthsWeaknesses
Log compression (log mel)Takes the log of each valueWeak (the whole output shifts when loudness changes)Simple and available in every libraryDiverges at 0. Spends much of its range on silence
Log + mean and variance normalization (e.g., cepstral mean normalization)Subtracts the mean over the utterance and divides by the varianceRobust to constant per-utterance differencesLong used together with MFCCsStruggles with loudness changes within an utterance. Must wait until the end of the utterance
PCENDivides by the recent magnitude and applies root compressionStrong (also tracks loudness that changes over time)Can be computed on the fly. Parameters can be learnedParameters depend on the input scale
Learnable frontend (LEAF)Learns filters, pooling, and PCEN (sPCEN) togetherStrongOptimizes the entire preprocessing for the taskRequires training data and compute

Rough guidelines for choosing:

  • Always-on keyword spotting, far-field speech, or environments with changing loudness: use PCEN.
  • Detecting sounds with loud background noise, such as animal calls: PCEN is worth trying. It suppresses constant background sound and makes salient sounds stand out. Benefits of PCEN have also been reported in animal bioacoustics research.
  • Large-scale speech recognition: log mel spectrograms are the standard, but benefits of PCEN have been reported for large-scale speech recognition as well.

PyTorch example

Show code
python
import math
import torch
import torch.nn as nn
import torchaudio

'''
Implement PCEN as a trainable layer (Eqs. (1)(2) of the original paper).
α, δ, and r are per-channel parameters, stored as logarithms to keep them positive. s is fixed.
(If it is not trained, librosa.pcen can also compute it.)
'''

class PCEN(nn.Module):
  def __init__(self, n_channels, s=0.025, alpha=0.98, delta=2.0, r=0.5, eps=1e-6, trainable=True):
    super().__init__()
    self.s, self.eps = s, eps
    init = lambda v: torch.full((n_channels,), math.log(v))
    self.log_alpha = nn.Parameter(init(alpha), requires_grad=trainable)
    self.log_delta = nn.Parameter(init(delta), requires_grad=trainable)
    self.log_r = nn.Parameter(init(r), requires_grad=trainable)

  def forward(self, energy):
    # energy: [batch, channels, frames]  filterbank energy before the log
    # 1. Smooth with a first-order IIR filter: M(t) = (1 - s) M(t-1) + s E(t). This implementation initializes M with the first frame
    m = energy[..., 0]
    smoothed = []
    for t in range(energy.shape[-1]):
      m = (1 - self.s) * m + self.s * energy[..., t]
      smoothed.append(m)
    m = torch.stack(smoothed, dim=-1)

    alpha = self.log_alpha.exp()[:, None]  # [channels, 1]
    delta = self.log_delta.exp()[:, None]
    r = self.log_r.exp()[:, None]
    # 2. Divide by the recent magnitude (automatic gain control)
    agc = energy / (self.eps + m) ** alpha
    # 3. Root compression (output is 0 when input is 0)
    return (agc + delta) ** r - delta ** r


sample_rate = 16000
mel = torchaudio.transforms.MelSpectrogram(
  sample_rate=sample_rate, n_fft=400, hop_length=160, n_mels=40,  # 25 ms window, 10 ms hop, 40 channels
)
waveform = torch.randn(1, sample_rate)  # example: 1 second of audio. In practice, load it with torchaudio.load
waveform = waveform * 2 ** 31           # to use the original paper's values, scale the waveform to a large integer range
energy = mel(waveform)                  # [1, 40, 101]

pcen = PCEN(n_channels=40)
features = pcen(energy)                 # input to the acoustic model; can be trained together with it
print(features.shape)                   # torch.Size([1, 40, 101])

FAQ

Q. Should I use PCEN or a log mel spectrogram?
A.

PCEN suits environments where the speaker's distance or loudness changes, or where there is a lot of noise. In the original paper, PCEN outperformed log mel even on clean near-field speech. On the other hand, many pretrained models assume log mel, so match the model when using an existing one.

Q. What happens if α is set to 1?
A.

With α=1\alpha = 1, the input is divided directly by its recent magnitude, so the value stays almost the same no matter how much the volume is scaled (for sufficiently loud sounds). The original paper's α=0.98\alpha = 0.98 is a strong normalization close to that, and it was confirmed to be robust to loudness changes even when trained without loudness variation. Making α\alpha smaller weakens the normalization and keeps loudness information.

Q. Can PCEN be computed in real time?
A.

Yes. The smoothing is a first-order IIR filter that uses only past frames and is computed independently per channel, so an output can be produced on the fly for each frame. Unlike mean and variance normalization, which needs the mean over the whole utterance, it does not have to wait for the end of the utterance.

References

  1. Wang, Y., Getreuer, P., Hughes, T., Lyon, R. F., & Saurous, R. A. (2017). Trainable frontend for robust and far-field keyword spotting. 2017 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP), 5670–5674.
  2. Zeghidour, N., Teboul, O., de Chaumont Quitry, F., & Tagliasacchi, M. (2021). LEAF: A learnable frontend for audio classification. ICLR 2021. (Restates the PCEN formula and introduces sPCEN, which also learns the smoothing coefficient)
  3. librosa.pcen (librosa 0.11.0 documentation; default values and notes on input scale).