fftw

FFTW fast Fourier transform library bindings for Kit

Files

FileDescription
.editorconfigEditor formatting configuration
.gitignoreGit ignore rules for build artifacts and dependencies
.tool-versionsasdf tool versions (Zig, Kit)
LICENSEMIT license file
README.mdThis file
c/kit_fftw.cC FFI wrapper
c/kit_fftw.hC header for FFI wrapper
examples/basic.kitBasic usage example
kit.tomlPackage manifest with metadata and dependencies
src/fftw.kitKit FFTW - Fast Fourier Transform library bindings
tests/fftw.test.kitTests for fftw

Dependencies

No Kit package dependencies.

Installation

kit add gitlab.com/kit-lang/packages/kit-fftw.git

System Requirements

PlatformCommand
macOSbrew install fftw
Ubuntusudo apt install libfftw3-dev
Fedorasudo dnf install fftw-devel

Usage

import Kit.FFTW as Fftw

main = fn =>
  println ("FFTW version: " ++ Fftw.version)

  # Forward FFT magnitudes
  data = "1.0 0.0 -1.0 0.0"
  magnitudes = Fftw.forward-magnitudes data 4
  println ("Magnitudes: " ++ magnitudes)

  # Full forward FFT (complex output)
  fft-data = Fftw.forward data 4
  println ("FFT: " ++ fft-data)

  # Inverse FFT (round-trip)
  recovered = Fftw.inverse fft-data 4
  println ("Recovered: " ++ recovered)

  # Power spectrum
  power = Fftw.power-spectrum data 4
  println ("Power: " ++ power)

  # Dominant frequency bin
  signal = "1.0 0.0 -1.0 0.0 1.0 0.0 -1.0 0.0"
  match Fftw.dominant-frequency signal 8
    | Ok bin -> println ("Dominant bin: " ++ (show bin))
    | Err e -> println ("Error: " ++ e)

  # Plan-based API for repeated transforms
  match Fftw.create-forward-plan 4
    | Ok plan ->
      output = Fftw.execute plan data 4
      println ("Plan-based: " ++ output)
      Fftw.destroy-plan plan
    | Err e -> println ("Plan error: " ++ e)

main

Development

Running Examples

Run examples with the interpreter:

kit run examples/basic.kit

Compile examples to a native binary:

kit build examples/basic.kit && ./basic

Running Tests

Run the test suite:

kit test

Run the test suite with coverage:

kit test --coverage

Running kit dev

Run the standard development workflow (format, check, test):

kit dev

This will:

  1. Format and check source files in src/
  2. Run tests in tests/ with coverage

Generating Documentation

Generate API documentation from doc comments:

kit doc

Note: Kit sources with doc comments (##) will generate HTML documents in docs/*.html

Cleaning Build Artifacts

Remove generated files, caches, and build artifacts:

kit task clean

Note: Defined in kit.toml.

Local Installation

To install this package locally for development:

kit install

This installs the package to ~/.kit/packages/@kit/fftw/, making it available for import as Kit.FFTW in other projects.

License

This package is released under the MIT License - see LICENSE for details.

FFTW is released under the GPL 2.0 License. Note: The GPL license may restrict use in proprietary applications.

Exported Functions & Types

create-forward-plan

Create a forward FFT plan for the given size.

Parameters:

Returns:

Int -> Result Ptr String

create-inverse-plan

Create an inverse FFT plan for the given size.

Parameters:

Returns:

Int -> Result Ptr String

destroy-plan

Destroy an FFT plan and release its resources.

Parameters:

    Ptr -> Unit

execute

Execute an FFT plan on real input data.

Parameters:

Returns:

Ptr -> String -> Int -> String

forward-magnitudes

Compute the forward FFT magnitudes of real input data.

Parameters:

Returns:

String -> Int -> String

forward

Compute the forward FFT of real input data.

Returns interleaved real/imaginary pairs.

Parameters:

Returns:

String -> Int -> String

inverse

Compute the inverse FFT from interleaved real/imaginary data.

Parameters:

Returns:

String -> Int -> String

power-spectrum

Compute the power spectrum (squared magnitudes) of real input data.

Parameters:

Returns:

String -> Int -> String

dominant-frequency

Find the dominant frequency bin index in real input data.

Skips the DC component (index 0) and searches up to n/2.

Parameters:

Returns:

String -> Int -> Result Int String

version

Get the FFTW library version string.

String