フィルターのクリア

How to vectorize this nested loop for optimized performance

1 回表示 (過去 30 日間)
Yodish
Yodish 2017 年 12 月 18 日
コメント済み: Matt J 2017 年 12 月 19 日
hello everybody, I have been trying to optimize this nested for loop which is very very slow, but with no success
for i=1:size(Sxx,2)-1
for j=1:size(Sxx,2)-1
A=Sxx(:,i).*conj(Sxx(:,j));
B= (ifft(A, 'symmetric'));
[~, T(i,j)] = max(B(1:round(end/2)));
end
end
any help is appreciated!

採用された回答

Matt J
Matt J 2017 年 12 月 18 日
編集済み: Matt J 2017 年 12 月 19 日
My advice would be not to vectorize it completely (although there are ways to do so), but rather reduce it to one loop as below.
[m,n]=size(Sxx);
k=1:round(m/2);
SxxConj=conj(Sxx(:,1:n-1));
T=nan(n-1);
for i=1:n-1
B=ifft(Sxx(:,i).*SxxConj, [],1,'symmetric'); %If <R2016b use bsxfun
[~,T(i,:)]=max(B(k,:),[],1); %EDITED
end
You could also convert this to a parfor loop if the serial performance is insufficient.
  1 件のコメント
Matt J
Matt J 2017 年 12 月 19 日
Comment by Yodish:
Definitely faster (probably not enough yet though for my purposes) and more elegant, thanks Matt
PS. index of B needs to be swapped in second last line

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by