ankacomplex.cl 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (C) 2011-2014 Karlsruhe Institute of Technology
  3. *
  4. * This file is part of Ufo.
  5. *
  6. * This library is free software: you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation, either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * multiply_frequencies_with_real_sym:
  21. * @frequencies: complex Fourier transform frequencies with interleaved
  22. * real/imaginary values
  23. * @output: multiplication result
  24. * @coefficients: first half of symmetric coefficients for the multiplication
  25. * (size = width / 2 + 1)
  26. *
  27. * Multiply every row of @frequencies with @coefficients which are half the *real*
  28. * width + 1, i.e. width = global size / 2 because of the complex numbers. This
  29. * kernel takes advantage of symmetry and expects @frequencies to be ordered as
  30. * [0, 1, ..., width / 2 - 1, -width / 2, ..., -1]. After width / 2 the @coefficients
  31. * are mirrored.
  32. */
  33. kernel void
  34. multiply_frequencies_with_real_sym (global float *frequencies,
  35. global float *output,
  36. constant float *coefficients)
  37. {
  38. const int idx = get_global_id(0);
  39. const int idy = get_global_id(1);
  40. const int real_width = get_global_size (0) / 2;
  41. const int index = idy * 2 * real_width + idx;
  42. const int real_index = idx < real_width ? idx / 2 : real_width - idx / 2;
  43. output[index] = frequencies[index] * coefficients[real_index];
  44. }