Group Abstract Group Abstract

Message Boards Message Boards

Get the same FourierTransform results across different versions?

My research lab has used Mathematica for many years developing models for fuel cells and simulating signals we expect from experimental measurements. Many of these files were created in version 9.0 and I have been running version 11.0.1 on my personal laptop. I updated to version 12 today and the code is giving a different output from a Fourier Transform. Specifically, it is a Fourier transform of a cosine that is multiplied by a Gaussian window function and a rectangular window function. From the revision history, it seems the FourierTransform function was last changed in version 11.2.

All of this is shown in the attached file, but I will also repeat here for easy viewing. A few variables that need to be explained, ft= applied frequency, k= harmonic index, b= Gaussian window parameter, Cyc= number of signal waveforms, and nt= number of samples.

The cosine is defined by: voltage wave definition
Where Vk and Vmk are complex coefficients as: complex voltage coefficients
The Gaussian window function is defined as: gaussian window function

The rectangular window function is defined as: rectangular window function

Finally, we take the Fourier transform of the windowed signal: fourier transform

The (presumably correct) answer from Versions older than 11.2 is: correct output

But the answer I'm getting now is: incorrect output

Using SameQ confirms these equations aren't equivalent. I've tinkered with the Fourier Parameters a bit, but that only seems to change the scaling coefficients. One obvious solution is reverting to pre-11.2, but I would like to avoid being stuck to a past version. Thank you in advance!


Update: The apparent errors stemmed from changes in how Mathematica handles variable precisions and underflow. Using some workarounds from @Valerio in Q170416 and @halirutan in Q69912 I've updated my notebook to a working version. I would, however, appreciate if anyone knows of more elegant solutions than what I implemented. Thank you again!

POSTED BY: Brian Gerwe
5 Replies

I checked it numerically and they are not equivalent.

How did you check? I see this: enter image description here

Try this (from your notebook):

Vf1 == Vf2 // Simplify
(*  Out:  True  *)
POSTED BY: Henrik Schachner

SameQ looks for an exact correspondence. Therefore, SameQ[x^2 - 1, (x + 1) (x - 1)] returns False, while the expressions are mathematically identical. When I am faced with situations like yours I would check by evaluating it numerically. The result should be a clear indicator of equivalence (or not).

POSTED BY: Isaac Abraham

Using some workarounds from @Valerio on Q170416 and @halirutan plus @Nasser on Q69912 I've confirmed the issue arises from machine precision/ underflow checking.

With those workarounds in place, the equation calculated in Version 12 gives the expected resultsenter image description here

And the equation calculated by Version 9 evaluates correctly in Version 12 as well: enter image description here

Where differences between the two are on the order of the precision being used:enter image description here

The workarounds may be somewhat clunky but at least they work. Thanks everyone for your replies, and I've attached an updated notebook with the implemented workarounds.

Attachments:
POSTED BY: Brian Gerwe
POSTED BY: Brian Gerwe

I see, that's great to know for the future. I checked it numerically and they are not equivalent.

POSTED BY: Brian Gerwe
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard