Skip to content

Commit 544e5f8

Browse files
committed
added fftfreq and rfftfreq
1 parent e3ea93e commit 544e5f8

File tree

10 files changed

+65
-434
lines changed

10 files changed

+65
-434
lines changed

docs/markdown/ReleaseNotes.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,13 @@
88
* `fft::fftfreq` <https://numpy.org/doc/stable/reference/generated/numpy.fft.fftfreq.html>
99
* `fft::fftshift` <https://numpy.org/doc/stable/reference/generated/numpy.fft.fftshfit.html>
1010
* `fft::ifftshift` <https://numpy.org/doc/stable/reference/generated/numpy.fft.ifftshfit.html>
11-
* `fft::fftresample`: Resample a series to m points via Fourier interpolation
1211
* `fft::fft2` <https://numpy.org/doc/stable/reference/generated/numpy.fft.fft2.html#numpy.fft.fft2>
1312
* `fft::ifft2` <https://numpy.org/doc/stable/reference/generated/numpy.fft.ifft2.html#numpy.fft.ifft2>
14-
* `fft::fft2resample`: Resample a series to m x n points via Fourier interpolation
1513
* `fft::rfft` <https://numpy.org/doc/stable/reference/generated/numpy.fft.rfft.html#numpy.fft.rfft>
1614
* `fft::irfft` <https://numpy.org/doc/stable/reference/generated/numpy.fft.irfft.html#numpy.fft.irfft>
1715
* `fft::rfftfreq` <https://numpy.org/doc/stable/reference/generated/numpy.fft.rfftfreq.html>
18-
* `fft::rfftresample`: Resample a series to m points via Fourier interpolation
1916
* `fft::rfft2` <https://numpy.org/doc/stable/reference/generated/numpy.fft.rfft2.html#numpy.fft.rfft2>
2017
* `fft::irfft2` <https://numpy.org/doc/stable/reference/generated/numpy.fft.irfft2.html#numpy.fft.irfft2>
21-
* `fft::rfft2resample`: Resample a series to m x n points via Fourier interpolation
2218
* added `divmod` <https://numpy.org/doc/stable/reference/generated/numpy.divmod.html#numpy-divmod>
2319
* added `find_duplicates` <https://numpy.org/doc/stable//reference/generated/numpy.rec.find_duplicate.html>
2420
* added `mode` <https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.mode.html>

include/NumCpp/FFT.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,13 @@
2929

3030
#include "NumCpp/FFT/fft.hpp"
3131
#include "NumCpp/FFT/fft2.hpp"
32-
#include "NumCpp/FFT/fft2resample.hpp"
3332
#include "NumCpp/FFT/fftfreq.hpp"
34-
#include "NumCpp/FFT/fftresample.hpp"
3533
#include "NumCpp/FFT/fftshift.hpp"
3634
#include "NumCpp/FFT/ifft.hpp"
3735
#include "NumCpp/FFT/ifft2.hpp"
3836
#include "NumCpp/FFT/ifftshift.hpp"
3937
#include "NumCpp/FFT/irfft.hpp"
38+
#include "NumCpp/FFT/irfft2.hpp"
4039
#include "NumCpp/FFT/rfft.hpp"
4140
#include "NumCpp/FFT/rfft2.hpp"
42-
#include "NumCpp/FFT/rfft2resample.hpp"
4341
#include "NumCpp/FFT/rfftfreq.hpp"
44-
#include "NumCpp/FFT/rfftresample.hpp"

include/NumCpp/FFT/fft2resample.hpp

Lines changed: 0 additions & 71 deletions
This file was deleted.

include/NumCpp/FFT/fftfreq.hpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,42 @@ namespace nc::fft
4141
/// NumPy Reference: <https://numpy.org/doc/stable/reference/generated/numpy.fft.fftfreq.html#>
4242
///
4343
/// @param inN Window Length
44-
/// @param inD (Optional) Sample spacing (inverse of the sampling rate). Defaults to 1.
44+
/// @param inD (Optional) Sample spacing (inverse of the sampling rate). Must be positive non-zero. Defaults to 1.
4545
///
4646
/// @return NdArray
4747
///
4848
inline NdArray<double> fftfreq(uint32 inN, double inD = 1.)
4949
{
50-
return {};
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;
5181
}
5282
} // namespace nc::fft

include/NumCpp/FFT/fftresample.hpp

Lines changed: 0 additions & 73 deletions
This file was deleted.

include/NumCpp/FFT/rfft2resample.hpp

Lines changed: 0 additions & 71 deletions
This file was deleted.

include/NumCpp/FFT/rfftfreq.hpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,29 @@ namespace nc::fft
4747
///
4848
inline NdArray<double> rfftfreq(uint32 inN, double inD = 1.)
4949
{
50-
return {};
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 halfN = (inN / 2) + 1;
65+
const auto nTimesD = static_cast<double>(inN) * inD;
66+
67+
auto result = NdArray<double>(1, halfN);
68+
for (auto i = 0u; i < halfN; ++i)
69+
{
70+
result[i] = static_cast<double>(i) / nTimesD;
71+
}
72+
73+
return result;
5174
}
5275
} // namespace nc::fft

0 commit comments

Comments
 (0)