AI Logic

Audio Features and Front-ends

SincNet

Updated:

Diagram of SincNet. The left side shows the overall pipeline: an audio waveform goes through the SincNet layer (80 sinc bandpass filters), pooling, Layer Norm, Leaky ReLU, Dropout, CNN and fully connected layers, and Softmax to classify the speaker. The right side shows the inside of one filter: on top, a frequency response that passes only f1 to f2; below, the time-domain filter, a difference of sincs multiplied by a Hamming window

Background and Overview

SincNet is a CNN that takes raw audio waveforms as input and restricts the filters of its first convolutional layer to the shape of a bandpass filter, learning only the low and high cutoff frequencies f1f_1 and f2f_2. Ravanelli and Bengio proposed it in 2018 for speaker recognition (the task of identifying who is speaking from their voice).

Speaker recognition has long relied on hand-designed features such as MFCCs and mel filterbanks. However, these are built on human hearing and are not necessarily optimal for every task. Because they smooth the spectrum, they may also erase narrow-band cues that distinguish speakers, such as voice pitch and formants.

Learning directly from the waveform has therefore been explored, but the original paper points out that the first convolutional layer is the hardest part. The input is high-dimensional and gradients struggle to reach it in deep networks, so the filters learned by an ordinary CNN tend to look noisy or span multiple bands. This tendency is especially strong when training data is scarce.

SincNet fixes the filter shape to a "rectangular bandpass filter" and leaves only two frequencies as free parameters. Its defining feature is that it learns interpretable filters, adapted to the data, with few parameters.

Computing the SincNet Layer

The first layer of an ordinary CNN is the convolution y[n]=x[n]∗h[n]y[n] = x[n] * h[n] of a waveform x[n]x[n] with a filter h[n]h[n] of length LL, and all LL values of hh are learned. Instead of hh, SincNet uses a function g[n,θ]g[n, \theta] determined by a small set of parameters θ\theta.

  1. Consider a rectangular bandpass filter in the frequency domain: a bandpass filter can be written as the difference of two (rectangular) lowpass filters (Eq. 3).
  2. Go back to the time domain: the inverse Fourier transform of a rectangle is a sinc function, so the filter becomes the difference of two sinc functions (Eq. 4).
  3. Keep the cutoff frequencies ordered: to ensure f1≥0f_1 \ge 0 and f2≥f1f_2 \ge f_1, the values actually used are taken through absolute values (Eqs. 5 and 6).
  4. Apply a window: an ideal bandpass filter is infinitely long, so truncating it to length LL causes ripples in the passband and insufficient attenuation in the stopband. A Hamming window is applied to smooth the truncation (Eqs. 7 and 8).
  5. Train together with the other layers: every computation is differentiable, so f1f_1 and f2f_2 are learned together with the weights of the later layers using stochastic gradient descent or a similar method.
G[f,f1,f2]=rect ⁣(f2f2)−rect ⁣(f2f1)G[f, f_1, f_2] = \mathrm{rect}\!\left(\frac{f}{2 f_2}\right) - \mathrm{rect}\!\left(\frac{f}{2 f_1}\right) g[n,f1,f2]=2f2 sinc(2πf2n)−2f1 sinc(2πf1n),sinc(x)=sin⁡xxg[n, f_1, f_2] = 2 f_2\, \mathrm{sinc}(2\pi f_2 n) - 2 f_1\, \mathrm{sinc}(2\pi f_1 n), \qquad \mathrm{sinc}(x) = \frac{\sin x}{x} f1abs=∣f1∣,f2abs=f1+∣f2−f1∣f_1^{\mathrm{abs}} = |f_1|, \qquad f_2^{\mathrm{abs}} = f_1 + |f_2 - f_1| gw[n,f1,f2]=g[n,f1,f2]⋅w[n],w[n]=0.54−0.46cos⁡ ⁣(2πnL)g_w[n, f_1, f_2] = g[n, f_1, f_2] \cdot w[n], \qquad w[n] = 0.54 - 0.46 \cos\!\left(\frac{2\pi n}{L}\right)

The magnitude (gain) of each filter is not learned here and is left to the later layers. The cutoff frequencies are either set randomly in the range 00 to fs/2f_s/2 (fsf_s is the sampling rate) or initialized with the cutoff frequencies of a mel-scale filterbank. Mel-scale initialization places many filters from the start at low frequencies, where speaker cues are abundant.

If an ordinary CNN filter is "an equalizer with 251 knobs," a SincNet filter has "only two knobs: the lower and upper limits of the passband." Fewer knobs mean less freedom, but the filter reaches a meaningful setting without wandering.

Why It Works

The original paper lists three advantages of SincNet.

  • Faster convergence: it builds in knowledge about the filter shape (that it is a bandpass filter) from the start and learns only the parameters that matter most for performance, so it reaches a good solution quickly.
  • Fewer parameters: with FF filters of length LL, an ordinary CNN has F⋅LF \cdot L parameters and SincNet has 2F2F. For F=80F = 80 and L=100L = 100, that is 160 versus 8,000. Doubling LL does not increase SincNet's parameters, so long filters with sharp band edges can be used without adding parameters.
  • Interpretability: each filter has a physical meaning, "which frequencies from what Hz to what Hz it passes," so it is possible to read off what the network attends to.

The filters are also symmetric, which brings computational advantages: they introduce no phase distortion, and computing one half determines the other.

Looking at the cumulative frequency response of all learned filters, SincNet showed three distinct peaks.

Peak locationCorresponds to
Lowest peakVoice pitch (average 133 Hz for men, 234 Hz for women)
About 500 HzFirst formant (the average for English vowels is about 500 Hz)
900 to 1400 HzPart of the second formant (the average for the vowel /a/ is about 1100 Hz)

The ordinary CNN's filters also concentrated at low frequencies, but no such distinct peaks appeared. This shows that SincNet tuned its filters to bands useful for distinguishing speakers.

Experimental Results

The original paper evaluated under a demanding low-data condition: 12 to 15 seconds of training data per speaker and test sentences of 2 to 6 seconds. The datasets are TIMIT (462 speakers) and LibriSpeech (2,484 speakers).

The SincNet configuration is as follows.

  • Input: the waveform split into 200 ms chunks (with 10 ms overlap)
  • SincNet layer: 80 filters of length L=251L = 251. Cutoff frequencies initialized on the mel scale
  • Subsequent layers: two convolutional layers with 60 filters (length 5) and three fully connected layers with 2,048 units. Layer Normalization for the convolutions, Batch Normalization for the fully connected layers, and Leaky ReLU activations
  • Training: RMSprop (learning rate 0.001), minibatch size 128

Sentence-level error rates (%, lower is better) for speaker identification (determining who is speaking) are as follows.

Input and modelTIMITLibriSpeech
MFCC + fully connected network0.992.02
Mel filterbank + CNN0.861.55
Waveform + ordinary CNN1.651.00
Waveform + SincNet0.850.96

Equal error rates (%, LibriSpeech, lower is better) for speaker verification (deciding whether the speaker is who they claim to be) are as follows.

Input and modeld-vectorUsing the speaker classifier's output
MFCC + fully connected network0.880.72
Mel filterbank + CNN0.600.37
Waveform + ordinary CNN0.580.36
Waveform + SincNet0.510.32

The main takeaways are as follows.

  • The less data, the larger the gap over an ordinary CNN: on TIMIT, the error rate dropped from 1.65% to 0.85%. On LibriSpeech, it also achieved a relative improvement of about 4% with fewer epochs (1,200 vs. 1,800).
  • With more data, it beats the mel filterbank: on TIMIT it was about the same as the mel filterbank, but on LibriSpeech it was clearly better. Presumably, with enough data it can learn a filterbank tailored to the task.
  • Faster training: the frame-level error rate on TIMIT was 33.0% for SincNet versus 37.7% for the ordinary CNN, and it also decreased faster.

Under the same conditions, the conventional i-vector approach had an equal error rate of 1.1%, worse than the neural network approaches.

Practical Considerations

SincNet constrains only the first layer. Its filters can only take the shape of a rectangular bandpass filter, so they cannot represent filters spanning multiple bands or with asymmetric peaks. Also, it learns only the filter bands; subsequent compression (such as a log) and temporal downsampling are left to ordinary CNN layers. To learn the entire preprocessing, consider LEAF, which also learns compression and pooling.

Keep the following points in mind as well.

  • Watch the units of the cutoff frequencies: f1f_1 and f2f_2 in the formulas are values normalized by the sampling rate (0 to 0.5). Some implementations store them in Hz and others as normalized values, so check the units when borrowing initial values or learning rates from another implementation.
  • Exceeding the Nyquist frequency is rarely a concern: the original paper reports that f2f_2 naturally stayed below the Nyquist frequency during training without any explicit constraint.
  • Filter length and compute: even though the parameter count does not grow, a longer LL increases the cost of the convolution. At 16 kHz, L=251L = 251 corresponds to about 16 ms.
  • The window type matters little: the original paper reports no significant difference in performance when using Hann, Blackman, or Kaiser windows instead of the Hamming window.

Comparison with Other Frontends

Frontends that extract features from audio waveforms compare as follows.

FrontendFilter shapeWhat is learnedFirst-layer parameters (80 filters)StrengthsWeaknesses
MFCC / mel filterbankMel-scale trianglesNothing (fixed)0Cheap to compute and stable even with little dataCannot adapt to the task
Ordinary CNN (waveform input)UnconstrainedEvery value80×L80 \times LThe most expressiveHard to train; filters become noisy with little data
SincNetRectangular bandpassCutoff frequencies f1f_1 and f2f_2160Trains quickly with few parameters and is interpretableFixed shape. Does not learn compression or pooling
LEAFGabor filters (Gaussian-shaped)Center frequency and bandwidth, pooling, compression (PCEN)160 (filter part)Learns the entire preprocessingSomewhat more complex

Rough guidelines for choosing:

  • Tasks where fine-grained voice bands matter, such as speaker recognition: SincNet is a good fit. In the comparison in the LEAF paper as well, SincNet reached 43.5% accuracy on speaker identification (VoxCeleb), beating the mel filterbank (31.9%) and LEAF (33.1%).
  • Little data, and a stable baseline is needed first: start with a mel filterbank or MFCCs.
  • General audio classification, with the whole preprocessing learned: consider LEAF.

PyTorch example

Show code
python
import math
import torch
import torch.nn as nn
import torch.nn.functional as F

'''
The first layer of SincNet (Eqs. (4) to (8) of the original paper).
Only the low and high cutoff frequencies f1 and f2 of each filter are learned (stored as values normalized by the sampling rate).
'''

def hz_to_mel(f):
  return 2595.0 * math.log10(1.0 + f / 700.0)

def mel_to_hz(m):
  return 700.0 * (10.0 ** (m / 2595.0) - 1.0)

class SincConv(nn.Module):
  def __init__(self, n_filters=80, kernel_size=251, sample_rate=16000):
    super().__init__()
    assert kernel_size % 2 == 1, 'use an odd length so the filter is symmetric'
    self.kernel_size = kernel_size
    # Initialize the cutoff frequencies at equal intervals on the mel scale (one example)
    edges = [mel_to_hz(m) for m in torch.linspace(hz_to_mel(30.0), hz_to_mel(sample_rate / 2 - 100), n_filters + 1).tolist()]
    self.f1 = nn.Parameter(torch.tensor(edges[:-1]) / sample_rate)  # low cutoff frequency
    self.f2 = nn.Parameter(torch.tensor(edges[1:]) / sample_rate)   # high cutoff frequency
    n = torch.arange(kernel_size, dtype=torch.float32)
    self.register_buffer('t', n - (kernel_size - 1) / 2)          # positions centered at 0
    self.register_buffer('window', 0.54 - 0.46 * torch.cos(2 * math.pi * n / kernel_size))  # Eq. (8)

  @staticmethod
  def lowpass(fc, t):
    # 2 fc sinc(2π fc t). Equals 2 fc at t = 0
    x = 2 * math.pi * fc[:, None] * t[None, :]
    safe = torch.where(t == 0, torch.ones_like(x), x)
    return 2 * fc[:, None] * torch.where(t == 0, torch.ones_like(x), torch.sin(safe) / safe)

  def forward(self, x):
    # x: [batch, 1, samples]
    f1 = self.f1.abs()                      # Eq. (5)
    f2 = f1 + (self.f2 - self.f1).abs()     # Eq. (6)
    g = self.lowpass(f2, self.t) - self.lowpass(f1, self.t)  # Eq. (4): difference of two lowpass filters
    g = g * self.window                     # Eq. (7): apply the window
    return F.conv1d(x, g.unsqueeze(1), padding=self.kernel_size // 2)


# First half of the original architecture (SincNet layer -> pooling -> Layer Norm -> Leaky ReLU)
sample_rate = 16000
frontend = nn.Sequential(
  SincConv(n_filters=80, kernel_size=251, sample_rate=sample_rate),
  nn.MaxPool1d(3),
  nn.GroupNorm(1, 80),     # normalize over channels and time together (in place of Layer Norm)
  nn.LeakyReLU(0.2),
)
chunk = torch.randn(8, 1, int(0.2 * sample_rate))  # eight 200 ms chunks
out = frontend(chunk)
print(out.shape)  # torch.Size([8, 80, 1066])

FAQ

Q. Can SincNet be used for speech recognition?
A.

Yes. The original paper dealt only with speaker recognition and listed speech recognition, emotion recognition, source separation, and music as future applications. The later LEAF paper compared SincNet on eight classification tasks, including acoustic scenes, bird audio, emotion, music, and keywords. When trained separately on each task, it outperformed the mel filterbank on speaker identification and language identification but underperformed on the other six tasks.

Q. How should the filter length $L$ be chosen?
A.

The original paper used L=251L = 251 (about 16 ms) for 16 kHz audio. A longer LL sharpens the band edges and resolves low frequencies more finely, but increases the cost of the convolution. The number of parameters stays at 2 per filter regardless of LL.

Q. Is it always better than MFCCs?
A.

Not always. Under the original paper's conditions, it was about the same as the mel filterbank on the low-data TIMIT and clearly better on the larger LibriSpeech. With little data, it is hard to learn filters that are much better than mel-scale filters.

References

  1. Ravanelli, M., & Bengio, Y. (2018). Speaker recognition from raw waveform with SincNet. 2018 IEEE Spoken Language Technology Workshop (SLT), 1021–1028.
  2. Official SincNet implementation (GitHub).