Skip to main content

An implementation of STFT and Inverse STFT in mlx

Project description

Short-Time Fourier Transform (STFT)

This module implements the Short-Time Fourier Transform (STFT) in Python using MLX.

It is designed to inherit from the nn.Module, which allows it to be used either as a standalone module or as part of a larger neural network architecture.

Installation

You can install mlx_stft directly from pypi:

pip install mlx_stft

Or you can install it directly from the source code:

git clone https://github.com/nuniz/mlx_stft.git
cd mlx_stft
python setup.py install

Usage

from mlx_stft import STFT

# Create an instance of the STFT module
stft = STFT(n_fft=1024, win_length=256, hop_length=128, return_db=True, onesided=True)

# Compute STFT of an audio signal
y = stft(x)
x: mx.array [batch, length]
y: mx.array [batch, n_fft // 2, size of fold] if one_sided else [batch, n_fft, size of fold]
where size of fold = 1 + length // hop_length

Arguments

n_fft: Number of Fourier transform points.
win_length: Length of the STFT window.
hop_length: Number of audio samples between adjacent STFT columns.
window: Type of window function to apply (default is "hann").
onesided: Whether to return only the non-redundant part of the spectrum (default is False).
return_db: Whether to return the result in decibels (default is False).

Example

The STFT is illustrated in the picture below using the NOIZEUS dataset's sp09.wav file.

One-Sided STFT

one-sided stft

Dual-Sided STFT

dual-sided stft

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

mlx_stft-0.1.1.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

mlx_stft-0.1.1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file mlx_stft-0.1.1.tar.gz.

File metadata

  • Download URL: mlx_stft-0.1.1.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for mlx_stft-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a2c9e6c2949b4199cf3cbda311476adf00bb10e89db0f6d94b3f916fc44e45e6
MD5 8720cf38c9b0b29a4ba9a0f7cfd5bc9b
BLAKE2b-256 32eeb2ab5f090e60c288f075cd5587ff6c494e4aaaccc14a62fab5e935140f19

See more details on using hashes here.

File details

Details for the file mlx_stft-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: mlx_stft-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for mlx_stft-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2c798d4a59c14ad135e741609573e3208a1f1dc63248935cd8dafe7c91366d34
MD5 d568c99a8fccaacb188e2291446dafb2
BLAKE2b-256 dbfb55859ded1ef90a336ba44ace3ef4762f3e37aaa4d686d40e1c0304e20889

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page