NumCpp  2.7.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
hanning.hpp
Go to the documentation of this file.
1 #pragma once
29 
30 #include <cmath>
31 
32 #include "NumCpp/NdArray.hpp"
34 
35 namespace nc
36 {
37  //============================================================================
38  // Method Description:
49  {
50  if (m < 1)
51  {
52  return {};
53  }
54 
55  const auto mDouble = static_cast<double>(m);
56  const auto twoPiDivMMinus1 = (2.0 * constants::pi) / (mDouble - 1.0);
57 
58  NdArray<double> result(1, m);
59  int32 i = 0;
60  for (auto n : linspace(0.0, mDouble - 1.0, m, true))
61  {
62  result[i++] = 0.5 - 0.5 * std::cos(twoPiDivMMinus1 * n);
63  }
64 
65  return result;
66  }
67 } // namespace nc
constexpr double pi
Pi.
Definition: Constants.hpp:43
Definition: Coordinate.hpp:45
NdArray< dtype > linspace(dtype inStart, dtype inStop, uint32 inNum=50, bool endPoint=true)
Definition: linspace.hpp:61
auto cos(dtype inValue) noexcept
Definition: cos.hpp:49
std::int32_t int32
Definition: Types.hpp:36
NdArray< double > hanning(int32 m)
Definition: hanning.hpp:48