On 27/06/2015 10:29 p.m., kerdemdemir wrote:
Hi

My question is more about Maths than D lang,
I am hoping, maybe somebody worked with AutoCorrelation function before.


auto autoCorrelation(R)(R range)
         if (isRandomAccessRange!R)
{
     auto residual = residualPowerOf2(range.length); // Find how many
zeros to add
     auto fftResult = range.chain(repeat(0, residual)).fft(); // Takes FFT

     //First zip each element of fft with conjagute of fft
     auto autoCorrResult = fftResult.zip(fftResult.map!(a => a *
a.conj())).
                 map!( a=> a[0] * a[1] ). // Than multiple them
                 inverseFft(). // Than take inverse
                 dropBack(residual);//Drop the additional zeros

     auto finalResult = autoCorrResult.take(1). // Take DC element
                 chain(autoCorrResult[$/2..$]).//Take last half to
beginning
                 chain(autoCorrResult[1..$/2]). // First(negative lags)
to end
             map!(a => a.re); // I just need real part

     return finalResult ;
}


My autocorrelation method return some crazy values(finalResult[0] =
-101652). I am mostly suspicious about calculations to set
"finalResult"  variable.

Also is there any performance issues? can I make this faster?

No idea about the maths behind it are but:

chain(autoCorrResult[1..$/2])

Should that one be a zero?

Reply via email to