Skip to content

acemoglu/AuraSignal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AuraSignal

AuraSigIcon

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.

Features

  • 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.

Installation

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")
]

Usage Examples & Mathematical Background

1. Finding Dominant Frequencies (Vibration / Sensor Data)

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:

$$w(n)=0.5\left(1-\cos\left(\frac{2\pi n}{N-1}\right)\right)$$

The signal is then transformed using the Discrete Fourier Transform (DFT) (efficiently calculated via FFT):

$$X_k=\sum_{n=0}^{N-1}x_n\cdot e^{-i2\pi kn/N}$$

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")
}

2. Audio Processing & Decibels

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:

$$dB=20\log_{10}\left(\frac{A}{A_{ref}}\right)$$

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!")
}

3. High-Speed Convolution (Signal Filtering)

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 $O(N \log N)$ speed:

$$\mathcal{F}{f*g}=\mathcal{F}{f}\cdot\mathcal{F}{g}$$

(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)

Requirements

About

A high-performance signal processing and Fourier analysis library for Swift, powered by Apple's Accelerate framework.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages