FftSharp Documentation

repository·main·Indexed 18 days ago

https://github.com/swharden/fftsharp

A dependency-free .NET Standard library for Fast Fourier Transform (FFT) tools, designed for signal processing tasks including spectral analysis, filtering, and windowing. It provides routines for Complex and Real Discrete Fourier Transforms, as well as Discrete Cosine and Sine Transforms. The library includes support for window functions (Hanning, Hamming, Blackman, Tukey), frequency filtering (LowPass, HighPass, BandPass, BandStop), and power spectral density calculations.

Tokens
4.6K
Snippets
11
Records
25
Agent score
64%

What's inside FftSharp

  1. Overview of OOURA FFT Package

    main
    The OOURA FFT package is a general-purpose library for calculating Discrete Fourier, Cosine, and Sine Transforms of 1-dimensional sequences with a length of $2^N$. It is available in both C and Fortran implementations and offers several versions optimized for different hardware architectures and performance requirements.
  2. Explore external FFT/IFFT implementations

    main
    This repository provides a curated list of various FFT (Fast Fourier Transform) and IFFT (Inverse Fast Fourier Transform) implementations across different programming languages. Developers can use these as references, study their optimizations, or integrate them into their own projects depending on their licensing and performance requirements.
  3. How ddst (Discrete Sine Transform) works

    main

    The ddst routine implements a discrete sine transform by appending a butterfly operation to rdft.

    In a backward transform, it processes an input array a[] to create an intermediate array r[], calls rdft of length $n$, and then maps the results $A[k]$ to the final sine coefficients $S[k]$ using the following relationship:

    • $S[2*k] = ext{Re}(A[k] * (1+i))$
    • $S[2*k-1] = - ext{Im}(A[k] * (1+i))$
  4. How windowing works and why to use it

    main

    Windowing involves multiplying a waveform by a bell-shaped curve before performing an FFT. This process improves the frequency resolution and signal-to-noise ratio at lower frequencies by reducing spectral leakage.

    In FftSharp, you can use window functions in two ways:

    1. window.ApplyInPlace(signal): Modifies the original array.
    2. window.Apply(signal): Returns a new array containing the windowed signal.

    Common window functions include Hanning, Hamming, Blackman, and Tukey.

    double[] signal = FftSharp.SampleData.SampleAudio1();
    
    var window = new FftSharp.Windows.Hanning();
    double[] windowed = window.Apply(signal);
  5. How dfct and dfst work

    main

    These routines are used to split transforms into half-length components:

    • dfct: Splits a Cosine Transform into dfct and ddct of half length. It uses ddct recursively. To maintain in-place operation, data in fft*g_h.* versions are sorted in bit-reversal order.
    • dfst: Splits a Sine Transform into dfst and ddst of half length. It uses ddst recursively. To maintain in-place operation, data in fft*g_h.* versions are sorted in bit-reversal order.
  6. How rdft (Real Discrete Fourier Transform) works

    main

    The rdft routine implements a real transform by appending a butterfly operation to a cdft call.

    In a forward transform, it takes an array a[] and produces an array x[] where x[j] = a[2*j] + i*a[2*j+1]. It then calls cdft of length $n/2$. The final results $A[k]$ are derived from the cdft output $X[k]$ using complex conjugates and specific weighting factors to account for the real-valued input symmetry.

  7. How ddct (Discrete Cosine Transform) works

    main

    The ddct routine implements a discrete cosine transform by appending a butterfly operation to rdft.

    In a backward transform, it processes an input array a[] to create an intermediate array r[] (using real and imaginary parts of the input), calls rdft of length $n$, and then maps the results $A[k]$ to the final cosine coefficients $C[k]$ using the following relationship:

    • $C[2*k] = ext{Re}(A[k] * (1-i))$
    • $C[2*k-1] = - ext{Im}(A[k] * (1-i))$
  8. Choose the appropriate OOURA FFT implementation

    main

    The package provides several file variations depending on your performance and memory needs:

    • fft4g*.*: Optimized for most machines (uses radix 4,2).
    • fft8g*.*: Fast on UltraSPARC architectures (uses radix 8,4,2).
    • fftsg*.*: Optimized for machines with multi-level caches (L1, L2, etc.) using a Split-Radix algorithm.
    • fft*g_h.c (Simple Versions): These versions use no work area (no extra memory allocation), making them suitable for memory-constrained environments, though they may be slower than the fast versions.
    • Fast Versions (fft*g.*): These use work areas to achieve higher performance.
  9. Choose the appropriate FFT implementation

    main

    FftSharp provides several versions of FFT (Fast Fourier/Cosine/Sine Transform) optimized for different hardware and performance requirements. All implementations calculate transforms for 1-dimensional sequences of length $2^N$.

    Fast Versions (Use work areas for speed)

    • fft4g*.*: Optimized for most general-purpose machines (uses radix 4,2).
    • fft8g*.*: Optimized for UltraSPARC architectures (uses radix 8,4,2).
    • fftsg*.*: Optimized for machines with multi-level caches (L1, L2, etc.) using a Split-Radix recursive algorithm.

    Simple Versions (No work area required)

    • fft*g_h.c: These versions use no additional work area but are generally slower than the fast versions. They are available in C for radix 4,2, radix 8,4,2, and Split-Radix variants.
  10. How cdft (Complex Discrete Fourier Transform) works

    main

    The implementation method for cdft depends on the package version used:

    • fft4g*.* and fft8g*.*: Uses an in-place, radix $2^M$, Sande-Tukey (decimation in frequency) method. The butterfly loop index is in bit-reverse order to maintain continuous memory access.
    • fftsg*.*: Uses an in-place, Split-Radix, recursive fast algorithm.
  11. How the FFT routines work

    main

    The implementation details vary by routine and chosen package:

    cdft (Complex DFT)

    • fft4g*.*, fft8g*.*: Uses an in-place, radix $2^M$, Sande-Tukey (decimation in frequency) method. The butterfly loop index is in bit-reverse order to maintain continuous memory access.
    • fftsg*.*: Uses an in-place, Split-Radix, recursive fast algorithm.

    rdft (Real DFT)

    Appends a butterfly operation to cdft. For a forward transform of length $n$, it constructs an array $x[j] = a[2j] + i imes a[2j+1]$ and calls cdft of length $n/2$.

    ddct (Discrete Cosine Transform)

    Appends a butterfly operation to rdft. In backward transform, it constructs an array $r[]$ based on the input $a[]$ and calls rdft of length $n$.

    ddst (Discrete Sine Transform)

    Appends a butterfly operation to rdft. In backward transform, it constructs an array $r[]$ based on the input $a[]$ and calls rdft of length $n$.

    dfct and dfst (Symmetric/Anti-symmetric Transforms)

    These routines split the transform into ddct/ddst of half length. To maintain in-place operation, data in the simple versions (fft*g_h.*) are sorted in bit-reversal order.