Explanation for a function within xcorr

2 Ansichten (letzte 30 Tage)
Big heads
Big heads am 10 Aug. 2022
Kommentiert: David Goodmanson am 14 Aug. 2022
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?

Akzeptierte Antwort

David Goodmanson
David Goodmanson am 12 Aug. 2022
Bearbeitet: David Goodmanson am 12 Aug. 2022
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 Kommentare
Big heads
Big heads am 12 Aug. 2022
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 am 14 Aug. 2022
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by