Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yoyololicon/kazane
Simple sinc interpolation in PyTorch.
https://github.com/yoyololicon/kazane
downsampling dsp pytorch-implementation upsample
Last synced: 21 days ago
JSON representation
Simple sinc interpolation in PyTorch.
- Host: GitHub
- URL: https://github.com/yoyololicon/kazane
- Owner: yoyololicon
- License: mit
- Created: 2021-06-13T11:17:23.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-07-08T15:59:06.000Z (over 1 year ago)
- Last Synced: 2024-10-04T15:48:40.569Z (about 1 month ago)
- Topics: downsampling, dsp, pytorch-implementation, upsample
- Language: Python
- Homepage:
- Size: 46.9 KB
- Stars: 14
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Kazane: simple sinc interpolation for 1D signal in PyTorch
[![build](https://github.com/yoyololicon/kazane/actions/workflows/python-package.yml/badge.svg)](https://github.com/yoyololicon/kazane/actions/workflows/python-package.yml)
[![Upload Python Package](https://github.com/yoyololicon/kazane/actions/workflows/python-publish.yml/badge.svg)](https://github.com/yoyololicon/kazane/actions/workflows/python-publish.yml)
[![PyPI version](https://badge.fury.io/py/kazane.svg)](https://badge.fury.io/py/kazane)Kazane utilize FFT based convolution to provide fast sinc interpolation for 1D signal when your sample rate only needs to change by an integer amounts; If you need to change by a fraction amounts, checkout [julius](https://github.com/adefossez/julius).
## Installation
```commandline
pip install kazane
```
or
``` commandline
pip install git+https://github.com/yoyololicon/kazane
```
for latest version.## Usage
```python
import kazane
import torchsignal = torch.randn(8, 2, 44100)
# downsample by an amount of 3
decimater = kazane.Decimate(3)
resampled_signal = decimater(signal)# upsample by an amount of 2
upsampler = kazane.Upsample(2)
resampled_signal = upsampler(signal)# you can also control number of zeros, roll-off frequency of the sinc interpolation kernel
decimater = kazane.Decimate(3, num_zeros=24, roll_off=0.9)# use other types of window function for the sinc kernel
upsampler = kazane.Upsample(2, window_func=torch.blackman_window)
```## Benchmarks on CUDA
Using the benchmark scripts at [bench](./bench), you can see that FFT can gives some speed improvements when the sample rate changes with some common integer numbers.
```
[---------- Down sample ----------]
| julius | kazane
2 threads: ------------------------
rate: 2 | 52.2 | 52.4
rate: 3 | 66.5 | 36.1
rate: 5 | 94.8 | 30.0
rate: 7 | 121.7 | 42.3Times are in milliseconds (ms).
[----------- Up sample -----------]
| julius | kazane
2 threads: ------------------------
rate: 2 | 48.8 | 39.0
rate: 3 | 68.1 | 51.6
rate: 5 | 112.5 | 78.9
rate: 7 | 159.4 | 108.0Times are in milliseconds (ms).
```