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 Center および File ExchangeCorrelation and Convolution についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by