NumCpp  2.9.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
kaiser.hpp
Go to the documentation of this file.
1 #pragma once
29 
30 #include <cmath>
31 
32 #if defined(__cpp_lib_math_special_functions) || !defined(NUMCPP_NO_USE_BOOST)
33 
34 #include "NumCpp/NdArray.hpp"
36 #include "NumCpp/Utils/sqr.hpp"
37 
38 namespace nc
39 {
40  //============================================================================
41  // Method Description:
50  inline NdArray<double> kaiser(int32 m, double beta)
51  {
52  if (m < 1)
53  {
54  return {};
55  }
56 
57  const auto mDouble = static_cast<double>(m);
58  const auto mMinus1 = mDouble - 1.;
59  const auto mMinus1Over2 = mMinus1 / 2.;
60  const auto mMinus1Squared = utils::sqr(mMinus1);
61  const auto i0Beta = special::bessel_in(0, beta);
62 
63  NdArray<double> result(1, m);
64  int32 i = 0;
65  for (auto n : linspace(-mMinus1Over2, mMinus1Over2, m, true))
66  {
67  auto value = beta * std::sqrt(1. - (4. * utils::sqr(n)) / mMinus1Squared);
68  result[i++] = special::bessel_in(0, value) / i0Beta;
69  }
70 
71  return result;
72  }
73 } // namespace nc
74 
75 #endif // #if defined(__cpp_lib_math_special_functions) || !defined(NUMCPP_NO_USE_BOOST)
dtype beta(GeneratorType &generator, dtype inAlpha, dtype inBeta)
Definition: Random/beta.hpp:63
auto bessel_in(dtype1 inV, dtype2 inX)
Definition: bessel_in.hpp:59
constexpr dtype sqr(dtype inValue) noexcept
Definition: sqr.hpp:44
Definition: Coordinate.hpp:45
NdArray< double > kaiser(int32 m, double beta)
Definition: kaiser.hpp:50
NdArray< dtype > linspace(dtype inStart, dtype inStop, uint32 inNum=50, bool endPoint=true)
Definition: linspace.hpp:60
std::int32_t int32
Definition: Types.hpp:36
auto sqrt(dtype inValue) noexcept
Definition: sqrt.hpp:48