kfr

Fast, modern C++ DSP framework, FFT, Sample Rate Conversion, FIR/IIR/Biquad Filters (SSE, AVX, AVX-512, ARM NEON)
Log | Files | Refs | README

commit 90469c942a605d81fa40ccc67d145990f89a4d17
parent bd01dfab4e1354ec6c6c5ed5a548b68fd7ccf8d2
Author: Stephen Larew <stephen@slarew.net>
Date:   Thu, 20 Feb 2020 12:30:52 -0800

add cabssqr

Diffstat:
Minclude/kfr/math/complex_math.hpp | 33+++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+), 0 deletions(-)

diff --git a/include/kfr/math/complex_math.hpp b/include/kfr/math/complex_math.hpp @@ -64,6 +64,12 @@ KFR_INTRINSIC vec<complex<T>, N> ccosh(const vec<complex<T>, N>& x) } template <typename T, size_t N> +KFR_INTRINSIC vec<T, N> cabssqr(const vec<complex<T>, N>& x) +{ + const vec<T, N* 2> xx = sqr(cdecom(x)); + return even(xx) + odd(xx); +} +template <typename T, size_t N> KFR_INTRINSIC vec<T, N> cabs(const vec<complex<T>, N>& x) { const vec<T, N* 2> xx = sqr(cdecom(x)); @@ -158,6 +164,11 @@ KFR_HANDLE_SCALAR(csqrt) KFR_HANDLE_SCALAR(csqr) template <typename T, size_t N> +KFR_INTRINSIC vec<T, N> cabssqr(const vec<T, N>& a) +{ + return to_scalar(intrinsics::cabssqr(static_cast<vec<complex<T>, N>>(a))); +} +template <typename T, size_t N> KFR_INTRINSIC vec<T, N> cabs(const vec<T, N>& a) { return to_scalar(intrinsics::cabs(static_cast<vec<complex<T>, N>>(a))); @@ -168,6 +179,12 @@ KFR_INTRINSIC vec<T, N> carg(const vec<T, N>& a) return to_scalar(intrinsics::carg(static_cast<vec<complex<T>, N>>(a))); } template <typename T1> +KFR_INTRINSIC realtype<T1> cabssqr(const T1& a) +{ + using vecout = vec1<T1>; + return to_scalar(intrinsics::cabssqr(vecout(a))); +} +template <typename T1> KFR_INTRINSIC realtype<T1> cabs(const T1& a) { using vecout = vec1<T1>; @@ -185,6 +202,7 @@ KFR_I_FN(csin) KFR_I_FN(csinh) KFR_I_FN(ccos) KFR_I_FN(ccosh) +KFR_I_FN(cabssqr) KFR_I_FN(cabs) KFR_I_FN(carg) KFR_I_FN(clog) @@ -254,6 +272,21 @@ KFR_FUNCTION internal::expression_function<fn::ccosh, E1> ccosh(E1&& x) return { fn::ccosh(), std::forward<E1>(x) }; } +/// @brief Returns the squared absolute value (magnitude squared) of the complex number x +template <typename T1, KFR_ENABLE_IF(is_numeric<T1>)> +KFR_FUNCTION realtype<T1> cabssqr(const T1& x) +{ + return intrinsics::cabssqr(x); +} + +/// @brief Returns template expression that returns the squared absolute value (magnitude squared) of the +/// complex number x +template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>)> +KFR_FUNCTION internal::expression_function<fn::cabssqr, E1> cabssqr(E1&& x) +{ + return { fn::cabssqr(), std::forward<E1>(x) }; +} + /// @brief Returns the absolute value (magnitude) of the complex number x template <typename T1, KFR_ENABLE_IF(is_numeric<T1>)> KFR_FUNCTION realtype<T1> cabs(const T1& x)