summaryrefslogtreecommitdiffhomepage
path: root/util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'util.cpp')
-rw-r--r--util.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/util.cpp b/util.cpp
new file mode 100644
index 0000000..2a81823
--- /dev/null
+++ b/util.cpp
@@ -0,0 +1,25 @@
+#include "util.h"
+
+bool RIT::is_power_of_two(unsigned int n) {
+ return n != 0 && (n & (n - 1)) == 0;
+}
+
+std::vector<double> RIT::magnitudes(const std::vector<std::complex<double>>& v) {
+ std::vector<double> result(v.size());
+ std::transform(std::begin(v), std::end(v), std::begin(result), std::abs<double>);
+ return result;
+}
+
+/// size: fft size in sample points, power of 2
+int RIT::bitreverse(int i, int size) {
+ int result{0};
+
+ while (size > 1) {
+ result <<= 1;
+ result |= i & 1;
+ i >>= 1;
+ size >>= 1;
+ }
+
+ return result;
+}