Working on Swift Real/Complex Vector DSP Library

Hello! I've been working on a vector math/DSP library along the lines of Matlab/NumPy. It uses the Accelerate behind the scenes and adds Matlab type functions for DSP work like FFT and windows. It's fairly lightweight, using only typealiases for arrays and tuples for complex numbers.

This is my first package. Would anyone me some feedback?

Here is an example of the style. This is a recursive complex FFT using the Stockholm algorithm using vector operations.

public typealias Real = Double
public typealias RealArray = [Real]
public typealias Complex = (Real, Real)
public typealias ComplexArray = ([Real], [Real])
public func fftx(_ x: ComplexArray) -> ComplexArray {
    let n = length(x)
    let omega = exp(-2 * Real.pi * Real.i / Real(n))
    if rem(n, 2) == 0 {
        // Recursive divide and conquer.
        let k = vector(0 ... (n / 2 - 1))
        let w = omega ** k
        let u = fftx(slice(x, 0 ..< n - 1, 2))
        let v = w * fftx(slice(x, 1 ..< n, 2))
        return cat(u + v, u - v)
    } else {
        return x
    }
}

Matlab version

function y = fftx(x)
% FFTX Fast Finite Fourier Transform.
n = length(x);
omega = exp(-2*pi*i/n);
if rem(n,2) == 0
    % Recursive divide and conquer.
    k = (0:n/2-1)';
    w = omega.^k;
    u = fftx(x(1:2:n-1));
    v = w.*fftx(x(2:2:n));
    y = [u+v; u-v];
else
    y = x
end
2 Likes