Explanation for a function within xcorr

4 visualizaciones (últimos 30 días)
Big heads
Big heads el 10 de Ag. de 2022
Comentada: David Goodmanson el 14 de Ag. de 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?

Respuesta aceptada

David Goodmanson
David Goodmanson el 12 de Ag. de 2022
Editada: David Goodmanson el 12 de Ag. de 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 comentarios
Big heads
Big heads el 12 de Ag. de 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 el 14 de Ag. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by