Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

FID - Transformations

In Magnetic Resonance Spectroscopy (MRS), the raw data acquired by the scanner is a time-domain Free Induction Decay (FID).

To visualize the chemical resonances, this digital FID signal is processed by a discrete Fourier transformation (DFT) to produce a digital MR spectrum. Because an FID conventionally starts at t=0t=0, we perform a standard Fast Fourier Transform (FFT) followed by a frequency-domain shift (fftshift) to center the zero-frequency (DC) component.

1. Generate a Synthetic FID

Let’s create an FID with two distinct resonances (at 50 Hz and -150 Hz).

Source
<Figure size 1200x450 with 1 Axes>

2. Convert to Spectrum

We use .xmr.to_spectrum() to perform the FFT and automatically rename the dimension to “frequency”. Notice how the resulting coordinates automatically represent the correct centered frequency axis (ranging from -500 Hz to 500 Hz).

<Figure size 1200x450 with 1 Axes>
Where did that clean “Frequency [Hz]” xlabel come from?

If you spotted that our spectrum has a clean “Frequency [Hz]” xaxis label — even though we never manually assigned it (e.g. with ax.set_xlabel(...)) — good eye!

While you can pass simple strings like "time" and "frequency" to xmris functions to keep the entry barrier low, the package internally maps your input against a strict global vocabulary (xmris.core.config.DIMS and COORDS).

When .xmr.to_spectrum() built the new frequency axis, it intercepted your "frequency" string, fetched the associated physical metadata (long_name="Frequency", units="Hz"), and injected it directly into the new xarray coordinates. When you call .plot(), xarray automatically detects this metadata and formats the axis labels for you!

Bonus: Because "time" and "frequency" are declared default dimensions in xmris, we could actually drop the arguments completely and just call da_fid.xmr.to_spectrum() for the exact same result!

For more info on this design, see xmris Architecture: Why We Built It This Way

3. Convert back to FID

We can accurately recover the original time-domain signal using .xmr.to_fid().

<Figure size 1200x450 with 1 Axes>