Current page Parallel pthreads-TDFDFit CPU Fitting

Updated in version 3.0.1 Alpha

Parallel pthreads-TDFDFit CPU Fitting

TDFDFit is the prior-knowledge fitting engine used by spectrIm-QMRS for quantitative MRS and MRSI analysis. In version 3.0.1 Alpha, a new pthreads-based implementation parallelizes fitting over CPU cores, making prior-knowledge fitting more practical for larger voxel selections and MRSI volumes.

Why clinicians need prior-knowledge fitting

Clinical spectra often contain overlapping metabolite resonances, residual nuisance signals, broad baselines, variable linewidths, and limited signal-to-noise ratio. In such data, simple peak-height or peak-area measurements can be misleading because a visible peak may represent several chemically different contributions.

Prior-knowledge fitting addresses this by fitting a model of the expected spectral components instead of measuring isolated peaks. The model can include metabolite basis functions, linewidth and frequency constraints, amplitude relations, phase behavior, and baseline terms. This helps turn complex spectra into more stable quantitative estimates that can be reviewed as spectra, fitted curves, residuals, and metabolite maps.

For clinicians, the practical value is that fitting becomes a structured interpretation step: the software uses a spectroscopy model to separate overlapping signals and to report results in a way that is more reproducible than manual spectral inspection alone. Clinical users are advised to create such models with the automatic TDFDFit model creator. Spectroscopists can also build or refine models in the expert TDFDFit modelling frame. The practical application workflow is described on Applying predefined TDFDFit models to spectra.

Academic background

TDFDFit follows the approach described by Slotboom and colleagues in the late 1990s: spectral quantification is formulated as a model-based nonlinear fitting problem in which prior knowledge is explicitly incorporated into the fit. The method is commonly described as time-domain/frequency-domain fitting because the spectral components can be represented by time-domain models while the optimization can be performed against the measured data in the frequency domain.

This formulation is attractive for in vivo spectroscopy because it allows physically meaningful constraints to be imposed while still fitting the experimentally observed spectrum. The model can encode expected resonance patterns, amplitudes, frequency shifts, damping, phase, and baseline behavior. Selective frequency-domain fitting can restrict the optimization to spectral regions that are informative for the metabolites or nuisance components of interest.

The original TDFDFit publication is Slotboom, Boesch and Kreis, "Versatile Frequency Domain Fitting Using Time Domain Models and Prior Knowledge", Magnetic Resonance in Medicine 39:899-911 (1998). In that paper, TDFD fitting is presented as an iterative nonlinear least-squares algorithm that fits complex frequency-domain MR spectra using model functions defined in the time domain. This combination gives the method advantages of both domains: handling missing or truncated time-domain data while still allowing direct, multiple frequency-selective fitting in the frequency domain.

Model concept

A simple way to view the TDFDFit approach is that the measured complex signal is represented as a weighted sum of model components plus baseline and residual error:

\[ y(t) = \sum_{k=1}^{K} a_k\,m_k(t; \Delta f_k, d_k, \phi_k) + b(t) + \varepsilon(t) \]

Here, \(m_k\) denotes a modeled metabolite or nuisance component, \(a_k\) its amplitude, \(\Delta f_k\) a frequency shift, \(d_k\) a damping or linewidth-related term, \(\phi_k\) phase, \(b(t)\) baseline contribution, and \(\varepsilon(t)\) the residual. Prior knowledge enters by constraining which parameters are free, linked, bounded, or fixed.

In frequency-domain fitting, the same modeled signal can be compared to the measured spectrum after Fourier transformation, optionally only over selected frequency regions:

\[ \min_{\theta}\; \sum_{f \in \Omega} w_f\,\left|Y(f) - \hat{Y}(f;\theta)\right|^2 \]

Key points from the original TDFDFit paper

Frequency-domain fitting with time-domain models

Slotboom, Boesch and Kreis introduced TDFD fitting as a way to fit frequency-domain MR spectra while calculating the model signal in the time domain. The model is sampled in discrete time, transformed to the frequency domain, and then compared with the measured spectrum. This lets the fit use realistic time-domain signal models while preserving the practical advantages of frequency-domain inspection and selection.

Combines advantages of TD and FD quantification

The paper explicitly positions TDFD fitting between classical time-domain and frequency-domain approaches. Time-domain fitting handles missing initial points and truncated data more naturally; frequency-domain fitting makes it straightforward to fit selected spectral regions. TDFD fitting was designed to keep both advantages in one algorithm.

Multiple frequency-selective fitting

A central strength is the ability to fit one or more selected frequency intervals. This matters when parts of the spectrum are dominated by residual water, lipid resonances, strong nuisance peaks, or poorly modeled regions. The least-squares target can focus on the spectral bands that contain the information needed for a particular metabolite or component.

Prior knowledge is built into the fitting strategy

The paper emphasizes prior knowledge as essential for in vivo spectra with strongly overlapping resonance lines. TDFDFit can encode relationships between amplitudes, resonance frequencies, linewidth-related parameters, and phase terms. This reduces ambiguity and improves the chance of obtaining meaningful fitted parameters from complex spectra.

More than Lorentzian lineshapes

Simple Lorentzian models are often inadequate for in vivo MRS. The original paper describes support for Lorentzian, Gaussian, Voigt, and nonanalytic lineshapes. This is important for living tissue, where susceptibility effects, imperfect shimming, eddy currents, spatially varying metabolite distributions, and lipid frequency distributions can produce nonideal lineshapes.

Experimental reference lineshapes can be incorporated

When analytic lineshape functions do not represent the data well, the paper describes incorporating an experimentally observed reference lineshape directly into the model. This can reduce systematic quantification errors caused by forcing a poor analytic model onto spectra with distorted or broadened resonances.

Arbitrary nonanalytic lineshapes can be fitted

If no suitable reference line is available, the method can estimate a general nonanalytic lineshape function together with the analytic model parameters. The authors note that this is computationally more expensive, but useful for cases where the data cannot be represented accurately by simple analytic lineshapes.

User-defined fitting strategies

TDFDFit was designed so the user can define a fitting strategy as a sequence of steps. Parameters can be fitted in groups, frequency intervals can be changed between steps, and different spectral modes can be fitted, including absorption, dispersion, complex, magnitude, or power spectra. This helps guide the optimizer toward a useful least-squares minimum.

Robustness was a design goal

The paper discusses the risk of local minima in high-dimensional spectral fitting. Robustness is improved through starting values, correct prior knowledge, stepwise fitting strategies, selective fitting regions, and different least-squares forms. Example data showed good fit quality even when deliberately poor starting values were used.

Fit quality and parameter uncertainty

The authors describe not only fitted parameter values but also fit quality and uncertainty estimation. A quality factor was used to detect systematic deviations between model and data, and Cramer-Rao minimum variance bounds were calculated after minimization to estimate parameter uncertainty.

Examples across nuclei and applications

The paper illustrates the method using in vivo 1H, 31P, and 13C MR spectroscopy examples. These examples demonstrate why a flexible fitting engine is valuable: different nuclei and tissues require different prior knowledge, different fitting regions, and different assumptions about lineshape and nuisance components.

Why it is central to spectrIm-QMRS

spectrIm-QMRS builds on this TDFDFit idea: quantitative MRS is not just peak picking, but model-based interpretation of complex spectra. Version 3.0.1 Alpha adds automatic basis-set and model creation plus parallel CPU fitting, making the original TDFDFit methodology more accessible for both clinical and research workflows.

Version 3.0.1 Alpha: Linux and Windows parallel implementation

The multithreaded pthreads-based TDFDFit implementation is a new feature of spectrIm-QMRS 3.0.1 Alpha and is available for both Linux and Windows. The parallel version was tested against the original algorithm and produced digitally identical results, while distributing voxel-wise fitting work over CPU threads.

This is important for scientific continuity. The goal of the parallel implementation is not to change the mathematical fitting result, but to preserve the established TDFDFit behavior while making larger MRSI fitting tasks faster and more practical on modern multicore systems.

Parallel fitting in spectrIm-QMRS 3.0.1 Alpha

Legacy fitting logic

The new implementation keeps the established TDFDFit model concept and prior-knowledge workflow while modernizing the execution path.

CPU parallelization

Fitting jobs can be distributed across CPU threads using a pthreads-based implementation, improving throughput for larger MRSI datasets.

Volume workflow

Parallel fitting is especially useful when the same model must be applied to many voxels in a spectroscopic imaging volume.

Model review

The fitting model remains inspectable and adjustable, so users can review assumptions before applying the model broadly.

Workflow role

1

Prepare data

Load MRS or MRSI data and optionally apply preprocessing such as water removal, lipid removal, or denoising.

4

Review output

Inspect fitted spectra, residuals, parameter estimates, uncertainty information, and metabolite maps.

References

Primary TDFDFit reference: Slotboom J, Boesch C, Kreis R. "Versatile Frequency Domain Fitting Using Time Domain Models and Prior Knowledge." Magnetic Resonance in Medicine 39:899-911 (1998). Related basis-set and linear-combination fitting reference: Hofmann L, Slotboom J, Jung B, Maloca P, Boesch C, Kreis R. "Quantitative 1H-magnetic resonance spectroscopy of human brain: Influence of composition and parameterization of the basis set in linear combination model-fitting", Magnetic Resonance in Medicine, first published 23 August 2002. The ISMRM abstract by Kreis et al. comparing TDFDFit with LCModel will be added when the exact archival reference has been verified. See also the dedicated Citing spectrIm-QMRS page.