71#ifdef EIGEN_FFTW_DEFAULT
74# include "src/FFT/ei_fftw_impl.h"
77 template <
typename T>
struct default_fft_impl :
public internal::fftw_impl<T> {};
79#elif defined EIGEN_MKL_DEFAULT
82# include "src/FFT/ei_imklfft_impl.h"
84 template <
typename T>
struct default_fft_impl :
public internal::imklfft_impl {};
89# include "src/FFT/ei_kissfft_impl.h"
92 struct default_fft_impl :
public internal::kissfft_impl<T> {};
100template<
typename T_SrcMat,
typename T_FftIfc>
struct fft_fwd_proxy;
101template<
typename T_SrcMat,
typename T_FftIfc>
struct fft_inv_proxy;
104template<
typename T_SrcMat,
typename T_FftIfc>
105struct traits< fft_fwd_proxy<T_SrcMat,T_FftIfc> >
107 typedef typename T_SrcMat::PlainObject ReturnType;
109template<
typename T_SrcMat,
typename T_FftIfc>
110struct traits< fft_inv_proxy<T_SrcMat,T_FftIfc> >
112 typedef typename T_SrcMat::PlainObject ReturnType;
116template<
typename T_SrcMat,
typename T_FftIfc>
118 :
public ReturnByValue<fft_fwd_proxy<T_SrcMat,T_FftIfc> >
120 typedef DenseIndex Index;
122 fft_fwd_proxy(
const T_SrcMat& src,T_FftIfc & fft, Index nfft) : m_src(src),m_ifc(fft), m_nfft(nfft) {}
124 template<
typename T_DestMat>
void evalTo(T_DestMat& dst)
const;
126 Index rows()
const {
return m_src.rows(); }
127 Index cols()
const {
return m_src.cols(); }
129 const T_SrcMat & m_src;
133 fft_fwd_proxy& operator=(
const fft_fwd_proxy&);
136template<
typename T_SrcMat,
typename T_FftIfc>
138 :
public ReturnByValue<fft_inv_proxy<T_SrcMat,T_FftIfc> >
140 typedef DenseIndex Index;
142 fft_inv_proxy(
const T_SrcMat& src,T_FftIfc & fft, Index nfft) : m_src(src),m_ifc(fft), m_nfft(nfft) {}
144 template<
typename T_DestMat>
void evalTo(T_DestMat& dst)
const;
146 Index rows()
const {
return m_src.rows(); }
147 Index cols()
const {
return m_src.cols(); }
149 const T_SrcMat & m_src;
153 fft_inv_proxy& operator=(
const fft_inv_proxy&);
157template <
typename T_Scalar,
158 typename T_Impl=default_fft_impl<T_Scalar> >
162 typedef T_Impl impl_type;
163 typedef DenseIndex Index;
164 typedef typename impl_type::Scalar Scalar;
165 typedef typename impl_type::Complex Complex;
175 FFT(
const impl_type & impl=impl_type() , Flag flags=Default ) :m_impl(impl),m_flag(flags) { }
178 bool HasFlag(Flag f)
const {
return (m_flag & (
int)f) == f;}
181 void SetFlag(Flag f) { m_flag |= (int)f;}
184 void ClearFlag(Flag f) { m_flag &= (~(int)f);}
187 void fwd( Complex * dst,
const Scalar * src, Index nfft)
189 m_impl.fwd(dst,src,
static_cast<int>(nfft));
190 if ( HasFlag(HalfSpectrum) ==
false)
191 ReflectSpectrum(dst,nfft);
195 void fwd( Complex * dst,
const Complex * src, Index nfft)
197 m_impl.fwd(dst,src,
static_cast<int>(nfft));
208 template <
typename _Input>
210 void fwd( std::vector<Complex> & dst,
const std::vector<_Input> & src)
212 if ( NumTraits<_Input>::IsComplex == 0 && HasFlag(HalfSpectrum) )
213 dst.resize( (src.size()>>1)+1);
215 dst.resize(src.size());
216 fwd(&dst[0],&src[0],src.size());
219 template<
typename InputDerived,
typename ComplexDerived>
221 void fwd( MatrixBase<ComplexDerived> & dst,
const MatrixBase<InputDerived> & src, Index nfft=-1)
223 typedef typename ComplexDerived::Scalar dst_type;
224 typedef typename InputDerived::Scalar src_type;
225 EIGEN_STATIC_ASSERT_VECTOR_ONLY(InputDerived)
226 EIGEN_STATIC_ASSERT_VECTOR_ONLY(ComplexDerived)
227 EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(ComplexDerived,InputDerived)
228 EIGEN_STATIC_ASSERT((internal::is_same<dst_type, Complex>::value),
229 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
230 EIGEN_STATIC_ASSERT(
int(InputDerived::Flags)&
int(ComplexDerived::Flags)&
DirectAccessBit,
231 THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_WITH_DIRECT_MEMORY_ACCESS_SUCH_AS_MAP_OR_PLAIN_MATRICES)
236 if ( NumTraits< src_type >::IsComplex == 0 && HasFlag(HalfSpectrum) )
237 dst.derived().resize( (nfft>>1)+1);
239 dst.derived().resize(nfft);
241 if ( src.innerStride() != 1 || src.size() < nfft ) {
242 Matrix<src_type,1,Dynamic> tmp;
243 if (src.size()<nfft) {
245 tmp.block(0,0,src.size(),1 ) = src;
249 fwd( &dst[0],&tmp[0],nfft );
251 fwd( &dst[0],&src[0],nfft );
255 template<
typename InputDerived>
257 fft_fwd_proxy< MatrixBase<InputDerived>, FFT<T_Scalar,T_Impl> >
258 fwd(
const MatrixBase<InputDerived> & src, Index nfft=-1)
260 return fft_fwd_proxy< MatrixBase<InputDerived> ,FFT<T_Scalar,T_Impl> >( src, *
this,nfft );
263 template<
typename InputDerived>
265 fft_inv_proxy< MatrixBase<InputDerived>, FFT<T_Scalar,T_Impl> >
266 inv(
const MatrixBase<InputDerived> & src, Index nfft=-1)
268 return fft_inv_proxy< MatrixBase<InputDerived> ,FFT<T_Scalar,T_Impl> >( src, *
this,nfft );
272 void inv( Complex * dst,
const Complex * src, Index nfft)
274 m_impl.inv( dst,src,
static_cast<int>(nfft) );
275 if ( HasFlag( Unscaled ) ==
false)
276 scale(dst,Scalar(1./nfft),nfft);
280 void inv( Scalar * dst,
const Complex * src, Index nfft)
282 m_impl.inv( dst,src,
static_cast<int>(nfft) );
283 if ( HasFlag( Unscaled ) ==
false)
284 scale(dst,Scalar(1./nfft),nfft);
287 template<
typename OutputDerived,
typename ComplexDerived>
289 void inv( MatrixBase<OutputDerived> & dst,
const MatrixBase<ComplexDerived> & src, Index nfft=-1)
291 typedef typename ComplexDerived::Scalar src_type;
292 typedef typename ComplexDerived::RealScalar real_type;
293 typedef typename OutputDerived::Scalar dst_type;
294 const bool realfft= (NumTraits<dst_type>::IsComplex == 0);
295 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OutputDerived)
296 EIGEN_STATIC_ASSERT_VECTOR_ONLY(ComplexDerived)
297 EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(ComplexDerived,OutputDerived)
298 EIGEN_STATIC_ASSERT((internal::is_same<src_type, Complex>::value),
299 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
300 EIGEN_STATIC_ASSERT(
int(OutputDerived::Flags)&
int(ComplexDerived::Flags)&
DirectAccessBit,
301 THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_WITH_DIRECT_MEMORY_ACCESS_SUCH_AS_MAP_OR_PLAIN_MATRICES)
304 if ( realfft && HasFlag(HalfSpectrum) )
305 nfft = 2*(src.size()-1);
309 dst.derived().resize( nfft );
312 Index resize_input= ( realfft && HasFlag(HalfSpectrum) )
313 ? ( (nfft/2+1) - src.size() )
314 : ( nfft - src.size() );
316 if ( src.innerStride() != 1 || resize_input ) {
318 Matrix<src_type,1,Dynamic> tmp;
319 if ( resize_input ) {
320 size_t ncopy = (std::min)(src.size(),src.size() + resize_input);
321 tmp.setZero(src.size() + resize_input);
322 if ( realfft && HasFlag(HalfSpectrum) ) {
324 tmp.head(ncopy) = src.head(ncopy);
325 tmp(ncopy-1) =
real(tmp(ncopy-1));
330 tmp.head(nhead) = src.head(nhead);
331 tmp.tail(ntail) = src.tail(ntail);
332 if (resize_input<0) {
333 tmp(nhead) = ( src(nfft/2) + src( src.size() - nfft/2 ) )*real_type(.5);
335 tmp(nhead) = src(nhead) * real_type(.5);
336 tmp(tmp.size()-nhead) = tmp(nhead);
342 inv( &dst[0],&tmp[0], nfft);
344 inv( &dst[0],&src[0], nfft);
348 template <
typename _Output>
350 void inv( std::vector<_Output> & dst,
const std::vector<Complex> & src,Index nfft=-1)
353 nfft = ( NumTraits<_Output>::IsComplex == 0 && HasFlag(HalfSpectrum) ) ? 2*(src.size()-1) : src.size();
355 inv( &dst[0],&src[0],nfft);
371 impl_type & impl() {
return m_impl;}
374 template <
typename T_Data>
376 void scale(T_Data * x,Scalar s,Index nx)
379 for (
int k=0;k<nx;++k)
382 if ( ((ptrdiff_t)x) & 15 )
391 void ReflectSpectrum(Complex * freq, Index nfft)
394 Index nhbins=(nfft>>1)+1;
395 for (Index k=nhbins;k < nfft; ++k )
396 freq[k] =
conj(freq[nfft-k]);
403template<
typename T_SrcMat,
typename T_FftIfc>
404template<
typename T_DestMat>
inline
405void fft_fwd_proxy<T_SrcMat,T_FftIfc>::evalTo(T_DestMat& dst)
const
407 m_ifc.fwd( dst, m_src, m_nfft);
410template<
typename T_SrcMat,
typename T_FftIfc>
411template<
typename T_DestMat>
inline
412void fft_inv_proxy<T_SrcMat,T_FftIfc>::evalTo(T_DestMat& dst)
const
414 m_ifc.inv( dst, m_src, m_nfft);
static ConstMapType Map(const Scalar *data)
static ConstAlignedMapType MapAligned(const Scalar *data)
const unsigned int DirectAccessBit
Namespace containing all symbols from the Eigen library.
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_real_op< typename Derived::Scalar >, const Derived > real(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_conjugate_op< typename Derived::Scalar >, const Derived > conj(const Eigen::ArrayBase< Derived > &x)