フィルターのクリア

Remidies for changed values in a vector as a result of fftshift?

1 回表示 (過去 30 日間)
Robert
Robert 2017 年 2 月 16 日
コメント済み: Star Strider 2017 年 2 月 16 日
Hi,
While rewriting a script, I noticed that the sum of a vector changes if ifftshift/fftshift has been carried out. Take the following example:
t=-10:.1:10-.1; y=exp(-t.^2/2); s1=sum(y); s2=sum(ifftshift(y)); s3=sum(fftshift(y)); d1=vpa(s1-s2); d2=vpa(s1-s3);
I get the following: d1=d2=0.0000000000000035527136788005009293556213378906
I also found that I get the same difference if I carry out the shift manually like:
y2=[y(101:200),y(1:100)]; s4=sum(y2); s4-s2=0
So my question is, why does the sum of the vector change if the vector is shifted in this manner and are there any ways to make sure that the sum stays the same without having to evaluate both of the sums and then re-scaling the shifted vector?
Thanks in advance, Robert

採用された回答

Star Strider
Star Strider 2017 年 2 月 16 日
I believe you intend ‘d1-d2’ here:
d1=d2=0.0000000000000035527136788005009293556213378906
In any event, that value, 3.6E-15, is on the order of floating point approximation error. See: Why is 0.3 - 0.2 - 0.1 (or similar) not equal to zero? for a thorough discussion.
  2 件のコメント
Robert
Robert 2017 年 2 月 16 日
Hi,
I meant that d1 and d2 gives the same result, but thank you for your answer, do you know if there are any ways of adjusting the floating point approximation? Like using more significant digits or something like that?
Star Strider
Star Strider 2017 年 2 月 16 日
My pleasure.
You can use single precision instead of the default double, but I would not recommend that. You’ve already discovered the Symbolic Math Toolbox and its extended-precision capabilities.
Another option is John D’Errico’s HPF - a big decimal class. I’ve no experience with it, since I rarely need precision beyond the MATLAB default. If you want extended-precision computations, it would definitely be worth exploring.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by