How to vectorize loop of fft ?
조회 수: 5 (최근 30일)
이전 댓글 표시
How to vectorize a for loop of fft ?
clear all
W = ones(1,100)*1.5;
y(1:200,1:100) = 0.3;
y(1,:) = ones(1,100)*1.2;
for j=1:200;
y(j+1,:) = ifft(fft(y(j,:)).*W);
end
댓글 수: 0
답변 (1개)
Geoff Hayes
2015년 2월 28일
Ole - is this something that you need to vectorize or just simplified? If the above is a valid example with all elements of W being identical, then the line
y(j+1,:) = (ifft((((fft((y(j,:)))).*W))));
can be simplified to
y(j+1,:) = ifft(fft((y(j,:))).*W);
= ifft(1.5*fft((y(j,:))));
= 1.5*y(j,:);
due to the linearity of the inverse Fourier transform. And so your for loop becomes
for j=1:200;
y(j+1,:) = 1.5*y(j,:);
end
The above implies that the nth column of y (for n>1) is simply
(1.5)^(n-1)*y(1,:)
in which case you can replace your code with just
y = 1.5*ones(201,100);
y(1,:) = 1.2;
y = cumprod(z);
Try the above and see what happens!
댓글 수: 2
Geoff Hayes
2015년 3월 1일
Ole - what is the error? Is it
Error using .*
Matrix dimensions must agree.
because of the line
ifft(fft(y(1:200,:)).*W);
where W is just a 1x100 array and fft(y(1:200,:)) is a 200x200 array. You can only perform an element-wise multiplication on arrays/matrices of the same dimension.
A question that I should have asked sooner - why are you trying to vectorize this problem? Performance reasons? Because the recurrence relation (k+1 depends on k) in the above for loop may provide the best solution.
참고 항목
카테고리
Help Center 및 File Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!