fftw
| Kind | ffi-c |
|---|---|
| Capabilities | ffi |
| Categories | math ffi |
| Keywords | fftw fft fourier signal-processing dsp |
FFTW fast Fourier transform library bindings for Kit
Files
| File | Description |
|---|---|
.editorconfig | Editor formatting configuration |
.gitignore | Git ignore rules for build artifacts and dependencies |
.tool-versions | asdf tool versions (Zig, Kit) |
LICENSE | MIT license file |
README.md | This file |
c/kit_fftw.c | C FFI wrapper |
c/kit_fftw.h | C header for FFI wrapper |
examples/basic.kit | Basic usage example |
kit.toml | Package manifest with metadata and dependencies |
src/fftw.kit | Kit FFTW - Fast Fourier Transform library bindings |
tests/fftw.test.kit | Tests for fftw |
Dependencies
No Kit package dependencies.
Installation
kit add gitlab.com/kit-lang/packages/kit-fftw.gitSystem Requirements
| Platform | Command |
|---|---|
| macOS | brew install fftw |
| Ubuntu | sudo apt install libfftw3-dev |
| Fedora | sudo 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)
mainDevelopment
Running Examples
Run examples with the interpreter:
kit run examples/basic.kitCompile examples to a native binary:
kit build examples/basic.kit && ./basicRunning Tests
Run the test suite:
kit testRun the test suite with coverage:
kit test --coverageRunning kit dev
Run the standard development workflow (format, check, test):
kit devThis will:
- Format and check source files in
src/ - Run tests in
tests/with coverage
Generating Documentation
Generate API documentation from doc comments:
kit docNote: Kit sources with doc comments (##) will generate HTML documents in docs/*.html
Cleaning Build Artifacts
Remove generated files, caches, and build artifacts:
kit task cleanNote: Defined in kit.toml.
Local Installation
To install this package locally for development:
kit installThis 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