Skip to content

File syn_fft.h

FileList > dsp > syn_fft.h

Go to the source code of this file

Fixed-point Q16.16 Fast Fourier Transform (FFT).

  • #include "../common/syn_defs.h"
  • #include "../util/syn_qmath.h"

Classes

Type Name
struct SYN_FFTPeak
FFT peak information structure.

Public Functions

Type Name
SYN_Status syn_dsp_fft (q16_t * real, q16_t * imag, uint16_t n)
Computes the in-place Radix-2 Decimation-in-Time FFT.
SYN_Status syn_fft_find_peaks (const q16_t * mag, uint16_t n_bins, q16_t sample_rate_hz, SYN_FFTPeak * peaks, uint8_t max_peaks, uint8_t * num_peaks_found)
Find dominant peaks in magnitude spectrum.
SYN_Status syn_fft_magnitude_spectrum (const q16_t * real, const q16_t * imag, q16_t * mag, uint16_t n)
Compute magnitude spectrum: mag[k] = sqrt(real[k]^2 + imag[k]^2).
SYN_Status syn_fft_thd (const q16_t * mag, uint16_t n_bins, uint16_t fundamental_bin, uint8_t max_harmonics, q16_t * thd_pct)
Compute Total Harmonic Distortion (THD) percentage.
SYN_Status syn_fft_window_blackman (q16_t * out, uint16_t n)
Generate Blackman-Harris window: w[i] = 0.42 - 0.5*cos(2*pi*i/(n-1)) + 0.08*cos(4*pi*i/(n-1)).
SYN_Status syn_fft_window_hamming (q16_t * out, uint16_t n)
Generate Hamming window: w[i] = 0.54 - 0.46 * cos(2*pi*i / (n-1)).
SYN_Status syn_fft_window_hanning (q16_t * out, uint16_t n)
Generate Hanning window: w[i] = 0.5 * (1 - cos(2*pi*i / (n-1))).

Public Functions Documentation

function syn_dsp_fft

Computes the in-place Radix-2 Decimation-in-Time FFT.

SYN_Status syn_dsp_fft (
    q16_t * real,
    q16_t * imag,
    uint16_t n
) 

n must be a power of 2 (e.g., 8, 16, 32, 64, 128, 256). Max supported size is 256.

Parameters:

  • real Array of real parts (size n).
  • imag Array of imaginary parts (size n).
  • n Size of the FFT (must be power of 2).

Returns:

SYN_OK on success, SYN_ERROR on invalid parameters (e.g. not power of 2).


function syn_fft_find_peaks

Find dominant peaks in magnitude spectrum.

SYN_Status syn_fft_find_peaks (
    const q16_t * mag,
    uint16_t n_bins,
    q16_t sample_rate_hz,
    SYN_FFTPeak * peaks,
    uint8_t max_peaks,
    uint8_t * num_peaks_found
) 

Parameters:

  • mag Magnitude array (size n_bins).
  • n_bins Number of bins (typically n/2 + 1).
  • sample_rate_hz Sampling rate in Hz (Q16.16).
  • peaks Output peak array.
  • max_peaks Capacity of peaks array.
  • num_peaks_found Output count of detected peaks.

Returns:

SYN_OK on success, SYN_INVALID_PARAM on invalid inputs.


function syn_fft_magnitude_spectrum

Compute magnitude spectrum: mag[k] = sqrt(real[k]^2 + imag[k]^2).

SYN_Status syn_fft_magnitude_spectrum (
    const q16_t * real,
    const q16_t * imag,
    q16_t * mag,
    uint16_t n
) 

Parameters:

  • real Real part array (size n).
  • imag Imaginary part array (size n).
  • mag Output magnitude array (size n/2 + 1).
  • n FFT size (number of points).

Returns:

SYN_OK on success, SYN_INVALID_PARAM on invalid inputs.


function syn_fft_thd

Compute Total Harmonic Distortion (THD) percentage.

SYN_Status syn_fft_thd (
    const q16_t * mag,
    uint16_t n_bins,
    uint16_t fundamental_bin,
    uint8_t max_harmonics,
    q16_t * thd_pct
) 

THD = sqrt(sum(V_h^2)) / V_1 * 100%

Parameters:

  • mag Magnitude array (size n_bins).
  • n_bins Number of bins.
  • fundamental_bin Bin index of the fundamental frequency.
  • max_harmonics Number of harmonics to sum (e.g. 5).
  • thd_pct Output THD percentage in Q16.16 (e.g., 5.2% = Q16_FROM_FLOAT(5.2)).

Returns:

SYN_OK on success, SYN_INVALID_PARAM on invalid inputs.


function syn_fft_window_blackman

Generate Blackman-Harris window: w[i] = 0.42 - 0.5*cos(2*pi*i/(n-1)) + 0.08*cos(4*pi*i/(n-1)).

SYN_Status syn_fft_window_blackman (
    q16_t * out,
    uint16_t n
) 

Parameters:

  • out Output buffer of size n.
  • n Window length.

Returns:

SYN_OK on success, SYN_INVALID_PARAM if NULL or n <= 1.


function syn_fft_window_hamming

Generate Hamming window: w[i] = 0.54 - 0.46 * cos(2*pi*i / (n-1)).

SYN_Status syn_fft_window_hamming (
    q16_t * out,
    uint16_t n
) 

Parameters:

  • out Output buffer of size n.
  • n Window length.

Returns:

SYN_OK on success, SYN_INVALID_PARAM if NULL or n <= 1.


function syn_fft_window_hanning

Generate Hanning window: w[i] = 0.5 * (1 - cos(2*pi*i / (n-1))).

SYN_Status syn_fft_window_hanning (
    q16_t * out,
    uint16_t n
) 

Parameters:

  • out Output buffer of size n.
  • n Window length.

Returns:

SYN_OK on success, SYN_INVALID_PARAM if NULL or n <= 1.



The documentation for this class was generated from the following file src/syntropic/dsp/syn_fft.h