How to parallelize this code or make it more efficient

24 views (last 30 days)
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 Comments
Adam
Adam on 8 Feb 2017
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 on 8 Feb 2017
Edited: Omar Hammouda on 8 Feb 2017
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

Sign in to comment.

Answers (0)

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!