views:

548

answers:

2

I'm wondering if anyone knows of a fast (i.e. O(N log(N)) ) method of calculating the average square difference function (ASDF) or average magnitude difference function (AMDF) for a periodic signal, or it is even possible.

I know that one can use the FFT to calculate the periodic cross correlation. For example, in Matlab code,

for i=1:N
xc(i)=sum(x1*circshift(x2,i-1));
end

is equivalent to the much faster

xc=ifft(fft(x1).*conj(fft(x2));

Is there a similar "fast" algorithm for

for i=1:N
ASDF(i)=sum((x1-circshift(x2,i-1)).^2)/N;
end

or

for i=1:N
AMDF(i)=sum(abs(x1-circshift(x2,i-1)))/N;
end

?

A: 

This might be worth looking at:

http://windale.com/transformnet.php

It's not free (or cheap), but if you have a serious need, they do offer source code (and a 30 day guarantee).

Robert Harvey
I know how to calculate an FFT. I want to know if there is an fast method of calculating the ASDF or AMDF.
tkw954
They say they calculate "Gain, Phase, Magnitude functions to enable fast viewing of FFT outputs." That's the same thing, right?
Robert Harvey
No, the magnitude function they're talking about is simply the magnitude of the FFT.
tkw954
+5  A: 

You can expand your definition of ASDF as follows:

for i = 1:N
    asdf(i) = (sum(x1.^2) - 2*sum(x1*circshift(x2,i-1)) + sum(x2.^2))/N;
end

which simplifies to

asdf = (-2*ifft(fft(x1).*conj(fft(x2))) + sum(x1.^2) + sum(x2.^2))/N;
mtrw
Awesome. Perfect. Your code runs 550 times faster on Matlab for N=1024.Thanks
tkw954