필터 지우기
필터 지우기

how to reduce the execution time of xcorr() function?

조회 수: 3 (최근 30일)
Sangeetha R
Sangeetha R 2019년 2월 26일
답변: Sangeetha R 2019년 3월 1일
I want to find the windowed correlation values of x & y having array size of 1*20000. Xcorr function taking too much time to execute. Is there any way to reduce the execution time. The code is given below
k=1;
for i=1:stepsize:(length(x)-w+1)
corrValue_w=xcorr(x(i:i+w-1),y(i:i+w-1));
maxCorrValue_w(k)=max(corrValue_w);
k=k+1;
end
  댓글 수: 7
Sangeetha R
Sangeetha R 2019년 2월 28일
Thank you very much.
I think, using loop will take more time to execute in case of large vectors. Buffer function solved my problem.
idx = buffer(x,w,stepsize,'nodelay');
I also got another solution for this problem mentioned below:
idx = bsxfun( @plus, (1:w).', 0:stepsize:(numel(x)-w));
Jan
Jan 2019년 2월 28일
@Sangeetha R: Please post this as an anser and "accept" it as solution.

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

채택된 답변

Sangeetha R
Sangeetha R 2019년 3월 1일
@Jan, KSSV. Thank you so much for the solutions provided.
Solution for the problem asked is provided below;
Input matrix x & y reshaped using buffer function or bsxfun and perform the correlation at once.
% 1. Generate indexing matrix
idx = buffer(x,w,stepsize,'nodelay');
or
idx = bsxfun( @plus, (1:w).', 0:stepsize:(numel(x)-w));
% 2. Reshape the input matrix
x1 = x(idx);
y1 = y(idx);
% 3. Find the correlation of each column of x1 to that of y1
corrLength=2*w - 1
xcorr_value = fftshift(ifft(fft(x1,corrLength).*conj(fft(y1,corrLength))),1);
% 4. Find the maximum value from each column of xcorr_value
maxCorrValue_w = max(xcorr_value,[],1);

추가 답변 (0개)

카테고리

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

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by