NumCpp  2.16.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Loading...
Searching...
No Matches
fftfreq.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include "NumCpp/Core/Types.hpp"
31#include "NumCpp/NdArray.hpp"
32
33namespace nc::fft
34{
35 //===========================================================================
36 // Method Description:
48 inline NdArray<double> fftfreq(uint32 inN, double inD = 1.)
49 {
50 if (inN == 0)
51 {
52 return {};
53 }
54 else if (inN == 1)
55 {
56 return { 0 };
57 }
58
59 if (inD <= 0.)
60 {
61 return {};
62 }
63
64 const auto nTimesD = static_cast<double>(inN) * inD;
65
66 auto result = NdArray<double>(1, inN);
67 result[0] = 0.;
68
69 for (auto i = 1u; i < (inN + 1) / 2; ++i)
70 {
71 result[i] = static_cast<double>(i) / nTimesD;
72 result[inN - i] = -static_cast<double>(i) / nTimesD;
73 }
74
75 if (inN % 2 == 0)
76 {
77 result[inN / 2] = -static_cast<double>(inN / 2) / nTimesD;
78 }
79
80 return result;
81 }
82} // namespace nc::fft
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition NdArrayCore.hpp:139
Definition FFT/FFT.hpp:40
NdArray< double > fftfreq(uint32 inN, double inD=1.)
Definition fftfreq.hpp:48
NdArray< dtype > arange(dtype inStart, dtype inStop, dtype inStep=1)
Definition arange.hpp:59
std::uint32_t uint32
Definition Types.hpp:40