A high-performance Digital Signal Processing (DSP) and Fourier analysis library for Swift.
AuraSignal bridges the gap between Apple's low-level, hardware-accelerated Accelerate (vDSP) framework and a modern, math-friendly Swift API. It is designed for applications requiring real-time audio processing, seismic/vibration analysis, and complex frequency-domain mathematics.
- Hardware-Accelerated Transforms: O(N log N) Forward and Inverse Fast Fourier Transforms (FFT/IFFT).
- Advanced Convolution: Fast frequency-domain convolution and cross-correlation using the Convolution Theorem.
- Spectral Analytics: Extract magnitudes, phases, and Power Spectral Density (PSD).
- Time-Frequency Analysis: Short-Time Fourier Transform (STFT) for spectrogram generation.
- Acoustic Math: Direct conversions to Decibels (dB) for amplitude and power.
- Windowing Functions: Hann, Hamming, and Blackman windows to minimize spectral leakage.
Add AuraSignal via Swift Package Manager (SPM) in your Package.swift:
dependencies: [
.package(url: "[https://github.com/Bacemoglu/AuraSignal.git](https://github.com/Bacemoglu/AuraSignal.git)", from: "1.0.0")
]Ideal for analyzing accelerometer or IoT sensor data to detect specific vibration frequencies.
Before applying FFT, we typically apply a windowing function (like Hann) to reduce spectral leakage at the edges of the signal block. The Hann window is defined as:
The signal is then transformed using the Discrete Fourier Transform (DFT) (efficiently calculated via FFT):
import AuraSignal
import ComplexModule
let sampleRate: Double = 100.0 // 100 Hz sensor sampling rate
// Assume `sensorData` is an array of raw Double values from an accelerometer
let sensorData: [Double] = [/* ... */]
// 1. Apply a windowing function (Hann) to reduce spectral leakage
let windowedSignal = sensorData.applyingHannWindow()
// 2. Perform Fast Fourier Transform (vDSP accelerated)
let complexSpectrum = AuraFourier.fft(windowedSignal)
// 3. Extract magnitudes and map them to actual frequencies
// Magnitude = sqrt(real^2 + imag^2)
let magnitudes = AuraFourier.magnitudes(complexSpectrum)
let frequencies = AuraFourier.frequencies(fftLength: complexSpectrum.count, sampleRate: sampleRate)
// Find the dominant frequency peak
if let maxMagnitude = magnitudes.max(),
let index = magnitudes.firstIndex(of: maxMagnitude) {
let dominantHz = frequencies[index]
print("Dominant Vibration Frequency: \(dominantHz) Hz")
}Useful for hearing safety monitoring or acoustic applications. Audio amplitudes are typically converted to the logarithmic Decibel (dB) scale to match human perception.
For amplitude (sound pressure level), the formula is:
import AuraSignal
// Assume `audioBuffer` contains raw PCM audio samples (linear amplitudes between -1.0 and 1.0)
let audioBuffer: [Double] = [/* ... */]
// Convert linear amplitude to Decibels (dB) using standard reference (1.0 for full scale)
let decibelLevels = audioBuffer.toDecibels(reference: 1.0)
// Check against a safety threshold (e.g., 85 dB)
let isDangerous = decibelLevels.contains { $0 > 85.0 }
if isDangerous {
print("Warning: Harmful noise levels detected!")
}Applying a custom impulse response (filter) to a large signal. Time-domain convolution is slow ($O(N^2)$).
AuraSignal utilizes the Convolution Theorem to perform this operation in the frequency domain, achieving
(Convolution in time domain equals point-wise multiplication in frequency domain).
import AuraSignal
let rawSignal: [Double] = [/* Large dataset */]
// A simple moving average filter kernel
let lowPassKernel: [Double] = [0.2, 0.2, 0.2, 0.2, 0.2]
// Perform extremely fast convolution using vDSP FFT under the hood
let filteredSignal = rawSignal.fftConvolved(with: lowPassKernel)- iOS 15.0+ / macOS 12.0+
- Swift 6.0+
- Swift Numerics (ComplexModule)