DFT.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * TI Voxel Lib component.
  3. *
  4. * Copyright (c) 2014 Texas Instruments Inc.
  5. *
  6. * Borrowed from: DFT (Discrete Fourier Transform) and FFT (Fast Fourier Transform)
  7. * Written by Paul Bourke, June 1993. WWW - http://paulbourke.net/miscellaneous/dft/
  8. *
  9. * Modifications done for datatypes.
  10. *
  11. */
  12. #ifndef VOXEL_DFT_H
  13. #define VOXEL_DFT_H
  14. #include <Common.h>
  15. namespace Voxel
  16. {
  17. /**
  18. * \defgroup Flt Filter related classes
  19. * @{
  20. */
  21. typedef Vector<ComplexDouble> Complex1D;
  22. typedef Vector<Vector<ComplexDouble>> Complex2D;
  23. class VOXEL_EXPORT DFT
  24. {
  25. public:
  26. enum Direction
  27. {
  28. FORWARD = 1,
  29. REVERSE = -1
  30. };
  31. protected:
  32. Complex2D _internal;
  33. Map<SizeType, Complex2D> _expTable;
  34. void _computeExpTable(SizeType size, Direction dir);
  35. public:
  36. /**
  37. * Perform a 2D FFT inplace given a complex 2D array
  38. * The direction dir, 1 for forward, -1 for reverse
  39. * The size of the array (nx,ny)
  40. * Return false if there are memory problems or
  41. * the dimensions are not powers of 2
  42. */
  43. bool DFT2D(Complex2D &data, Direction dir);
  44. /**
  45. * This computes an in-place complex-to-complex DFT
  46. * x and y are the real and imaginary arrays of 2^m points.
  47. * dir = 1 gives forward transform
  48. * dir = -1 gives reverse transform
  49. *
  50. * Formula: forward
  51. * N-1
  52. * ---
  53. * 1 \ - j k 2 pi n / N
  54. * X(n) = --- > x(k) e = forward transform
  55. * N / n=0..N-1
  56. * ---
  57. * k=0
  58. *
  59. * Formula: reverse
  60. * N-1
  61. * ---
  62. * \ j k 2 pi n / N
  63. * X(n) = > x(k) e = forward transform
  64. * / n=0..N-1
  65. * ---
  66. * k=0
  67. */
  68. bool DFT1D(const Complex1D &in, Complex1D &out, Direction dir);
  69. };
  70. /**
  71. * @}
  72. */
  73. }
  74. #endif