Algorithmadvanced
RASTA filtering
Also called relative spectral filtering, RASTA.
Band-pass filter the time series of each log spectral band to remove slow channel effects and fast frame-to-frame noise.
- Time
- O(T B) worst
- Space
- O(B) extra
- Where
- B = the number of bands; T = the number of frames
- Model
- Real RAM
- Properties
- deterministicexactnot in placeonline
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Hynek Hermansky, Nelson Morgan, 1994
RASTA filtering runs a fixed band-pass filter along time over the log energy of each spectral band, one value per frame, so that changes slower than about 0.3 Hz and faster than about 13 Hz are removed. Cepstral mean normalization removes only the mean of each trajectory over an utterance or a window; RASTA also removes slow drifts and fast jitter, and it works frame by frame with no look at the whole utterance. Delta features are also a filter along time, but they are added as new features, while RASTA replaces the trajectories it filters. It was made for perceptual linear prediction, where the filter runs on the log critical band spectrum before the all-pole fit, and it works the same way on the log energies of a mel filter bank.
In plain words
A microphone or a telephone line acts like a fixed tone control: it makes some frequencies louder and some softer, and it does not change while a person talks. After the log, such a fixed change adds the same number to a band in every frame. Speech, on the other hand, changes the energy of a band a few times per second, as the syllables come and go. RASTA follows each band over time and keeps only the changes that happen at about the speed of speech. A level that stays the same, or that drifts very slowly, is removed, and so is very fast flicker from one frame to the next. The result is a set of band energies that depends less on the microphone and the line.
The problem
Given the log band energies of frames and bands, for example from a mel filter bank or the critical band analysis of PLP at 100 frames per second, compute filtered trajectories such that a constant added to a band trajectory does not change the output, and the output keeps the modulation frequencies of speech while it removes very slow and very fast changes.
The algorithm
Hermansky and Morgan use, for each band, the filter
The factor only moves the output 4 frames earlier, so this page uses the causal filter without it, and its output is the same signal 4 frames later. The numerator is a smoothed slope over 5 frames, and the pole at is a leaky integrator. Before the first frame, the input is taken equal to the first value of the trajectory and the output to 0.
RASTA(X, ρ) ▷ X[t][j] for t = 0 .. T-1 and j = 1 .. B, with 0 ≤ ρ < 1- 1
for j ← 1 to B do - 2
x ← (X[0][j], …, X[T-1][j]); x[-4], …, x[-1] ← x[0]; y[-1] ← 0 - 3
for t ← 0 to T - 1 do u ← 0.1 (2 (x[t] - x[t-4]) + (x[t-1] - x[t-3])) - 4
y[t] ← u + ρ y[t-1]; Y[t][j] ← y[t] - 5
return Y
Line L3 is the numerator , with the taps written in pairs so that the four differences are exactly 0 on a constant. Line L4 is the denominator. Only the 4 last inputs and the last output of each band must be kept, so the filter runs as the frames arrive.
Example
The impulse response and the step response with are:
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | |
|---|---|---|---|---|---|---|---|---|
| 0.2 | 0.296 | 0.2901 | 0.1843 | |||||
| 0.2 | 0.496 | 0.7861 | 0.9704 | 0.951 | 0.932 | 0.9133 | 0.8951 |
Take one band whose log energy is 3 in every frame except frame 3, where a short burst makes it 4. Lines L3 and L4 give the output 0, 0, 0, 0.2, 0.296, 0.2901, 0.1843, , and so on: the constant 3 is gone and the burst comes out as the impulse response. If the channel adds 10 to this band, so the input is 13 with a burst of 14, the output is the same. If the level jumps from 3 to 4 at frame 3 and stays there, the output is the step response: it rises to 0.97 within 4 frames and then decays by the factor 0.98 per frame, to half its peak after about 34 frames, or 0.34 s at 100 frames per second.
The magnitude of at 100 frames per second, with :
| modulation frequency (Hz) | 0.1 | 0.5 | 1 | 2 | 5 | 10 | 20 | 30 |
|---|---|---|---|---|---|---|---|---|
| 0.300 | 0.849 | 0.960 | 0.989 | 0.957 | 0.814 | 0.365 | 0.028 | |
| dB |
The peak is 0.9895 at 2.22 Hz, and the gain stays within 3 dB of the peak from 0.31 Hz to 12.8 Hz. The numerator factors as , so is exactly 0 at 0 Hz, at 50 Hz, and at the frequency Hz, where the zeros of lie on the unit circle.
Correctness
The filter computes a defined transform, so correctness means that lines L1 to L5 compute it and that it has the properties the problem asks for. The full proofs are below.
- The recursion is the filter. Let for and for . Because the numerator taps sum to 0, line L3 gives the same for and for , so , where is the impulse response of without (theorem).
- Offsets are removed exactly. A constant trajectory gives from the first frame on, and adding a constant to a trajectory does not change any output (theorem).
- A fixed channel is removed approximately. A fixed linear filter multiplies the spectrum by a fixed . It adds a constant to a log band only when is nearly flat inside the band and the frames are much longer than the impulse response of the channel, so in practice RASTA removes most, not all, of a channel (heuristic).
- Stable. The only pole is at with , so is finite and a bounded input gives a bounded output (theorem).
- Same on cepstra. The filter is linear and the same for every band, and the DCT of MFCC is a fixed linear map, so filtering the log bands and then taking the DCT gives the same result as filtering each cepstral coefficient (theorem).
Proof: The RASTA recursion is a stable band-pass filter that removes offsets exactlyfull
We work in the real RAM on one band, since lines L1 and L2 only select the bands one at a time and each band is filtered on its own. Fix and a trajectory . Line L2 sets and . Write , so line L3 computes : the pairs and are just a grouping of the same sum. Line L4 computes .
Let be the impulse response of , the filter of the paper without the factor : for .
Lemma 1 (the taps sum to zero). , so does not change when the same constant is added to .
Proof. , and .
Lemma 2 (the recursion is the filter). Let for and for . Then for every ,
Proof. For the five inputs of are , which equal for every , also for where both sides are . By Lemma 1, . Unrolling line L4 with gives . Substitute and collect the terms with ; since is 0 at negative times, .
So the output is the zero-state response of to , and the output of the paper's filter is the same sequence shifted 4 frames earlier.
Lemma 3 (offsets are removed exactly). If for all , then for all . If for all , then for all .
Proof. In the first case , and Lemma 2 gives . In the second case , so , and Lemma 2 gives the same output.
Lemma 4 (the impulse and step responses). , , , , , and for . The step response satisfies for .
Proof. The impulse response satisfies line L4 with for and after, which gives the values. For the step, , which is 0 for by Lemma 1, so for .
With this gives and , the values in the example.
Lemma 5 (stability). , so a bounded input gives a bounded output: if for all , then .
Proof. By Lemma 4, , which is finite since . The bound follows from Lemma 2 and the triangle inequality.
Lemma 6 (the frequency response). For a frame rate and a modulation frequency , let . Then , and is 0 exactly at , at , and at in .
Proof. on the unit circle. The numerator is , using . The first factor is 0 at . The second is on the unit circle, which is 0 exactly when . The denominator is never 0 on the unit circle because .
Lemma 7 (same on cepstra). Let be any fixed matrix, such as the DCT of MFCC. Filtering every band of and then applying to each frame gives the same result as applying to each frame and then filtering every coefficient.
Proof. By Lemma 2 each output is , a linear map of the trajectory with the same weights for every . So , which is the filter applied to the trajectory of coefficient .
Theorem. For , RASTA returns for each band the output of the stable filter , the paper's filter delayed by 4 frames, applied to the trajectory minus its first value. A constant offset on a band changes no output, and the filter has zeros at 0 Hz and at half the frame rate.
Proof. Lemmas 2, 3, 5 and 6.
The tests check Lemma 4 against the first values of the impulse and step responses, Lemma 3 on a constant and on an offset trajectory, Lemma 6 by comparing the gain on long sines with , and a fixed channel added to every frame of a log band spectrogram.
Complexity
In the real RAM, line L3 costs 4 additions and 2 multiplications and line L4 one multiplication and one addition, so the work is , about 8 operations per band and frame. The state is 4 past inputs and 1 past output per band, numbers, beyond the output. The implementation here copies each band into a list, which uses more memory but does not change the time.
Properties
- Causal and online. The causal form needs no future frames; its output is the noncausal filter of the paper delayed by 4 frames.
- Linear and time invariant along time. The filter commutes with any fixed linear map across the bands, such as the DCT.
- Not a linear phase filter. The pole makes the group delay change with the modulation frequency, so peaks of the trajectories move by different amounts. Recognizers trained on RASTA features learn this shape.
- Long memory. With the time constant is about 50 frames, or 0.5 s. The filter needs about this long to forget an old level.
Variants and improvements
- Pole 0.94. Ellis's widely used rastamat code uses , which shortens the memory to about 16 frames and moves the 3 dB band to 0.88 Hz to 13.5 Hz.
- J-RASTA. Hermansky and Morgan also describe filtering in place of , where depends on the noise level. For small this is nearly linear in , so additive noise becomes closer to an offset that the filter can reduce.
- RASTA on cepstra. Many systems filter the cepstral coefficients in place of the log bands. By the linearity argument above the result is the same up to the truncation of the DCT.
- Learned temporal filters. Later work designed the filter along time from data, for example with linear discriminant analysis on long spans of log band energies.
When to use it
Use RASTA when the channel changes between training and test, for example different microphones or telephone lines, and the system must process speech as it arrives, so that the mean over a whole utterance is not available. For offline recognition with utterances of a few seconds, cepstral mean normalization over the utterance is simpler and removes a constant offset just as well. Do not expect RASTA to remove additive noise: noise adds to the power, not to the log, and spectral subtraction or a Wiener filter addresses it.
Pitfalls
- Filter the log, not the energy. The channel becomes an offset only after the log. RASTA on the power spectrum does not remove it.
- Frame rate. The coefficients are designed for 100 frames per second. At another frame rate every frequency of the response scales with the rate, so the pass band moves.
- Start up. The first frames depend on the initial state. This page repeats the first input and sets the past output to 0, so a constant start gives 0; other toolkits start differently, and their first frames do not match.
- Delay. The causal output is 4 frames late compared with the filter of the paper. When RASTA features are combined with unfiltered features, align them first.
- Short utterances. With a change of channel is forgotten only after about half a second, so utterances shorter than that keep part of the channel.
Implementations
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/rasta-filtering/. The authors are listed in prov/C4662N.jsonl.
"""RASTA filtering of the log band energies of speech, after Hermansky and Morgan (1994).
Each band trajectory (the log energy of one band, one value per frame) goes
through the band-pass filter
H(z) = 0.1 (2 + z^-1 - z^-3 - 2 z^-4) / (1 - rho z^-1),
which is the filter of the paper without its factor z^4. That factor only moves
the output 4 frames earlier, so this causal form gives the same output 4 frames
later. The paper uses rho = 0.98. Ellis's rastamat code uses rho = 0.94.
Before the first frame the input is taken equal to x[0] and the output to 0, so a
constant trajectory gives 0 from the first frame on. The numerator taps sum to 0,
so adding a constant to a trajectory does not change the output.
"""
from typing import List, Sequence
def rasta_filter(x: Sequence[float], rho: float = 0.98) -> List[float]:
"""Filter one trajectory: y[t] = sum_k b_k x[t - k] + rho y[t - 1], with b = 0.1 (2, 1, 0, -1, -2)."""
if not 0.0 <= rho < 1.0:
raise ValueError("rho must be in [0, 1) for a stable filter")
if not x:
return []
y: List[float] = []
prev = 0.0
def past(t: int) -> float:
return x[t] if t >= 0 else x[0]
for t in range(len(x)):
# the taps in pairs, so that a constant gives exactly 0
u = 0.1 * (2.0 * (x[t] - past(t - 4)) + (past(t - 1) - past(t - 3))) # @line L3
prev = u + rho * prev # @line L4
y.append(prev)
return y # @line L5
def rasta_bands(log_bands: Sequence[Sequence[float]], rho: float = 0.98) -> List[List[float]]:
"""Filter every band of a log band spectrogram given as rows of frames (T rows of B values).
Returns T rows of B values. Each column (one band over time) is filtered on its own."""
if not log_bands:
return []
width = len(log_bands[0])
if any(len(row) != width for row in log_bands):
raise ValueError("all frames must have the same number of bands")
columns = []
for j in range(width): # @line L1
traj = [row[j] for row in log_bands] # @line L2
columns.append(rasta_filter(traj, rho))
return [[columns[j][t] for j in range(width)] for t in range(len(log_bands))]
test_rasta_filtering.py 98 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/rasta-filtering/. The authors are listed in prov/C4662N.jsonl.
import cmath
import math
import random
from rasta_filtering import rasta_bands, rasta_filter
def _h(f, rho, frame_rate=100.0):
z = cmath.exp(2j * math.pi * f / frame_rate)
return 0.1 * (2 + z**-1 - z**-3 - 2 * z**-4) / (1 - rho * z**-1)
def test_impulse_response():
rho = 0.98
x = [0.0] * 5 + [1.0] + [0.0] * 30
y = rasta_filter(x, rho)
assert y[:5] == [0.0] * 5
b = [0.2, 0.1, 0.0, -0.1, -0.2]
# h[n] = sum_{k <= min(n, 4)} b_k rho^(n - k)
for n in range(30):
ref = sum(b[k] * rho ** (n - k) for k in range(min(n, 4) + 1))
assert abs(y[5 + n] - ref) < 1e-12
def test_constant_gives_zero():
assert all(v == 0.0 for v in rasta_filter([3.5] * 50))
def test_offset_does_not_change_the_output():
rng = random.Random(2)
x = [rng.uniform(-5, 5) for _ in range(300)]
for rho in (0.98, 0.94):
a = rasta_filter(x, rho)
b = rasta_filter([v + 17.0 for v in x], rho)
assert all(abs(u - v) < 1e-9 for u, v in zip(a, b))
def test_step_decays_geometrically():
rho = 0.98
x = [0.0] * 10 + [1.0] * 200
y = rasta_filter(x, rho)
# after the 5 numerator taps have all seen the step, only the pole acts
for t in range(14, 210):
assert abs(y[t] - rho * y[t - 1]) < 1e-12
# the first outputs are the partial sums of the taps: 0.2, then 0.2 rho + 0.1, ...
assert abs(y[10] - 0.2) < 1e-12 and abs(y[11] - (0.2 * rho + 0.3)) < 1e-12
assert y[209] < 0.03 * max(y)
def test_sine_gain_matches_the_transfer_function():
rho = 0.98
for f in (0.5, 4.0, 12.0, 25.0):
n = 4000
x = [math.sin(2 * math.pi * f * t / 100.0) for t in range(n)]
y = rasta_filter(x, rho)
tail = range(2000, n)
c = sum(y[t] * math.cos(2 * math.pi * f * t / 100.0) for t in tail) * 2 / len(tail)
s = sum(y[t] * math.sin(2 * math.pi * f * t / 100.0) for t in tail) * 2 / len(tail)
assert abs(math.hypot(c, s) - abs(_h(f, rho))) < 2e-3
def test_pass_band_numbers():
# the -3 dB points of the paper's filter at 100 frames per second
assert abs(_h(0.0 + 1e-9, 0.98)) < 1e-6
peak = max(abs(_h(i / 100.0, 0.98)) for i in range(1, 5000))
assert abs(_h(0.30, 0.98)) < peak / math.sqrt(2) < abs(_h(0.32, 0.98))
assert abs(_h(12.9, 0.98)) < peak / math.sqrt(2) < abs(_h(12.8, 0.98))
def test_bands_remove_a_fixed_channel():
rng = random.Random(4)
spec = [[rng.uniform(-3, 3) for _ in range(6)] for _ in range(80)]
channel = [0.5, -1.0, 2.0, 0.0, 3.0, -0.25] # a fixed log gain per band
a = rasta_bands(spec)
b = rasta_bands([[v + g for v, g in zip(row, channel)] for row in spec])
assert len(a) == 80 and all(len(r) == 6 for r in a)
assert all(abs(u - v) < 1e-9 for ra, rb in zip(a, b) for u, v in zip(ra, rb))
col = rasta_filter([row[2] for row in spec])
assert all(abs(a[t][2] - col[t]) < 1e-15 for t in range(80))
def test_bad_arguments():
assert rasta_filter([]) == [] and rasta_bands([]) == []
for bad in (1.0, -0.1):
try:
rasta_filter([1.0], bad)
except ValueError:
continue
raise AssertionError(bad)
try:
rasta_bands([[1.0, 2.0], [1.0]])
except ValueError:
pass
else:
raise AssertionError("ragged input must fail")
History
Hermansky and colleagues introduced RASTA in the early 1990s as an addition to perceptual linear prediction, and Hermansky and Morgan gave the full account in 1994. The idea came from hearing: listeners pay little attention to a sound whose spectrum does not change, and the spectrum of speech changes at the rate of syllables. A filter along time on the log spectrum copies this, and since a fixed channel is an offset in the log domain, the same filter removes the channel. RASTA-PLP was widely used for telephone speech in the 1990s, and the idea of filtering band trajectories along time led to later work on modulation spectrum features.
References
- Hynek Hermansky and Nelson Morgan, RASTA processing of speech, IEEE Transactions on Speech and Audio Processing 2(4), 1994, 578 to 589, the RASTA band-pass filter of the log critical band trajectories, its transfer function with the pole at 0.98, and the J-RASTA variant for additive noise
- Xuedong Huang, Alex Acero and Hsiao-Wuen Hon, Spoken Language Processing, Prentice Hall, 2001, Chapter 10 (Environmental Robustness), the discussion of cepstral mean normalization and RASTA
- Daniel P. W. Ellis, PLP and RASTA (and MFCC, and inversion) in Matlab, the function rastafilt.m, which uses a pole of 0.94
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 | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag C4662N Edit this page History Report an error Markdown