Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fast Average Square Difference Function

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

?

like image 667
tkw954 Avatar asked Jun 10 '09 01:06

tkw954


1 Answers

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;
like image 54
mtrw Avatar answered Oct 05 '22 12:10

mtrw