spinguin.core.specutils#
This module provides core functions for spectral data analysis, including Fourier transforms, spectrum generation, and unit conversions commonly used in NMR and signal processing.
- fourier_transform(signal: ndarray, dt: float, normalize: bool = True) tuple[ndarray, ndarray] [source]#
Computes the Fourier transform of a given time-domain signal and returns the corresponding frequency-domain representation. The Fourier transform can be normalized to ensure consistent peak intensities regardless of the time step.
- Parameters:
signal (ndarray) – Input signal in the time domain.
dt (float) – Time step between consecutive samples in the signal.
normalize (bool, default=True) – Whether to normalize the Fourier transform.
- Returns:
freqs (ndarray) – Frequencies corresponding to the Fourier-transformed signal.
fft_signal (ndarray) – Fourier-transformed signal in the frequency domain (normalized if specified).
- frequency_to_chemical_shift(frequency: float | ndarray, reference_frequency: float, spectrometer_frequency: float) float | ndarray [source]#
Converts a frequency (or an array of frequencies, e.g., a frequency axis) to a chemical shift value based on the reference frequency and the spectrometer frequency.
- Parameters:
frequency (float or ndarray) – Frequency (or array of frequencies) to convert [in Hz].
reference_frequency (float) – Reference frequency for the conversion [in Hz].
spectrometer_frequency (float) – Spectrometer frequency for the conversion [in Hz].
- Returns:
chemical_shift – Converted chemical shift value (or array of values).
- Return type:
float or ndarray
- resonance_frequency(isotope: str, B: float, delta: float = 0, unit: Literal['Hz', 'rad/s'] = 'Hz') float [source]#
Computes the resonance frequency of a nucleus at specified magnetic field and chemical shift.
- Parameters:
isotope (str) – Nucleus symbol (e.g. ‘1H’) used to select the gyromagnetic ratio.
B (float) – Magnetic field strength in the units of T.
delta (float, default=0) – Chemical shift in ppm.
unit ({'Hz', 'rad/s'}) – Specifies in which units the frequency is returned.
- Returns:
omega – Resonance frequency of the given nucleus.
- Return type:
float
- spectral_width_to_dwell_time(spectral_width: float, isotope: str, B: float) float [source]#
Calculates the dwell time (in seconds) from the spectral width given in ppm.
- Parameters:
spectral_width (float) – Spectral width in ppm.
isotope (str) – Nucleus symbol (e.g. ‘1H’) used to select the gyromagnetic ratio required for the conversion.
B (float) – Magnetic field of the spectrometer in T.
- Returns:
dwell_time – Dwell time in seconds.
- Return type:
float
- spectrum(signal: ndarray, dt: float, normalize: bool = True, part: Literal['real', 'imag'] = 'real') tuple[ndarray, ndarray] [source]#
A wrapper function for the Fourier transform. Computes the Fourier transform and returns the frequency and spectrum (either the real or imaginary part of the Fourier transform).
- Parameters:
signal (ndarray) – Input signal in the time domain.
dt (float) – Time step between consecutive samples in the signal.
normalize (bool, default=True) – Whether to normalize the Fourier transform.
part ({'real', 'imag'}) – Specifies which part of the Fourier transform to return. Can be “real” or “imag”.
- Returns:
freqs (ndarray) – Frequencies corresponding to the Fourier-transformed signal.
spectrum (ndarray) – Specified part (real or imaginary) of the Fourier-transformed signal in the frequency domain.