Skip to main content

build_fft_twiddles

Function build_fft_twiddles 

Source
pub fn build_fft_twiddles<const N: usize, const HALF: usize>() -> ([i16; HALF], [i16; HALF])
Expand description

The Q1.15 twiddle tables of a QFft1D<N, HALF>: cos(-2πk/N) and sin(-2πk/N) for k in 0..N/2, times 32768, rounded to nearest (ties away from zero) and clamped to i16 (C++ buildQFFTTwiddles). Returns (cos, sin).

1.0 (k = 0) clamps to 32767, the convention of TFLite and CMSIS-DSP; -1.0 (the sine at k = N/4) is exactly -32768. cos and sin come from the system math library, as in the C++, so the tables match the C++ ones on the same platform. The same checks on N and HALF as the layer’s apply.

use tinymind::int8::QFft1D;
use tinymind::int8::calibration::build_fft_twiddles;

let (cos, sin) = build_fft_twiddles::<8, 4>();
assert_eq!(cos, [32767, 23170, 0, -23170]);
assert_eq!(sin, [0, -23170, -32768, -23170]);
let fft: QFft1D<'_, 8, 4> = QFft1D { twiddle_cos: &cos, twiddle_sin: &sin };