Skip to main content

Implementation of Goertzel algorithm written in Rust

Project description

fastgoertzel Logo

fastgoertzel GitHub Actions

A Python implementation of the Goertzel algorithm built using Rust for improved run time and efficiency on large datasets and loops.

To-Do:

  • Improved speed. (Significantly increased speed by using numpy arrays).
  • Implement benchmarking for speed comparison.
  • Add IIR and k-th FTT implementation of Goertzel.
  • Add support for sampling rate.

Installation

You can install using two methods:

Using pip install:

$ pip install fastgoertzel

Using maturin after cloning repository:

$ git clone git://github.com/0zean/fastgoertzel.git
$ cd fastgoertzel
$ maturin develop

Usage

import numpy as np
import pandas as pd

import fastgoertzel as G


def wave(amp, freq, phase, x):
    return amp * np.sin(2*np.pi * freq * x + phase)


x = np.arange(0, 512)
y = wave(1, 1/128, 0, x)

amp, phase = G.goertzel(y, 1/128)
print(f'Goertzel Amp: {amp:.4f}, phase: {phase:.4f}')

# Compared to max amplitude FFT output 
ft = np.fft.fft(y)
FFT = pd.DataFrame()
FFT['amp'] = np.sqrt(ft.real**2 + ft.imag**2) / (len(y) / 2)
FFT['freq'] = np.fft.fftfreq(ft.size, d=1)
FFT['phase'] = np.arctan2(ft.imag, ft.real)

max_ = FFT.iloc[FFT['amp'].idxmax()]
print(f'FFT amp: {max_["amp"]:.4f}, '
        f'phase: {max_["phase"]:.4f}, '
        f'freq: {max_["freq"]:.4f}')

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

fastgoertzel-0.1.9.tar.gz (34.4 kB view hashes)

Uploaded Source

Built Distributions

fastgoertzel-0.1.9-cp37-abi3-win_amd64.whl (112.8 kB view hashes)

Uploaded CPython 3.7+ Windows x86-64

fastgoertzel-0.1.9-cp37-abi3-win32.whl (109.3 kB view hashes)

Uploaded CPython 3.7+ Windows x86

fastgoertzel-0.1.9-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ x86-64

fastgoertzel-0.1.9-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.2 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ s390x

fastgoertzel-0.1.9-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.2 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ppc64le

fastgoertzel-0.1.9-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.1 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ARMv7l

fastgoertzel-0.1.9-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ARM64

fastgoertzel-0.1.9-cp37-abi3-manylinux_2_5_i686.manylinux1_i686.whl (1.1 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.5+ i686

fastgoertzel-0.1.9-cp37-abi3-macosx_11_0_arm64.whl (231.7 kB view hashes)

Uploaded CPython 3.7+ macOS 11.0+ ARM64

fastgoertzel-0.1.9-cp37-abi3-macosx_10_7_x86_64.whl (236.5 kB view hashes)

Uploaded CPython 3.7+ macOS 10.7+ x86-64

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