tukey

module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2026 License: MIT

README

tukey

Digital Signal Processing (DSP) library for Go engineers, checked against SciPy and MATLAB.

Named after John Tukey, co-inventor of the FFT and considered by some as the father of Data Science.

Packages

The library is three packages, mirroring SciPy, each usable on its own:

Package Mirrors For
tukey/fft scipy.fft FFTs of any length
tukey/window scipy.signal.windows Window functions
tukey/dsp scipy.signal Filter design and filtering, spectral estimation, peaks, analysis

Usage

import "github.com/cxd309/tukey/fft"

spectrum, err := fft.ForwardReal(x)       // any length, O(n log n)
freqs, err := fft.RealFreq(len(x), 1/fs)  // each bin's frequency in Hz
import "github.com/cxd309/tukey/window"

w, err := window.Hann(1024, window.Periodic()) // periodic, for spectral analysis
k, err := window.Kaiser(64, 8.6)               // symmetric, for filter design
import "github.com/cxd309/tukey/dsp"

f, err := dsp.Butter(2, dsp.Lowpass(0.3))
b, a, err := f.BA()
y, err := dsp.FiltFilt(b, a, x)

// higher orders and narrow bands: second-order sections
f, err = dsp.Butter(8, dsp.Bandpass(0.30, 0.32))
sos, err := f.SOS()
y, err = dsp.SOSFiltFilt(sos, x)

// the lowest order that meets a specification, then the design
order, band, err := dsp.EllipOrd(dsp.Lowpass(0.2), dsp.Lowpass(0.25), 0.5, 60)
f, err = dsp.Ellip(order, 0.5, 60, band)

y, err = dsp.MedFilt(x, 5)          // spikes removed, steps kept
y, err = dsp.SavGolFilter(x, 21, 3) // noise smoothed, peaks kept

// the window sets the segment length
psd, err := dsp.Welch(x, fs, w)      // power spectral density, half-overlapped segments
tf, err := dsp.Spectrogram(x, fs, w) // power over time: tf.Values[segment][frequency]

Why

In brief: I wanted to port an web application from matlab into my preferred language golang, but there were no existing DSP libraries that could support what I needed.

Therefore I decided to develop this package/set of tools and make it public source so that someone might not encounter the same challenge.

I did consider "just using scipy" but I prefer the tooling and package management that comes with go.

Documentation

Each package's full documentation is on pkg.go.dev.

Conventions

  • Offline and stateless
    • The whole signal is input as a slice and a new slice is returned
    • Inputs never modified
    • All functions are safe for concurrent use
    • For block processing, FilterState and SOSFilterState take a starting state and return the final one
  • Errors and Panics
    • Error for an invalid input, this is a 'user' error
    • Panic for an internal error, this is a 'developer' error
    • Errors wrap an error sentinel so can be checked with errors.Is
  • Stability checking
    • Filtering functions assume the filter is stable
    • Same as SciPy and MATLAB

Status

tukey has been released as of v1.0.0 and the API should be considered as stable until v2 which is not currently planned. See roadmap for planned and unplanned future work.

Licence

MIT

Directories

Path Synopsis
cmd
doccomments command
Command doccomments fails on comments and docs that break the house style, so godoc, editors and GitHub show them as written.
Command doccomments fails on comments and docs that break the house style, so godoc, editors and GitHub show them as written.
tolerances command
Command tolerances reports the error tukey actually achieves against each reference-vector suite, SciPy's or MATLAB's, next to the tolerance its test enforces.
Command tolerances reports the error tukey actually achieves against each reference-vector suite, SciPy's or MATLAB's, next to the tolerance its test enforces.
Package dsp is offline signal processing for engineers: filter design, filtering, frequency response, conditioning, smoothing, peaks, alignment, spectral analysis and reductions.
Package dsp is offline signal processing for engineers: filter design, filtering, frequency response, conditioning, smoothing, peaks, alignment, spectral analysis and reductions.
Package fft computes discrete Fourier transforms of any length, in O(n log n), using only the standard library.
Package fft computes discrete Fourier transforms of any length, in O(n log n), using only the standard library.
internal
conformance
Package conformance checks tukey's public API against the reference vectors in testdata/<source>.
Package conformance checks tukey's public API against the reference vectors in testdata/<source>.
special
Package special is the special functions tukey needs: the elliptic functions for Ellip, I0 for the Kaiser windows, and exactly reduced sines and cosines of π·x.
Package special is the special functions tukey needs: the elliptic functions for Ellip, I0 for the Kaiser windows, and exactly reduced sines and cosines of π·x.
Package window computes window functions, matching scipy.signal.windows, using only the standard library.
Package window computes window functions, matching scipy.signal.windows, using only the standard library.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL