Explanation for a function within xcorr

조회 수: 4 (최근 30일)
Big heads
Big heads 2022년 8월 10일
댓글: David Goodmanson 2022년 8월 14일
Looking within the xcorr function, most of it is pretty straightforward, except for one function within xcorr called "findTransformLength".
function m = findTransformLength(m)
m = 2*m;
while true
r = m;
for p = [2 3 5 7]
while (r > 1) && (mod(r, p) == 0)
r = r / p;
end
end
if r == 1
break;
end
m = m + 1;
end
With no comments, i fail to understand what this function is meant to acheive and what is the significance of p = [2 3 5 7]. Why those numbers specifically? Why not take a fixed FFT size instead?

채택된 답변

David Goodmanson
David Goodmanson 2022년 8월 12일
편집: David Goodmanson 2022년 8월 12일
Hi big,
rather than puzzle this out in place, it seemed easier to look at the output of the function for the first hundred values of m. The answer seems to be: the smallest value that is
(a) greater than or equal to 2*m, and
(b) contains only the prime factors 2,3,5,7 to various powers.
This is done to take advantage of the speed of the fft in those circumstances.
n = 100;
a = zeros(n,1);
for k = 1:n
a(k) = findTransformLength(k);
end
[(1:n)' a]
function m = findTransformLength(m)
(as you have it)
end % extra 'end' required to delineate a function at the bottom of a script file
  댓글 수: 2
Big heads
Big heads 2022년 8월 12일
Thank you David for the reply. I see what the function does. But why not just use a constant FFT size? What would be wrong with that?
m2 = findTransformLength(m);
X = fft(x,m2,1);
As we know increasing the FFT size does not necessarily increase the resolution of the FFT output. so why do the "findTransformLength" at all. as long as we take the FFT (with a fixed size) of both A and B, do a multiplication of A with the complex conjugate of B and then take an inverse iFFT, that should suffice, shouldn't it?
David Goodmanson
David Goodmanson 2022년 8월 14일
Hi big,
I believe this is done for reasons of speed. If the length of the array is factored into primes, and one or more of the primes are large, then the fft is slow. When the length is the product of small prime factors, then the fft is faster, typically by a factor of 5 to 10.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by