Techniquecore
Delta features
Also called delta and delta-delta coefficients, dynamic features, acceleration coefficients.
Append to each frame the slopes of its features over a few neighbouring frames, and the slopes of those, found by linear regression.
Delta features add to each frame of a speech feature sequence, such as MFCC, the local slope of each coefficient over time, and delta-delta features add the slope of that slope. The slope is the least squares slope of a line fitted to a few frames on each side, so it is a short FIR filter along time, applied to each coefficient. RASTA filtering also filters along time, but it replaces the trajectories, while deltas are appended to the static features; cepstral mean normalization changes only the mean, which the deltas ignore. With 13 static coefficients the result is the standard 39 numbers per frame.
In plain words
One frame of MFCC describes the sound in a 25 ms slice, but speech is about change: a vowel glides into a consonant, and the change tells as much as the slice. The delta of a coefficient says how fast it is rising or falling at this frame. It is found by looking two frames back and two frames ahead and fitting a straight line through the five values; the slope of that line is the delta. The delta-delta does the same to the deltas, so it says whether the change is speeding up or slowing down. At the start and the end of the recording there are no frames to look at, so the first and last frames are repeated.
When it applies
- The features form a sequence of vectors at a fixed frame rate, usually 100 frames per second, and the model treats frames as if they were independent given their state, as a GMM-HMM does. Deltas put information about the neighbours into each frame.
- The features change smoothly over a few frames, so that a local line is a good summary of the trajectory.
- The slope should be robust to frame-to-frame noise. A plain difference of two frames is noisier than a regression over five.
- Neural acoustic models that see many frames at once, by stacking frames or by convolution and recurrence, gain little from deltas, and they are often left out there.
The template
For a sequence of feature vectors and a half width , the delta of frame is
computed for each coefficient on its own, with for and for . The usual value is , for which the denominator is 10. The delta-deltas are the deltas of the deltas.
DELTAS(c, Θ) ▷ c[t][j] for t = 0 .. T-1 and j = 1 .. D, with Θ ≥ 1- 1
den ← 2 (1² + 2² + … + Θ²); s[t][j] ← 0 for all t and j - 2
for t ← 0 to T - 1, j ← 1 to D, n ← 1 to Θ do a ← c[min(t + n, T - 1)][j]; b ← c[max(t - n, 0)][j] - 3
s[t][j] ← s[t][j] + n (a - b) - 4
return d with d[t][j] ← s[t][j] / den ADD-DELTAS(c, Θ)- 5
d ← DELTAS(c, Θ) - 6
dd ← DELTAS(d, Θ); return the frames (c[t], d[t], dd[t]) for t ← 0 to T - 1
Why it is a slope (theorem). For the points with , the least squares line has , because the are centered, . Pairing with gives exactly . So a straight line gives wherever no edge frame is repeated, and a constant gives 0 everywhere.
Why offsets do not matter (theorem). Adding the same vector to every frame adds to each term, so the deltas, and so the delta-deltas, do not change. A fixed channel that cepstral mean normalization removes from the static features is thus already absent from the dynamic ones.
As a filter (theorem). For , the delta is the FIR filter along time. On a sine with radians per frame its gain is , which is about for small , like a derivative, peaks at 0.547 near 13.8 Hz at 100 frames per second, and is 0 at 0 Hz, at 50 Hz and where , near 29.0 Hz. The numerator of the RASTA filter is the same 5 taps.
Classic examples
A quadratic. For one coefficient with the values , lines L1 to L4 with give . At , the only frame with two real neighbours on each side, , which is the slope of the quadratic at . The other values are pulled down by the repeated edge frames. The delta-deltas are ; for a long quadratic sequence they would be the constant second difference 1 away from the edges, but 5 frames are too few for any frame to be clear of the edges in both passes.
A ramp. For over 20 frames, for and for .
The 39-dimensional vector. Thirteen MFCC per frame, their 13 deltas and their 13 delta-deltas give 39 numbers per frame, the standard input of GMM-HMM recognizers. Many recipes use the log energy of the frame in place of .
A tone at the syllable rate. A coefficient that oscillates at 4 Hz with amplitude 1, at 100 frames per second, has and a delta of amplitude 0.2425 per frame, close to the amplitude of the derivative. The taps are odd around frame , so the phase of the delta is exactly that of the derivative, with no added delay.
Variations
- Window size. gives the central difference ; smooths more. HTK and Kaldi both take as an option, and 2 is the common choice.
- Delta-deltas in one pass. Kaldi computes the second order coefficients by applying the combined 9-tap filter to the static features, with the clamp on the static frames. In the interior this equals the deltas of the deltas; within 4 frames of an edge the two differ.
- Savitzky-Golay deltas. librosa estimates the derivative with a Savitzky-Golay filter of width 9 by default, a local polynomial fit that contains the linear regression above as its first order case.
- Third differentials. HTK can add the deltas of the delta-deltas, for 52 numbers per frame.
- Frame stacking and projection. In place of deltas, stack the static features of 7 to 11 frames and reduce the dimension with linear discriminant analysis. This learns the temporal filters from data.
Pitfalls
- Units. The deltas are per frame. A model trained at 100 frames per second sees different numbers at another frame rate, or when the frames are counted in seconds.
- Edge frames. Repeating the first and last frames, as here and in Kaldi, makes the deltas of the first and last frames smaller. Padding with zeros instead creates large false slopes at the edges, because the features are not near 0.
- Different delta-delta conventions. Deltas of deltas and the combined filter agree only away from the edges, so two toolkits can disagree on the first and last frames.
- Normalizing after deltas. Mean normalization does not change the deltas, but variance normalization does. Apply it to the full 39-dimensional vector if the model expects unit variances.
- Streaming. The delta needs frames of the future, and the delta-delta . A streaming recognizer must wait 4 frames, 40 ms, before it can emit a frame.
Code
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/delta-features/. The authors are listed in prov/AZKQ3W.jsonl.
"""Delta and delta-delta (acceleration) coefficients of a sequence of feature vectors.
The regression formula of HTK:
d_t = sum_{n=1}^{Theta} n (c_{t+n} - c_{t-n}) / (2 sum_{n=1}^{Theta} n^2),
with Theta = 2 by default. At the edges the first and the last frames are repeated,
so c_{t} for t < 0 is c_0 and for t >= T is c_{T-1}. The delta-deltas are the
deltas of the deltas, with the same formula. Thirteen static coefficients give a
vector of 13 + 13 + 13 = 39 numbers per frame.
"""
from typing import List, Sequence
def deltas(c: Sequence[Sequence[float]], theta: int = 2) -> List[List[float]]:
"""The deltas of T frames of D values each. Returns T frames of D values."""
if theta < 1:
raise ValueError("theta must be at least 1")
t_count = len(c)
if t_count == 0:
return []
dim = len(c[0])
denom = 2.0 * sum(n * n for n in range(1, theta + 1)) # @line L1
out = []
for t in range(t_count):
row = []
for j in range(dim):
acc = 0.0
for n in range(1, theta + 1):
ahead = c[min(t + n, t_count - 1)][j] # @line L2
behind = c[max(t - n, 0)][j]
acc += n * (ahead - behind) # @line L3
row.append(acc / denom) # @line L4
out.append(row)
return out
def add_deltas(c: Sequence[Sequence[float]], theta: int = 2) -> List[List[float]]:
"""Each frame becomes [static, delta, delta-delta], 3 D values."""
d = deltas(c, theta) # @line L5
dd = deltas(d, theta) # @line L6
return [list(a) + b + e for a, b, e in zip(c, d, dd)]
test_delta_features.py 61 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/delta-features/. The authors are listed in prov/AZKQ3W.jsonl.
import random
from delta_features import add_deltas, deltas
def test_ramp_gives_its_slope():
c = [[2.0 * t + 1.0, -0.5 * t] for t in range(10)]
d = deltas(c)
for t in range(2, 8): # away from the edges
assert abs(d[t][0] - 2.0) < 1e-12 and abs(d[t][1] + 0.5) < 1e-12
# at the edges the repeated frames lower the slope: t = 0 gives (1 * 2 + 2 * 4) / 10 = 1.0
assert abs(d[0][0] - 1.0) < 1e-12
assert abs(d[1][0] - (1 * 4.0 + 2 * 6.0) / 10.0) < 1e-12
def test_constant_gives_zero():
d = deltas([[3.0, 4.0]] * 6)
assert all(v == 0.0 for row in d for v in row)
def test_quadratic_gives_a_constant_acceleration():
c = [[0.5 * t * t] for t in range(20)]
full = add_deltas(c)
for t in range(4, 16):
assert abs(full[t][1] - t) < 1e-12 # the slope of t^2 / 2 is t
assert abs(full[t][2] - 1.0) < 1e-12
def test_delta_is_the_least_squares_slope():
rng = random.Random(6)
c = [[rng.uniform(-1, 1)] for _ in range(30)]
for theta in (1, 2, 3):
d = deltas(c, theta)
for t in range(theta, 30 - theta):
xs = list(range(-theta, theta + 1))
ys = [c[t + n][0] for n in xs]
mean_y = sum(ys) / len(ys)
slope = sum(x * (y - mean_y) for x, y in zip(xs, ys)) / sum(x * x for x in xs)
assert abs(d[t][0] - slope) < 1e-12
def test_thirty_nine_numbers():
rng = random.Random(1)
c = [[rng.gauss(0, 1) for _ in range(13)] for _ in range(50)]
full = add_deltas(c)
assert len(full) == 50 and all(len(row) == 39 for row in full)
assert all(row[:13] == list(s) for row, s in zip(full, c))
def test_edges_and_bad_input():
assert deltas([]) == []
assert deltas([[5.0]]) == [[0.0]]
try:
deltas([[1.0]], 0)
except ValueError:
pass
else:
raise AssertionError("theta 0 must fail")
Exercises
- Show that for the delta of away from the edges is , and that the delta-delta is 2.
- Prove that the delta of any sequence is the least squares slope of a line fitted to the frames around , after the edge frames are repeated.
- Write the delta and the delta-delta as one FIR filter of 9 taps for , and find its coefficients.
- Find the gain of the filter on a sine of radians per frame, and compare it with the filter at 5 Hz and at 25 Hz at 100 frames per second.
- Show that adding a fixed vector to every frame leaves both the deltas and the delta-deltas unchanged, and explain why this means mean normalization can come before or after the delta computation.
Proof: Deltas are least squares slopes, ignore offsets, and give 39 numbers from 13full
We work in the real RAM. Fix and a sequence of vectors of dimension with . Every step works on each coordinate on its own, so we write for one coordinate. Let be the sequence with the edge frames repeated, and .
Lemma 1 (lines L1 to L4 compute the formula). DELTAS returns for .
Proof. Line L1 sets and every to 0. Line L2 reads and , because for , and similarly for . Line L3 adds once for each from 1 to , and line L4 divides by .
Lemma 2 (least squares slope). For each , is the slope of the line that minimizes .
Proof. The objective is a convex quadratic in . Setting the derivatives to 0 gives and . Since and , the second equation gives , and the system has this unique solution. The terms for and combine to , and the term is 0, so by Lemma 1.
Lemma 3 (lines and constants). If for all , then for . If for all , then for all .
Proof. For those no index is clamped, so and . For a constant, is the same constant, every difference is 0, and .
Lemma 4 (offsets). If for all , then and for all .
Proof. , so every difference in Lemma 1 is unchanged, hence . The delta-deltas are DELTAS applied to , so they are unchanged too.
Lemma 5 (the output of ADD-DELTAS). Line L5 computes and line L6 computes by Lemma 1 on the sequence , which also has frames of dimension . Each output frame is the concatenation of , and , so it has coordinates; for this is 39.
Proof. Lemma 1 shows that DELTAS returns frames of values, and line L6 concatenates three such frames.
Theorem. ADD-DELTAS returns for each frame the static features, their least squares slopes over frames with the edges repeated, and the slopes of those slopes. The result does not change when a constant vector is added to every frame, and a straight line gives its slope away from the edges.
Proof. Lemmas 1 to 5.
The tests check Lemma 3 on a ramp and a constant, Lemma 2 against a direct least squares fit on random data with a fixed seed, the delta-delta of a quadratic away from the edges, the edge values against the repeated frames, and Lemma 5 with 13 coefficients.
References
- S. Furui, Speaker-independent isolated word recognition using dynamic features of speech spectrum, the regression coefficients of the cepstrum over neighbouring frames, used together with the cepstrum itself
- The HTK Book, version 3.4, Chapter Speech Input/Output, section Delta, Acceleration and Third Differential Coefficients (the regression formula with the window size Θ)
- Kaldi speech recognition toolkit, src/feat/feature-functions.cc, the class DeltaFeatures: the regression window normalized by the sum of j squared, and frames outside the utterance clamped to the first and last frames
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H2 full proof |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag AZKQ3W Edit this page History Report an error Markdown