필터 지우기
필터 지우기

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 CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by