# Speed up FFT calculation

조회 수: 47(최근 30일)
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 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표시숨기기 이전 댓글 수: 8
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?

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

### Community Treasure Hunt

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

Start Hunting!
{"ft_lang_label":"__label__en","ft_lang_prob":0.94437826,"math_prob":0.9173055,"size":819,"snap":"2021-43-2021-49","text_gpt3_token_len":198,"char_repetition_ratio":0.13006134,"word_repetition_ratio":0.0,"special_character_ratio":0.25518927,"punctuation_ratio":0.11309524,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98796356,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-10-19T22:51:01Z\",\"WARC-Record-ID\":\"<urn:uuid:eeb6edda-2094-4fe6-a87a-6be820ef1349>\",\"Content-Length\":\"168556\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:143ee819-19be-4fab-a0da-d7da23227668>\",\"WARC-Concurrent-To\":\"<urn:uuid:9524b5b8-8e8d-40e8-b0cb-c30e4b3ed3d3>\",\"WARC-IP-Address\":\"104.68.243.15\",\"WARC-Target-URI\":\"https://kr.mathworks.com/matlabcentral/answers/552676-speed-up-fft-calculation?s_tid=prof_contriblnk\",\"WARC-Payload-Digest\":\"sha1:ZPXFPK6ZWQA5U6XRAP3JY5MT5HIGRFNR\",\"WARC-Block-Digest\":\"sha1:VCBMRXX3GT56ABX5HI6Q3BUN4YAYEB4W\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-43/CC-MAIN-2021-43_segments_1634323585281.35_warc_CC-MAIN-20211019202148-20211019232148-00673.warc.gz\"}"}