Fast, efficient, and differentiable time-varying LPC filtering in PyTorch.
Project description
TorchLPC
torchlpc
provides a PyTorch implementation of the Linear Predictive Coding (LPC) filtering operation, also known as IIR filtering.
It's fast, differentiable, and supports batched inputs with time-varying filter coefficients.
The computation is done as follows:
Given an input signal $\mathbf{x} \in \mathbb{R}^T$ and time-varying LPC coefficients $\mathbf{A} \in \mathbb{R}^{T \times N}$ with an order of $N$, the LPC filtering operation is defined as:
\mathbf{y}_t = \mathbf{x}_t - \sum_{i=1}^N \mathbf{A}_{t,i} \mathbf{y}_{t-i}.
It's still in early development, so please open an issue if you find any bugs.
Usage
import torch
from torchlpc import sample_wise_lpc
# Create a batch of 10 signals, each with 100 time steps
x = torch.randn(10, 100)
# Create a batch of 10 sets of LPC coefficients, each with 100 time steps and an order of 3
A = torch.randn(10, 100, 3)
# Apply LPC filtering
y = sample_wise_lpc(x, A)
# Optionally, you can provide initial values for the output signal (default is 0)
zi = torch.randn(10, 3)
y = sample_wise_lpc(x, A, zi=zi)
Installation
pip install torchlpc
or from source
pip install git+https://github.com/yoyololicon/torchlpc.git
Derivation of the gradients of the LPC filtering operation
Will (not) be added soon... I'm not good at math :sweat_smile:.
But the implementation passed both gradcheck
and gradgradcheck
tests, so I think it's 99.99% correct and workable :laughing:.
The algorithm is extended from my recent paper GOLF[^1].
[^1]: Singing Voice Synthesis Using Differentiable LPC and Glottal-Flow-Inspired Wavetables.
TODO
- Use PyTorch C++ extension for faster computation.
- Use native CUDA kernels for GPU computation.
- Add examples.
Citation
If you find this repository useful in your research, please cite the repository with the following BibTex entry:
@software{torchlpc,
author = {Chin-Yun Yu},
title = {{TorchLPC}: fast, efficient, and differentiable time-varying {LPC} filtering in {PyTorch}},
year = {2023},
version = {0.1.0},
url = {https://github.com/yoyololicon/torchlpc},
}
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file torchlpc-0.2.tar.gz
.
File metadata
- Download URL: torchlpc-0.2.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 808cb942e49a90ba97c8f4607acafc5d3aa6e26dcc4e446dfb1b1daeacef4b20 |
|
MD5 | c4cc5822e1325f0bc75a4f5b864789d0 |
|
BLAKE2b-256 | ea3295c5d94039b6871ed437db6f126814e3a51ec0205f1291e3f6adae6201de |
File details
Details for the file torchlpc-0.2-py3-none-any.whl
.
File metadata
- Download URL: torchlpc-0.2-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33eac91a61e61b01ef65130c8b6fd5116361530c332332a0e54935d51514dddc |
|
MD5 | 24e43743cc228fad373d802655bce99b |
|
BLAKE2b-256 | f27ffd9a8888e11e44df728564e2a578edea7c15d90b31e824fb66c8e720a261 |