FID-A simmulation code

Hi, everyone. I am trying to make basis with FID-A, But I can’t understand the code very well.
In the sim_readout script, the FD data can be get by ifft “ out.specs=fftshift(ifft(out.fids)) ”, but in the fit_makebasis script provided by Osprey, the FD data get by fft, “temp.(basisFct{ll}).specs=fftshift(fft(temp.(basisFct{ll}).fids, [], 1),1)”.
I have some puzzle in understanding this, is the two functions (fft and ifft) have no difference in transforming the data? Thanks in advance!

Hi Murph,
I would guess that the FID-A scripts are older than the Osprey ones. FFT should be the right one here and I have also corrected this in some of my FID-A scripts which I use. Such differences are especially noticeable when you have several software packages running on FID-A (e.g. Osprey, MRSCloud) and all are set in your path.


1 Like

There are subtle but significant differences between these two functions: scaling and orientation in the complex plane; see Fast Fourier transform - MATLAB fft - MathWorks Nordic. Mix them at your peril.

Upstream FID-A uses a less conventional combination of fftshift and ifft, but is internally consistent in doing so. Simulation etc from exampleRunScripts contained in the upstream FID-A package work nicely and correctly with the other processing and simulation functions in that package.

The modified version of FID-A contained within the Osprey package changes this throughout, to the more conventional fftshift(fft(...)) pattern. Note that these changes also imply a change to the ppm axis calculation.

Some other software, at least historically, has been less consistent in its approach.

Trouble is that not all of the FID-A functions are replicated (and modified) within Osprey, so if Osprey’s FID-A is higher than upstream FID-A in your matlab search path, it’s quite likely it’ll use a bit of each. In the first instance, if you look at the real frequency-domain spectra, the results might appear quite similar – but any further transforms using the “other” convention will quickly cause big and confusing problems: back-to-front spectra, or FIDs split across the axis boundaries for example. In principle one should be able to fix this by taking the complex conjugate, but it gets difficult to track which way around things are and which way around they should be. Pain and suffering ensues.

So, as alluded to by @hraum, it’s best to ensure that only one FID-A is on your matlab search path at a time, and that you know which one it is. If you’re using Osprey, then it has to be the included FID-A under libraries/FID-A. If you’re hoping to use FID-A’s examples and simulation tools, then it’s best to use that one instead.

1 Like

Thanks @hraum and @alex. If I could undo one Osprey design decision with the stroke of a pen, it would be the reversal of the fft/ifft direction - although even @JamieNear now agrees that fid → spec should be the fft direction :wink:

1 Like