29 FourierTransform::FourierTransform() {};
32 FourierTransform::~FourierTransform() {};
42 std::vector< std::complex<double> >
43 FourierTransform::Transform(std::vector< std::complex<double> > input) {
46 int n = NextPowerOfTwo(input.size());
47 vector< std::complex<double> > output(n);
52 for(
int i = 0; i < n; i++) {
53 if(output[i] == 0.0) {
54 int j = BitReverse(n, i);
62 for(
int m = 1; m < n; m *= 2) {
63 complex<double> Wm(polar(1.0, -1.0 *
PI / m));
64 for(
int k = 0; k < n; k += 2 * m) {
66 complex<double> W(1.0);
67 for(
int j = 0; j < m; j++) {
68 complex<double> t = W * output[k+j+m];
69 complex<double> u = output[k+j];
71 output[k+j+m] = u - t;
89 std::vector< std::complex<double> >
90 FourierTransform::Inverse(std::vector< std::complex<double> > input) {
93 std::vector< std::complex<double> > temp(n);
94 for(
int i = 0; i < n; i++) {
95 temp[i] = conj(input[i]);
98 std::vector< std::complex<double> > output =
Transform(temp);
100 for(
int i = 0; i < n; i++) {
101 output[i] = conj(output[i]) / ((double)n);
115 bool FourierTransform:: IsPowerOfTwo(
int n) {
117 if(n % 2 == 1)
return false;
131 int FourierTransform:: lg(
int n) {
152 int FourierTransform::BitReverse(
int n,
int x) {
164 return(
int)(ans * n / 2);
175 int FourierTransform::NextPowerOfTwo(
int n) {
176 if(IsPowerOfTwo(n))
return n;
177 return(
int)pow(2.0, lg(n) + 1);
const double PI
The mathematical constant PI.
Namespace for the standard library.
Namespace for ISIS/Bullet specific routines.