Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
Robert
Robert le 16 Fév 2017
Commenté : Star Strider le 16 Fév 2017
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

Réponse acceptée

Star Strider
Star Strider le 16 Fév 2017
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 commentaires
Robert
Robert le 16 Fév 2017
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 le 16 Fév 2017
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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by