fn_fft2.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
  2. // Copyright 2008-2016 National ICT Australia (NICTA)
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // ------------------------------------------------------------------------
  15. //! \addtogroup fn_fft2
  16. //! @{
  17. // 2D FFT & 2D IFFT
  18. template<typename T1>
  19. arma_warn_unused
  20. inline
  21. typename
  22. enable_if2
  23. <
  24. is_arma_type<T1>::value,
  25. Mat< std::complex<typename T1::pod_type> >
  26. >::result
  27. fft2(const T1& A)
  28. {
  29. arma_extra_debug_sigprint();
  30. // not exactly efficient, but "better-than-nothing" implementation
  31. typedef typename T1::pod_type T;
  32. Mat< std::complex<T> > B = fft(A);
  33. // for square matrices, strans() will work out that an inplace transpose can be done,
  34. // hence we can potentially avoid creating a temporary matrix
  35. B = strans(B);
  36. return strans( fft(B) );
  37. }
  38. template<typename T1>
  39. arma_warn_unused
  40. inline
  41. typename
  42. enable_if2
  43. <
  44. is_arma_type<T1>::value,
  45. Mat< std::complex<typename T1::pod_type> >
  46. >::result
  47. fft2(const T1& A, const uword n_rows, const uword n_cols)
  48. {
  49. arma_extra_debug_sigprint();
  50. typedef typename T1::elem_type eT;
  51. const quasi_unwrap<T1> tmp(A);
  52. const Mat<eT>& B = tmp.M;
  53. const bool do_resize = (B.n_rows != n_rows) || (B.n_cols != n_cols);
  54. return (do_resize) ? fft2(resize(B,n_rows,n_cols)) : fft2(B);
  55. }
  56. template<typename T1>
  57. arma_warn_unused
  58. inline
  59. typename
  60. enable_if2
  61. <
  62. (is_arma_type<T1>::value && (is_cx_float<typename T1::elem_type>::yes || is_cx_double<typename T1::elem_type>::yes)),
  63. Mat< std::complex<typename T1::pod_type> >
  64. >::result
  65. ifft2(const T1& A)
  66. {
  67. arma_extra_debug_sigprint();
  68. // not exactly efficient, but "better-than-nothing" implementation
  69. typedef typename T1::pod_type T;
  70. Mat< std::complex<T> > B = ifft(A);
  71. // for square matrices, strans() will work out that an inplace transpose can be done,
  72. // hence we can potentially avoid creating a temporary matrix
  73. B = strans(B);
  74. return strans( ifft(B) );
  75. }
  76. template<typename T1>
  77. arma_warn_unused
  78. inline
  79. typename
  80. enable_if2
  81. <
  82. (is_arma_type<T1>::value && (is_cx_float<typename T1::elem_type>::yes || is_cx_double<typename T1::elem_type>::yes)),
  83. Mat< std::complex<typename T1::pod_type> >
  84. >::result
  85. ifft2(const T1& A, const uword n_rows, const uword n_cols)
  86. {
  87. arma_extra_debug_sigprint();
  88. typedef typename T1::elem_type eT;
  89. const quasi_unwrap<T1> tmp(A);
  90. const Mat<eT>& B = tmp.M;
  91. const bool do_resize = (B.n_rows != n_rows) || (B.n_cols != n_cols);
  92. return (do_resize) ? ifft2(resize(B,n_rows,n_cols)) : ifft2(B);
  93. }
  94. //! @}