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. (fastgoertzel is ~75 times faster than native python)
  • 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.2.0.tar.gz (35.2 kB view details)

Uploaded Source

Built Distribution

fastgoertzel-0.2.0-cp37-abi3-win_amd64.whl (110.2 kB view details)

Uploaded CPython 3.7+ Windows x86-64

File details

Details for the file fastgoertzel-0.2.0.tar.gz.

File metadata

  • Download URL: fastgoertzel-0.2.0.tar.gz
  • Upload date:
  • Size: 35.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.7.0

File hashes

Hashes for fastgoertzel-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9e9d08afc53579a20260353d984f0ef0595e980ff2b2fb27fea362683e963c38
MD5 d72f66a4e5e1a4e82dd46581e218bc91
BLAKE2b-256 a5abc02d0318a07516a26851d1e2957bd97b0fbe847f66f9fe8117e47acf45a7

See more details on using hashes here.

File details

Details for the file fastgoertzel-0.2.0-cp37-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for fastgoertzel-0.2.0-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 0db00019fd118ada9a62a9dddc740bd3cfe9684d598d2b46aa910ed763e46828
MD5 52bc48c556d584a8aedf7ee8221a9567
BLAKE2b-256 26b8b312578a28c4d2b7f6819979693153e07ef078d7200375fa8aafc5b02578

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