我正在试图找出vDSP函数,我得到的结果非常奇怪。
这与这个问题有关:
Using std::complex with iPhone's vDSP functions
基本上我正试图理解vDSP_vdist,因为我开始使用std :: complex<的向量。浮动>。现在AFAIK我应该能够通过以下方式来计算幅度:
// std::abs of a complex does sqrtf( r^2 + i^2 ).
pOut[idx] = std::abs( pIn[idx] );
然而,当我这样做时,我看到光谱反射在矢量的中点附近。这很奇怪。
但是,奇怪的是,如果我使用vDSP_ztoc后跟vDSP_vdist,我会得到我期望的结果。所以我写了一些代码来试着理解什么是错的。
bool VecMagnitude( float* pOut, const std::complex< float >* pIn, unsigned int num )
{
std::vector< float > realTemp( num );
std::vector< float > imagTemp( num );
DSPSplitComplex dspsc;
dspsc.realp = &realTemp.front();
dspsc.imagp = &imagTemp.front();
vDSP_ctoz( (DSPComplex*)pIn, 1, &dspsc, 1, num );
int idx = 0;
while( idx < num )
{
if ( fabsf( dspsc.realp[idx] - pIn[idx].real() ) > 0.0001f ||
fabsf( dspsc.imagp[idx] - pIn[idx].imag() ) > 0.0001f )
{
char temp[256];
sprintf( temp, "%f, %f - %f, %f", dspsc.realp[idx], dspsc.imagp[idx], pIn[idx].real(), pIn[idx].imag() );
fprintf( stderr, temp );
}
}
return true;
}
现在奇怪的是上面的代码在idx = 1时开始失败并继续到最后。原因是dspsc.realp [1] == pIn [0] .imag()。它不是将它分成两个不同的缓冲区,而是直接将std :: complex的一半传输到dspsc.realp。即2在std :: complex [0]浮动,然后2浮在std :: complex [1],依此类推。 dspsc.imagp大致相同。 dspsc.imagp [1] = pIn [1] .real()。
这没有任何意义。有人可以解释我在哪里无法理解最新情况吗?