A collection of Fast Fourier Transform (FFT) implementations across six programming languages: Python, C++, Java, JavaScript, TypeScript, and Rust. Each implementation uses only standard library functions and includes comprehensive test suites with performance benchmarks.
- Overview
- Quick Start with Codespaces β‘
- Features
- Project Structure
- Installation
- Running Tests
- Language-Specific Details
- Performance Comparison
- Algorithm
- CI/CD
- Contributing
- License
This project implements the Cooley-Tukey FFT algorithmβa divide-and-conquer algorithm that computes the Discrete Fourier Transform (DFT) in O(N log N) time. Each language implementation:
- Uses only standard library (no external dependencies for core FFT)
- Includes three comprehensive tests:
- Correctness Test: Validates FFT output against known values
- Edge Cases Test: Tests empty inputs, single elements, power-of-2 and non-power-of-2 lengths
- Performance Benchmark: Measures execution time for various input sizes
- Automatically pads inputs to the next power of 2
- Produces executable artifacts
Want to start coding immediately without any setup? Use GitHub Codespaces!
- Click the "Code" button β "Codespaces" tab β "Create codespace"
- Wait 3-5 minutes for automatic setup
- Start debugging with one click (press
F5)
Everything is pre-configured: All languages, dependencies, debugging, and testing ready to go!
π See QUICKSTART.md for a detailed walkthrough with screenshots.
- π Multi-language: Six complete implementations
- π Performance benchmarks: Compare execution times across languages
- β Comprehensive testing: Three test categories for each language
- π§ Standard library only: No external dependencies for FFT computation
- π CI/CD ready: GitHub Actions workflow included
- π Automatic padding: Handles non-power-of-2 input sizes
- π± Android App: Real-time FFT visualizer with multi-language benchmarking
- βοΈ Codespaces ready: One-click development environment with debugging pre-configured
FFT/
βββ python/ # Python implementation
β βββ fft.py
β βββ test_fft.py
β βββ README.md
βββ cpp/ # C++ implementation
β βββ fft.h
β βββ fft_impl.cpp
β βββ fft.cpp
β βββ test_fft.cpp
β βββ Makefile
β βββ README.md
βββ java/ # Java implementation
β βββ FFT.java
β βββ TestFFT.java
β βββ README.md
βββ javascript/ # JavaScript implementation
β βββ fft.js
β βββ test_fft.js
β βββ package.json
β βββ README.md
βββ typescript/ # TypeScript implementation
β βββ fft.ts
β βββ test_fft.ts
β βββ package.json
β βββ tsconfig.json
β βββ README.md
βββ rust/ # Rust implementation
β βββ src/
β β βββ lib.rs
β β βββ main.rs
β βββ Cargo.toml
β βββ README.md
βββ android/ # Android FFT Visualizer App π±
β βββ app/
β β βββ src/main/
β β β βββ java/com/flaccidfacade/fftvisualizer/
β β β βββ cpp/ # JNI wrapper for C++ FFT
β β β βββ res/ # Android resources
β β βββ build.gradle.kts
β βββ build.gradle.kts
β βββ README.md
β βββ BUILD.md
β βββ ARCHITECTURE.md
βββ .github/
β βββ workflows/
β βββ ci.yml # CI/CD configuration
βββ run_tests.sh # Unified test runner
βββ README.md
Get started instantly with a pre-configured development environment:
- Click the green "Code" button above
- Select the "Codespaces" tab
- Click "Create codespace on main"
That's it! In a few minutes, you'll have a fully configured environment with all dependencies installed and ready to debug with one click. See DEVCONTAINER.md for details.
Make sure you have the following installed:
- Python 3.12+
- C++ compiler (g++ with C++11 support)
- Java 17+ (JDK)
- Node.js 20+ (for JavaScript and TypeScript)
- Rust 1.56+ (with cargo)
git clone https://github.com/FlaccidFacade/FFT.git
cd FFTUse the unified test runner to run tests for all languages:
./run_tests.shcd python
python3 test_fft.pycd cpp
make
./test_fftcd java
javac FFT.java TestFFT.java
java -ea TestFFTcd javascript
node test_fft.jscd typescript
npm install
npm testcd rust
cargo test --release
# or run with output
cargo run --releaseSee the Android README for detailed instructions on building and running the Android FFT Visualizer app.
Quick start:
cd android
./gradlew assembleDebug
./gradlew installDebugOr open the android/ directory in Android Studio.
- Standard library:
cmathfor complex numbers - Type hints: Fully typed
- Requirements: None (standard library only)
- Standard: C++11
- Libraries:
<complex>,<vector>,<cmath> - Build system: Makefile
- Version: Java 8+
- Features: Custom Complex class, no external dependencies
- Assertions: Enabled with
-eaflag
- Standard: ES2020
- Runtime: Node.js 10+
- Module system: CommonJS
- Version: TypeScript 5.0+
- Target: ES2020
- Type safety: Strict mode enabled
- Edition: 2021
- Features: Zero-cost abstractions, memory safety
- Build: Cargo with release optimizations
- Language: Kotlin
- SDK: Android 34+ (Android 14+)
- NDK: C++ FFT via JNI
- Features: Real-time audio capture, live FFT visualization, performance benchmarking
- See: android/README.md for details
Performance benchmarks are run automatically for 4096 samples. Here are typical results:
| Language | Time (ms) | Relative Speed |
|---|---|---|
| Rust | 0.91 | 1.00x (fastest) |
| C++ | 1.00 | 1.09x |
| Java | 2.63 | 2.88x |
| JavaScript | 4.11 | 4.49x |
| TypeScript | 4.45 | 4.86x |
| Python | 10.99 | 12.02x |
Note: Actual performance varies by hardware and system load.
# Run comprehensive performance comparison
./benchmark.shEach implementation includes performance benchmarks for input sizes:
- 64 samples
- 256 samples
- 1024 samples
- 4096 samples
All implementations use the Cooley-Tukey FFT algorithm:
- Divide: Split input into even and odd indexed elements
- Conquer: Recursively compute FFT of both halves
- Combine: Merge results using twiddle factors
Time Complexity: O(N log N)
Space Complexity: O(N)
function FFT(x):
N = length(x)
if N β€ 1:
return x
even = FFT(x[0, 2, 4, ...])
odd = FFT(x[1, 3, 5, ...])
result = array of size N
for k from 0 to N/2 - 1:
t = exp(-2Οi * k/N) * odd[k]
result[k] = even[k] + t
result[k + N/2] = even[k] - t
return result
The project uses GitHub Actions for continuous integration:
- Automated testing: All language tests run on each push
- Code coverage: Multi-language coverage reports uploaded to Codecov
- Performance benchmarking: Compares execution times across languages
- Multiple platforms: Tested on Ubuntu (can be extended to Windows/macOS)
- Artifact upload: Performance results saved for each run
- Auto branch delete: Merged PR branches are automatically deleted to keep the repository clean
See .github/workflows/ci.yml and .github/workflows/auto-delete-branch.yml for details.
The project uses Codecov to track code coverage across all languages:
- Python:
coverage.pygenerates XML reports - C++:
gcovandlcovgenerate coverage data - Java: JaCoCo generates XML reports
- JavaScript:
c8generates lcov reports - TypeScript:
c8generates lcov reports - Rust:
cargo-llvm-covgenerates lcov reports
Coverage reports are automatically generated and uploaded on every CI run. View detailed coverage reports and trends on Codecov.
To generate coverage locally:
# Python
cd python && pip install coverage && coverage run test_fft.py && coverage report
# C++
cd cpp && make coverage
# Java
cd java && ./build.sh # Downloads JaCoCo if needed
# JavaScript
cd javascript && npm run coverage
# TypeScript
cd typescript && npm run coverage
# Rust
cd rust && cargo install cargo-llvm-cov && cargo llvm-covThe README includes badges for:
- CI/CD status
- Code coverage percentage
- Language versions
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new features
- Ensure all tests pass
- Submit a pull request
This repository includes a comprehensive Android application that:
- Captures live audio from the device microphone
- Runs FFT analysis using multiple implementations (C++, Java)
- Displays real-time visualizations in a grid layout
- Benchmarks processing speed, accuracy, and divergence
- Exports performance metrics to CSV
- Provides interactive charts for analysis
Target Devices: Samsung Galaxy S25 Ultra, Samsung Tab S10+, and any Android 14+ device
Learn More: See android/README.md, android/BUILD.md, and android/ARCHITECTURE.md
MIT License - feel free to use this code for learning or in your projects.
- Cooley-Tukey FFT algorithm (1965)
- Standard library maintainers of all languages
- Open source community