File 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.
n must be a power of 2 (e.g., 8, 16, 32, 64, 128, 256). Max supported size is 256.
Parameters:
realArray of real parts (size n).imagArray of imaginary parts (size n).nSize 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:
magMagnitude array (size n_bins).n_binsNumber of bins (typically n/2 + 1).sample_rate_hzSampling rate in Hz (Q16.16).peaksOutput peak array.max_peaksCapacity of peaks array.num_peaks_foundOutput 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:
realReal part array (size n).imagImaginary part array (size n).magOutput magnitude array (size n/2 + 1).nFFT 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:
magMagnitude array (size n_bins).n_binsNumber of bins.fundamental_binBin index of the fundamental frequency.max_harmonicsNumber of harmonics to sum (e.g. 5).thd_pctOutput 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)).
Parameters:
outOutput buffer of size n.nWindow 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)).
Parameters:
outOutput buffer of size n.nWindow 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))).
Parameters:
outOutput buffer of size n.nWindow 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