summaryrefslogtreecommitdiffhomepage
path: root/util.cpp
blob: d4616cf6ae9284ba3215c9058387a210a05da399 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "util.h"

#include <algorithm>

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;
}