Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. void idct(complex* v, int n) {
  2. float k = PI / (2 * n);
  3. complex* new = (complex*)malloc(sizeof(complex) * n);
  4. complex * scratch = (complex*)malloc(sizeof(complex) * n);
  5. complex aux;
  6.  
  7. new[0].Re = v[0].Re / (n * 2);
  8. for (int i = 1; i < n; i++) {
  9. aux.Im = sin(i * k);
  10. aux.Re = cos(i * k);
  11. new[i].Re = (v[n-i].Re * aux.Im + v[i].Re * aux.Re) / (n * 2);
  12. new[i].Im = (aux.Im * v[i].Re - v[n-i].Re * aux.Re) / (n * 2);
  13. }
  14.  
  15. fft(new, n, scratch);
  16.  
  17. for (int i = 0; i < n / 2; i++) {
  18. v[2 * i].Re = new[i].Re;
  19. v[2 * i + 1].Re = new[n - 1 - i].Re;
  20. }
  21.  
  22. for (int i = 1; i < n-1; i+=2) {
  23. aux = v[i];
  24. v[i] = v[i + 1];
  25. v[i + 1] = aux;
  26. }
  27. free(scratch);
  28. free(new);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement