Advertisement
Guest User

Untitled

a guest
Jul 29th, 2014
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. void forwardDFT(const double *s, const int &N, double *&a, double *&b)
  2. {
  3.     // note: this code is not optimised at all, written for clarity not speed.
  4.     for (int k = 0; k <= N / 2; ++k) {
  5.         a[k] = b[k] = 0;
  6.         for (int x = 0; x < N; ++x) {
  7.             a[k] += s[x] * cos(2 * M_PI / N * k * x);
  8.             b[k] += s[x] * sin(2 * M_PI / N * k * x);
  9.         }
  10.         // normalization
  11.         a[k] *= (k == 0 || k == N / 2) ? 1. / N : 2. / N;
  12.         b[k] *= 2. / N;
  13.     }
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement