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 OutputDerived::Scalar dst_type;
293 const bool realfft= (NumTraits<dst_type>::IsComplex == 0);
294 EIGEN_STATIC_ASSERT_VECTOR_ONLY(OutputDerived)
295 EIGEN_STATIC_ASSERT_VECTOR_ONLY(ComplexDerived)
296 EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(ComplexDerived,OutputDerived)
297 EIGEN_STATIC_ASSERT((internal::is_same<src_type, Complex>::value),
298 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
299 EIGEN_STATIC_ASSERT(
int(OutputDerived::Flags)&
int(ComplexDerived::Flags)&DirectAccessBit,
300 THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_WITH_DIRECT_MEMORY_ACCESS_SUCH_AS_MAP_OR_PLAIN_MATRICES)
303 if ( realfft && HasFlag(HalfSpectrum) )
304 nfft = 2*(src.size()-1);
308 dst.derived().resize( nfft );
311 Index resize_input= ( realfft && HasFlag(HalfSpectrum) )
312 ? ( (nfft/2+1) - src.size() )
313 : ( nfft - src.size() );
315 if ( src.innerStride() != 1 || resize_input ) {
317 Matrix<src_type,1,Dynamic> tmp;
318 if ( resize_input ) {
319 size_t ncopy = (std::min)(src.size(),src.size() + resize_input);
320 tmp.setZero(src.size() + resize_input);
321 if ( realfft && HasFlag(HalfSpectrum) ) {
323 tmp.head(ncopy) = src.head(ncopy);
324 tmp(ncopy-1) = real(tmp(ncopy-1));
329 tmp.head(nhead) = src.head(nhead);
330 tmp.tail(ntail) = src.tail(ntail);
331 if (resize_input<0) {
332 tmp(nhead) = ( src(nfft/2) + src( src.size() - nfft/2 ) )*src_type(.5);
334 tmp(nhead) = src(nhead) * src_type(.5);
335 tmp(tmp.size()-nhead) = tmp(nhead);
341 inv( &dst[0],&tmp[0], nfft);
343 inv( &dst[0],&src[0], nfft);
347 template <
typename _Output>
349 void inv( std::vector<_Output> & dst,
const std::vector<Complex> & src,Index nfft=-1)
352 nfft = ( NumTraits<_Output>::IsComplex == 0 && HasFlag(HalfSpectrum) ) ? 2*(src.size()-1) : src.size();
354 inv( &dst[0],&src[0],nfft);
370 impl_type & impl() {
return m_impl;}
373 template <
typename T_Data>
375 void scale(T_Data * x,Scalar s,Index nx)
378 for (
int k=0;k<nx;++k)
381 if ( ((ptrdiff_t)x) & 15 )
382 Matrix<T_Data, Dynamic, 1>::Map(x,nx) *= s;
384 Matrix<T_Data, Dynamic, 1>::MapAligned(x,nx) *= s;
390 void ReflectSpectrum(Complex * freq, Index nfft)
393 Index nhbins=(nfft>>1)+1;
394 for (Index k=nhbins;k < nfft; ++k )
395 freq[k] = conj(freq[nfft-k]);
402template<
typename T_SrcMat,
typename T_FftIfc>
403template<
typename T_DestMat>
inline
404void fft_fwd_proxy<T_SrcMat,T_FftIfc>::evalTo(T_DestMat& dst)
const
406 m_ifc.fwd( dst, m_src, m_nfft);
409template<
typename T_SrcMat,
typename T_FftIfc>
410template<
typename T_DestMat>
inline
411void fft_inv_proxy<T_SrcMat,T_FftIfc>::evalTo(T_DestMat& dst)
const
413 m_ifc.inv( dst, m_src, m_nfft);
Namespace containing all symbols from the Eigen library.
Definition AdolcForward:45