How to parallelize this code or make it more efficient

24 次查看(过去 30 天)
I'm doing 3D fft and I would like to parallelize this code if possible, or at least make it more efficient.
Dim=size(y);
N1_FFT=2*2^nextpow2(Dim(1));
N2_FFT=2*2^nextpow2(Dim(2));
N3_FFT=2*2^nextpow2(Dim(3));
N_FFT=[N1_FFT,N2_FFT,N3_FFT];
%Calculate 3D fft
CostFunction3=y;
for p = 1:length(size(y))
CostFunction3 = fft(CostFunction3,N_FFT(p),p);
end
CostFunction3 = fftshift(abs(CostFunction3).^2);
Edit: forgot to mention, y is a 3D matrix with signal samples
  2 个评论
Adam
Adam 2017-2-8
If y is a vector how is this a 3D FFT?
Also you should use
ndims(y)
if you want to loop over the number of dimensions, which is what length( size(y) ) will give you, but in your case, if y is a vector this will return 2 which is not helpful really anyway because one of those dimensions will be a singleton.
Omar Hammouda
Omar Hammouda 2017-2-8
编辑:Omar Hammouda 2017-2-8
Sorry for not being clear, y is a 3D matrix 256x256x256
also I forgot to add this part for calculating the N_FFT
Dim=size(y);
N1_FFT=2*2^nextpow2(Dim(1));
N2_FFT=2*2^nextpow2(Dim(2));
N3_FFT=2*2^nextpow2(Dim(3));
N_FFT=[N1_FFT,N2_FFT,N3_FFT];
I've fixed my question, thanks for noting the mistakes

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by