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