Skip to content

API‐Math

ZangoTech edited this page Jun 20, 2026 · 1 revision

Math

← Back to API Reference · Home

Namespace: acl::neon::math

Discrete Fourier Transform (DFT / IDFT / complex spectrum multiplication). matchTemplate also uses this API set internally.

Tier: Pro+
NEON only (there is no corresponding standalone CPP API)

DftFlags (see acl::DftFlags):

Flag Value Meaning
DFT_FORWARD 0 Forward transform (default)
DFT_INVERSE 1 Inverse transform
DFT_SCALE 2 Divide the result by N for normalization

Flags can be OR-combined, e.g. DFT_INVERSE \| DFT_SCALE.


dft1d

1D complex → complex DFT. Tier: Pro+
Channels: N/A (1-D signal)
Inplace: not supported
Types:

Template parameter Allowed types Constraint
T float
int dft1d(
    const float* srcRe, const float* srcIm,
    float* dstRe, float* dstIm,
    int n,
    int flags = acl::DFT_FORWARD);
Parameter Type Meaning Default
srcRe const float* Input real part (n elements) non-null
srcIm const float* Input imaginary part (n elements; may be nullptr for real-valued input) nullable
dstRe, dstIm float* Output real / imaginary parts (n elements each) non-null
n int Transform length > 0
flags int DFT_FORWARD / DFT_INVERSE, optionally OR'd with DFT_SCALE DFT_FORWARD

dftReal1d

1D real → complex forward DFT (output is a half-spectrum, n/2 + 1 complex coefficients, exploiting conjugate symmetry). Tier: Pro+
Channels: N/A (1-D signal)
Inplace: not supported
Types:

Template parameter Allowed types Constraint
T float
int dftReal1d(
    const float* srcImage,
    float* dstRe, float* dstIm,
    int n);
Parameter Type Meaning Default
srcImage const float* Input real-valued array (n elements) non-null
dstRe, dstIm float* Output real / imaginary parts (n/2 + 1 elements each) non-null
n int Input length even and a power of 2

idftReal1d

1D complex (CCS half-spectrum) → real inverse DFT. Symmetric to dftReal1d: input is n/2 + 1 complex coefficients, output is n real values. Tier: Pro+
Channels: N/A (1-D signal)
Inplace: not supported
Types:

Template parameter Allowed types Constraint
T float
int idftReal1d(
    const float* srcRe, const float* srcIm,
    float* dstImage,
    int n);
Parameter Type Meaning Default
srcRe, srcIm const float* Input real / imaginary parts (n/2 + 1 elements each, CCS format) non-null
dstImage float* Output real array (n elements) non-null
n int Output length even and a power of 2

dft2d

2D complex → complex DFT (row-wise + column-wise, two 1D FFTs). Tier: Pro+
Channels: 1ch
Inplace: not supported
Types:

Template parameter Allowed types Constraint
T float
int dft2d(
    const float* srcRe, const float* srcIm,
    float* dstRe, float* dstIm,
    int width, int height,
    int flags = acl::DFT_FORWARD);
Parameter Type Meaning Default
srcRe const float* Input real part (width * height, row-major) non-null
srcIm const float* Input imaginary part (same; may be nullptr for real input) nullable
dstRe, dstIm float* Output real / imaginary parts (same size) non-null
width, height int Columns / rows > 0
flags int Same as dft1d DFT_FORWARD

mulSpectrums

Per-element complex multiplication: C = A * B or C = A * conj(B). Commonly used for frequency-domain cross-correlation / convolution. Tier: Pro+
Channels: N/A (complex spectra)
Inplace: supported (aRe / aIm may equal dstRe / dstIm)
Types:

Template parameter Allowed types Constraint
T float
int mulSpectrums(
    const float* aRe, const float* aIm,
    const float* bRe, const float* bIm,
    float* cRe, float* cIm,
    int n,
    bool conjB = false);
Parameter Type Meaning Default
aRe, aIm const float* Real / imaginary parts of complex array A non-null
bRe, bIm const float* Real / imaginary parts of complex array B non-null
cRe, cIm float* Real / imaginary parts of the output product C non-null
n int Number of complex elements > 0
conjB bool true = take the conjugate of B before multiplying false

Example

int n = 1024;   // input length: even and a power of 2
std::vector<float> srcImage(n, 0.0f), re(n), im(n);
std::vector<float> back(n);

// 1) real → half-spectrum
acl::neon::math::dftReal1d(srcImage.data(), re.data(), im.data(), n);

// 2) Frequency-domain processing (example: pass-through)

// 3) half-spectrum → real restoration
acl::neon::math::idftReal1d(re.data(), im.data(), back.data(), n);

Clone this wiki locally