Speed up FFT calculation

36 次查看(过去 30 天)
William Gray
William Gray 2020-6-22
评论: dpb 2020-6-23
Hello everyone,
I'm currently struggling to speed up an FFT calculation within a for loop for a repeating signal.
the signal matrix is 36350x2048, 36350 being the number of signals and 2048 being the zero padded length of each signal. I padded each signal to this length in hopes that being a power of 2 would speed the calculation up. I also create a matix of ones to attempt to speed up the calculation.
My code for completeing this fft is very simple, but shown below:
SignalF = ones(36350,2048); %create empty matrix
for i = 1:NumS; %pepeat for number of signals
SignalF = fft(Signal(i,:));
end
However, I have found that for this size signal matrix, the calculation is taking around 30 minutes or so (I haven't actually timed it) but I have lots of these matracies to process and so need a way of speeding this up.
Any thoughts or ideas would be really appreciated!

采纳的回答

dpb
dpb 2020-6-22
"The signal matrix is 36350x2048, 36350 being the number of signals and 2048 being the zero padded length of each signal. "
Use the vectorized form TMW supplied --
Y=fft(Signal.');
From the documentation...
Y = fft(X) computes the discrete Fourier transform (DFT) of X using a fast Fourier transform (FFT) algorithm.
  • If X is a matrix, then fft(X) treats the columns of X as vectors and returns the Fourier transform of each column.
Reorient the input array by columns instead of by rows. You can test for comparison but the power of two probably won't make that big a difference (altho I've not timed anything this large to see, granted).
Your use of ones to preallocate probably also hurt instead of helped since the output array needs to be complex, not real -- I also didn't test that hypotheis as there's no need since you can (and should) build the full output array using array syntax.
  9 个评论
William Gray
William Gray 2020-6-23
Thank you very much for all you're help, it is now clearer what the issue is.
I have managed to re-write the code no longer using a loop at all and you are right, it is much quicker!
dpb
dpb 2020-6-23
Did you test the two orientations and/or the 3rd argument variations to see difference in speed the memory layout might make?

请先登录,再进行评论。

更多回答(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