Time-Domain Filtering
Time-domain filtering functions that run efficiently on CPU and GPU, and are differentiable in all arguments. The implementations are strongly based on philtorch and torchlpc.
Time-Invariant Filtering
Functions that apply linear time-invariant (LTI) filters to time-domain signals. Filter coefficients are constant over time.
korvax.filter.lti.lfilter
lfilter(
x: Float[Array, " n_samples"],
a: Float[Array, " n_a"] | None = None,
b: Float[Array, " n_b"] | None = None,
zi: Float[Array, " order"] | None = None,
*,
return_zi: Literal[False] = False,
transposed: bool = True,
) -> Float[Array, " n_samples"]
lfilter(
x: Float[Array, " n_samples"],
a: Float[Array, " n_a"] | None = None,
b: Float[Array, " n_b"] | None = None,
zi: Float[Array, " order"] | None = None,
*,
return_zi: Literal[True],
transposed: bool = True,
) -> tuple[
Float[Array, " n_samples"], Float[Array, " order"]
]
lfilter(
x,
a=None,
b=None,
zi=None,
*,
return_zi=False,
transposed=True,
)
Apply a time-invariant filter to the input signal.
Filtering is implemented using the state-space implementations with parallel associative scans as described in [1]. In the time-invariant case, this is also efficient at higher filter orders.
This function only operates on 1D signals, use jax.vmap to apply it to batched inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Float[Array, ' n_samples']
|
Input signal of shape |
required |
a
|
Float[Array, ' n_a'] | None
|
Denominator (IIR) coefficients |
None
|
b
|
Float[Array, ' n_b'] | None
|
Numerator (FIR) coefficients |
None
|
zi
|
Float[Array, ' order'] | None
|
Initial conditions of shape |
None
|
return_zi
|
bool
|
If |
False
|
transposed
|
bool
|
Whether to use transposed direct form II structure (default). Uses direct form II otherwise. |
True
|
Returns:
| Type | Description |
|---|---|
tuple[Float[Array, ' n_samples'], Float[Array, ' order']] | Float[Array, ' n_samples']
|
If
|
References
[1] C.-Y. Yu and G. Fazekas. "Accelerating Automatic Differentiation of Direct Form Digital Filters", DiffSys Workshap at EurIPS, 2025.
Source code in src/korvax/filter/lti.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
korvax.filter.lti.sosfilt
sosfilt(
x: Float[Array, " n_samples"],
a: Float[Array, " n_sections 2"],
b: Float[Array, " n_sections 3"],
zi: Float[Array, " n_sections 2"] | None = None,
*,
return_zi: Literal[False] = False,
) -> Float[Array, " n_samples"]
sosfilt(
x: Float[Array, " n_samples"],
a: Float[Array, " n_sections 2"],
b: Float[Array, " n_sections 3"],
zi: Float[Array, " n_sections 2"] | None = None,
*,
return_zi: Literal[True],
) -> tuple[
Float[Array, " n_samples"],
Float[Array, " n_sections 2"],
]
sosfilt(x, a, b, zi=None, *, return_zi=False)
Apply a cascade of time-invariant second-order filters (biquads) to the input signal.
This function only operates on 1D signals, use jax.vmap to apply it to batched inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Float[Array, ' n_samples']
|
Input signal of shape |
required |
a
|
Float[Array, ' n_sections 2']
|
Denominator (IIR) coefficients of shape |
required |
b
|
Float[Array, ' n_sections 3']
|
Numerator (FIR) coefficients of shape |
required |
zi
|
Float[Array, ' n_sections 2'] | None
|
Initial conditions of shape |
None
|
return_zi
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
tuple[Float[Array, ' n_samples'], Float[Array, ' n_sections 2']] | Float[Array, ' n_samples']
|
If |
Source code in src/korvax/filter/lti.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
Time-Varying Filtering
Functions that apply linear time-varying (LTV) filters to time-domain signals. Filter coefficients can change at audio sample rate.
korvax.filter.ltv.lfilter
lfilter(
x: Float[Array, " n_samples"],
a: Float[Array, " n_samples n_a"] | None = None,
b: Float[Array, " n_samples n_b"] | None = None,
zi: Float[Array, " order"] | None = None,
*,
return_zi: Literal[False] = False,
transposed: bool = False,
) -> Float[Array, " n_samples"]
lfilter(
x: Float[Array, " n_samples"],
a: Float[Array, " n_samples n_a"] | None = None,
b: Float[Array, " n_samples n_b"] | None = None,
zi: Float[Array, " order"] | None = None,
*,
return_zi: Literal[True],
transposed: bool = False,
) -> tuple[
Float[Array, " n_samples"], Float[Array, " order"]
]
lfilter(
x,
a=None,
b=None,
zi=None,
*,
return_zi=False,
transposed=False,
)
Apply a linear filter with time-varying coefficients to the input signal.
Filtering is implemented using the state-space implementations with parallel associative scans as described in [1].
No diagonalization is implemented currently! For time-varying filters with order > ~4, combining ltv.fir and ltv.allpole will likely be a lot more performant.
This function only operates on 1D signals, use jax.vmap to apply it to batched inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Float[Array, ' n_samples']
|
Input signal of shape |
required |
a
|
Float[Array, ' n_samples n_a'] | None
|
Time-varying denominator (IIR) coefficients |
None
|
b
|
Float[Array, ' n_samples n_b'] | None
|
Time-varying numerator (FIR) coefficients |
None
|
zi
|
Float[Array, ' order'] | None
|
Initial conditions of shape |
None
|
return_zi
|
bool
|
If |
False
|
transposed
|
bool
|
Whether to use transposed direct form II structure. Uses direct form II if False (default). |
False
|
Returns:
| Type | Description |
|---|---|
tuple[Float[Array, ' n_samples'], Float[Array, ' order']] | Float[Array, ' n_samples']
|
If
|
References
[1] C.-Y. Yu and G. Fazekas. "Accelerating Automatic Differentiation of Direct Form Digital Filters", DiffSys Workshap at EurIPS, 2025.
Source code in src/korvax/filter/ltv.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
korvax.filter.ltv.sosfilt
sosfilt(
x: Float[Array, " n_samples"],
a: Float[Array, " n_sections n_samples 2"],
b: Float[Array, " n_sections n_samples 3"],
zi: Float[Array, " n_sections 2"] | None = None,
*,
return_zi: Literal[False] = False,
) -> Float[Array, " n_samples"]
sosfilt(
x: Float[Array, " n_samples"],
a: Float[Array, " n_sections n_samples 2"],
b: Float[Array, " n_sections n_samples 3"],
zi: Float[Array, " n_sections 2"] | None = None,
*,
return_zi: Literal[True],
) -> tuple[
Float[Array, " n_samples"],
Float[Array, " n_sections 2"],
]
sosfilt(x, a, b, zi=None, *, return_zi=False)
Apply a cascade of second-order filters (biquads) with time-varying coefficients to the input signal.
This function only operates on 1D signals, use jax.vmap to apply it to batched inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Float[Array, ' n_samples']
|
Input signal of shape |
required |
a
|
Float[Array, ' n_sections n_samples 2']
|
Denominator (IIR) coefficients of shape |
required |
b
|
Float[Array, ' n_sections n_samples 3']
|
Numerator (FIR) coefficients of shape |
required |
zi
|
Float[Array, ' n_sections 2'] | None
|
Initial conditions of shape |
None
|
return_zi
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
tuple[Float[Array, ' n_samples'], Float[Array, ' n_sections 2']] | Float[Array, ' n_samples']
|
If |
Source code in src/korvax/filter/ltv.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
korvax.filter.ltv.fir
fir(x, b, zi=None)
Apply a linear FIR filter with time-varying coefficients to the input signal.
This function only operates on 1D signals, use jax.vmap to apply it to batched inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Float[Array, ' n_samples']
|
Input signal of shape |
required |
b
|
Float[Array, ' n_samples n_b']
|
Time-varying FIR coefficients |
required |
zi
|
Float[Array, ' n_b-1'] | None
|
Initial conditions of shape |
None
|
Returns:
| Type | Description |
|---|---|
Float[Array, ' n_samples']
|
Filtered signal of shape |
Source code in src/korvax/filter/ltv.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | |
korvax.filter.ltv.allpole
allpole(
x: Float[Array, " n_samples"],
a: Float[Array, " n_samples order"],
zi: Float[Array, " order"] | None = None,
*,
return_zi: Literal[False] = False,
) -> Float[Array, " n_samples"]
allpole(
x: Float[Array, " n_samples"],
a: Float[Array, " n_samples order"],
zi: Float[Array, " order"] | None = None,
*,
return_zi: Literal[True],
) -> tuple[
Float[Array, " n_samples"], Float[Array, " order"]
]
allpole(x, a, zi=None, return_zi=False)
Apply a time-varying all-pole filter to the input signal.
Port of torchlpc.sample_wise_lpc. Uses the efficient differentiation method proposed in [1].
This function only operates on 1D signals, use jax.vmap to apply it to batched inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Float[Array, ' n_samples']
|
Input signal of shape |
required |
a
|
Float[Array, ' n_samples order']
|
Time-varying all-pole coefficients of shape |
required |
zi
|
Float[Array, ' order'] | None
|
Initial conditions of shape |
None
|
return_zi
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
Float[Array, ' n_samples'] | tuple[Float[Array, ' n_samples'], Float[Array, ' order']]
|
If
|
References
[1] C.-Y. Yu, C. Mitcheltree, A. Carson, S. Bilbao, J. D. Reiss, and G. Fazekas. "Differentiable All-Pole Filters for Time-Varying Audio Systems," in Proc. DAFx, 2024.
Source code in src/korvax/filter/ltv.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |