Does fftn do post padding ?

2 ビュー (過去 30 日間)
raheem mian
raheem mian 2020 年 2 月 7 日
編集済み: David Goodmanson 2020 年 2 月 8 日
x = randi(256, 200,200,200);
x = fftn(x,[256,256,256]);
Is this post padding by 56 ?

回答 (1 件)

David Goodmanson
David Goodmanson 2020 年 2 月 8 日
編集済み: David Goodmanson 2020 年 2 月 8 日
HI raheem,
It's pre padding of the original x array by 56 in each dimension, before the fft. As you can see, the y array has no zeros.
x = randi(256, 200,200,200);
y = fftn(x,[256,256,256]);
any(y(:)==0)
ans =
logical
0
soapbox stuff: Unless the length of an array is a large prime number, padding before doing an fft is almost always a bad idea. It changes the resulting frequency array and can lead to problems representing the frequency domain waveform, among other things.
Certainly with the fft algorithms in use today, padding to length 2^n because of the vaunted speed advantage is mostly a myth. For small problems any speed advantage is negligible. So let's take your example as a medium size problem:
x = randi(256, 200,200,200);
tic
for k = 1:100
y = fftn(x,[256,256,256]);
end
toc
Elapsed time is 18.387219 seconds.
tic
for k = 1:100
y = fftn(x);
end
toc
Elapsed time is 5.873024 seconds.
so padding is faster, but only in the sense that it is 3 times slower.
  2 件のコメント
raheem mian
raheem mian 2020 年 2 月 8 日
but on the fftn matlab help page it says it applies trailing zeros ?
David Goodmanson
David Goodmanson 2020 年 2 月 8 日
編集済み: David Goodmanson 2020 年 2 月 8 日
from doc fftn:
Y = fftn(X,sz) truncates X or pads X with trailing zeros before taking the transform ...
I modified the answer above to address the whole idea of padding.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeFourier Analysis and Filtering についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by