Skip to content

Conversation

@singalsu
Copy link
Collaborator

No description provided.

@singalsu singalsu force-pushed the add_complex_polar_convert branch from bce13a4 to 2f173e0 Compare January 27, 2026 12:15
Copy link
Member

@lgirdwood lgirdwood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM so far.

@singalsu singalsu marked this pull request as ready for review January 28, 2026 07:55
Copilot AI review requested due to automatic review settings January 28, 2026 07:55
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for converting complex numbers between rectangular (real, imaginary) and polar (magnitude, angle) formats in the SOF audio processing framework. The implementation includes new conversion functions for 32-bit complex numbers, comprehensive unit tests, and integration with the STFT processing component.

Changes:

  • Added complex number conversion functions (sofm_icomplex32_to_polar and sofm_ipolar32_to_complex)
  • Implemented 32-bit square root function (sofm_sqrt_int32) to support magnitude calculations
  • Reorganized complex number type definitions into dedicated header files (icomplex16.h, icomplex32.h)

Reviewed changes

Copilot reviewed 34 out of 34 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/math/complex.c New implementation of polar/complex conversion functions
src/math/sqrt_int32.c New 32-bit square root function for magnitude calculations
src/include/sof/math/icomplex32.h Extracted and expanded 32-bit complex number types and operations
src/include/sof/math/icomplex16.h Extracted 16-bit complex number types and helper functions
src/include/sof/math/sqrt.h Added sofm_sqrt_int32 declaration and updated function naming
src/audio/stft_process/stft_process_common.c Added polar format conversion to STFT processing
test/ztest/unit/math/basic/complex/test_complex_polar.c Comprehensive unit tests for conversion functions
Various FFT files Updated includes to use new header organization

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@singalsu singalsu force-pushed the add_complex_polar_convert branch from 2f173e0 to 8d72029 Compare January 28, 2026 11:05
@singalsu singalsu requested a review from Copilot January 28, 2026 11:06
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 34 out of 34 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

/**
* @brief Test complex to polar conversion function
*
* This test validates the icomplex32_to_polar(() function against
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected typo - extra opening parenthesis in function name reference.

Suggested change
* This test validates the icomplex32_to_polar(() function against
* This test validates the icomplex32_to_polar() function against

Copilot uses AI. Check for mistakes.
* @brief Test complex to polar conversion function
*
* This test validates the icomplex32_to_polar(() function against
* Octave-generated reference values. The test includes 1000
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment ends mid-sentence with "The test includes 1000" but doesn't specify what 1000 refers to. Complete the sentence to indicate it tests 1000 data points or test cases.

Suggested change
* Octave-generated reference values. The test includes 1000
* Octave-generated reference values. The test includes 1000 data points.

Copilot uses AI. Check for mistakes.
uint16_t sqrt_int16(uint16_t u);
#endif
/**
* sqrt_int16() - Calculate 16-bit fractional square root function.
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation header still refers to the old function name "sqrt_int16()" but the actual function has been renamed to "sofm_sqrt_int16()". Update the documentation to match the new function name.

Suggested change
* sqrt_int16() - Calculate 16-bit fractional square root function.
* sofm_sqrt_int16() - Calculate 16-bit fractional square root function.

Copilot uses AI. Check for mistakes.
The rename is done to avoid possible conflict with other math
libraries. The change is done to prepare add of 32 bit square root
function.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
This patch adds a higher precision 32-bit fractional integer
square root function to SOF math library. The algorithm uses
a lookup table for initial value and two iterations with
Newton-Raphson method to improve the accuracy. Both input and
output format is Q2.30. The format was chosen to match complex
to polar conversions numbers range for Q1.31 complex values.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
This patch helps with more generic use of complex numbers not
directly related to the FFTs domain. It prepares to add polar
complex numbers format that is commonly used in frequency domain
signal processing.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
This patch adds functions sofm_icomplex32_to_polar() and
sofm_ipolar32_to_complex(). In polar format the Q1.31
(real, imag) numbers pair is converted to (magnitude, angle).
The magnitude is Q2.30 format and angle in -pi to +pi radians
in Q3.29 format.

The conversion to polar and back loses some quality so there
currently is no support for icomplex16.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
The new ztest cases test_icomplex32_to_polar and
ipolar32_to_complex test the conversion functions with a
pre-calculated -1,+1 box saturated (re, im) spiral shape with
1000 points.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
This patch adds to stft_process component conversion to polar
(magnitude, angle) format for first FFT half from DC to Nyquist
frequency. The polar format is converted back to (real, imaginary)
complex and upper FFT half symmetry is applied. The magnitude domain
is commonly used for signal processing in frequency domain.

This change when enabled in Kconfig change increases load in MTL
platform from 72 MCPS to 202 MCPS with 1024 size FFT and hop of
256. Currently the build option STFT_PROCESS_MAGNITUDE_PHASE is
not set.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
@singalsu singalsu force-pushed the add_complex_polar_convert branch from 8d72029 to fe02408 Compare January 28, 2026 11:15
@singalsu singalsu requested a review from Copilot January 28, 2026 11:16
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 34 out of 34 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


#include <stdint.h>

uint16_t sqrt_int16(uint16_t u);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't be better to let a conflict to manifest itself (multiple definition error) so that we are aware of the redundant functionality?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, we are already aware of some feature duplication in C/maths libraries.

The C/maths lib versions are non xtensa optimized and always max precision for type. i.e. we use a different name as we only need to perform maths effort to the quality desired for the audio format (as any extra effort would be wasted MCPS).


#include <stdint.h>

uint16_t sqrt_int16(uint16_t u);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, we are already aware of some feature duplication in C/maths libraries.

The C/maths lib versions are non xtensa optimized and always max precision for type. i.e. we use a different name as we only need to perform maths effort to the quality desired for the audio format (as any extra effort would be wasted MCPS).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants