summaryrefslogtreecommitdiffhomepage
path: root/fft.h
blob: 4bc493d540c1d44dae356f3593e17950fbb76035 (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// FFT

#pragma once

#include <complex>
#include <memory>
#include <vector>

namespace RIT {

// Fast Fourier Transform
class FFT {
private:
	int mSize;
	std::vector<int> order;
	std::vector<std::complex<double>> expLUT;

	bool mFlagHalfOnly;

public:
	FFT(int size, bool halfOnly = false);
	std::vector<std::complex<double>> operator()(const std::vector<std::complex<double>> &v) const;

	FFT& SetHalfOnly(bool enable);

private:
	void reorder(const std::vector<std::complex<double>>& src, std::vector<std::complex<double>>& dst) const;
	void fft_recursive(std::vector<std::complex<double>>::iterator X, int N) const;
	void fft_half(std::vector<std::complex<double>>::iterator X, int N) const;
}; // class FFT

// Inverse FFT
class IFFT {
public:
	IFFT(int size);
	IFFT(std::shared_ptr<FFT> fft);
	~IFFT();
	std::vector<std::complex<double>> operator()(const std::vector<std::complex<double>> &v) const;

private:
	struct Impl;
	std::unique_ptr<Impl> mImpl;
}; // class IFFT

} // namespace RIT