c /= N;
// Minimize phase
- long minIdx = 0;
- TScalar minImag = std::fabs( std::imag( p[ 0 ] - c ) );
- for( long m = 1; m < p.size( ); ++m )
+ struct _TComplexCmp
{
- TScalar y = std::fabs( std::imag( p[ m ] - c ) );
- if( y < minImag )
- {
- minIdx = m;
- minImag = y;
-
- } // fi
-
- } // rof
+ bool operator()( const TComplex& a, const TComplex& b )
+ {
+ return(
+ ( std::real( b ) < std::real( a ) ) &&
+ ( std::fabs( std::imag( a ) ) < std::fabs( std::imag( b ) ) )
+ );
+ }
+ };
+ std::map< TComplex, long, _TComplexCmp > ordered;
+ for( long m = 0; m < p.size( ); ++m )
+ ordered[ p[ m ] - c ] = m;
+ long si = ordered.begin( )->second;
// Real DFT computation
std::vector< TComplex > dft;
TComplex z( _0, _0 );
for( long i = 0; i < p.size( ); ++i )
z +=
- p[ ( i + minIdx ) % p.size( ) ] *
+ p[ ( i + si ) % p.size( ) ] *
std::polar( _1, _2piN * TScalar( m * i ) );
z /= N;
dft.push_back( z );