spectrochempy.PSD

class PSD(*, log_level='WARNING', demodulation='matrix', harmonic=1, integration_rule='trapezoid', n_spectra_per_cycle=None, phase_unit='degrees', phi)[source]

PSD (Phase-Sensitive Detection) for demodulating spectroscopic data.

PSD is a deterministic signal-processing transform, analogous to FFT or Hilbert transforms. It does not learn from data and stores no model state.

Supports two demodulation strategies:

  1. Matrix transform demodulation: A_demodulated = T · A_averaged

  2. Explicit integration demodulation: A_demodulated(φ, λ) = (2/period) A_averaged(t, λ) · sin(k·ω·t + φ) dt

Parameters:
  • Demodulation strategy. Matrix demodulation is the default because it is generally faster for trapezoid and

  • Simpson rules, while producing results equivalent to explicit integration.

  • Number of spectra per cycle. If None, inferred from data shape.

  • Demodulation harmonic index (k in sin(k*ω*t + phi)).

  • Phase angles for demodulation (in degrees).

  • Integration rule for numerical integration weights.

  • ``”riemann”`` uses a right-endpoint rectangular rule over n equal

  • subintervals of [0, 1], sampling at ``t = (i+1)/n``. This rule

  • gives exact results for pure sinusoids at any n.

  • Unit for phase output.

demodulation : any value of ['matrix', 'integration'], optional, default: 'matrix'

harmonicint, optional, default: 1

Demodulation harmonic index.

integration_rule : any value of ['riemann', 'trapezoid', 'simpson'], optional, default: 'trapezoid'

n_spectra_per_cycleint, optional, default: None

Number of spectra per cycle.

phase_unit : any value of ['degrees', 'radians'], optional, default: 'degrees'

phia list or a numpy array, optional, default: None

Phase angles for demodulation (in degrees).

Notes

  • Requires phi to contain 0° and 90° for in_phase/quadrature extraction.

  • Matrix demodulation is default and faster.

  • Integration demodulation uses explicit numerical integration with a configurable integration rule.

  • The "riemann" rule uses a right-endpoint rectangular grid t = (i+1)/n independent of the actual time coordinate; for irregular time coordinates use "trapezoid" or "simpson".

  • Constant offsets (DC) do not affect the PSD result because sinusoidal demodulation functions integrate to zero over one complete modulation period. No explicit mean subtraction is necessary.

Math notation:

  • T = transform matrix (shape: n_phi × n_spectra_per_cycle)

  • period = modulation period (from time coordinate)

  • ω = 2π / period (angular frequency)

  • harmonic = k (demodulation harmonic index)

PSD equation (matrix method):

A_demodulated = T · A_averaged

where A_averaged has shape (n_spectra_per_cycle, n_channels), averaged across all cycles.

PSD equation (integration method):

A_demodulated (φ, λ) = (2/period) ∫ A_averaged(t, λ) · sin(k·ω·t_rel + φ) dt

where φ is the demodulation phase angle, λ is the channel, and t_rel is normalized relative time within one modulation period (t_rel = 0 at the start of the period, t_rel = 1 at the end).

Examples

>>> import spectrochempy as scp
>>> import numpy as np
>>> # Raw 2D input (120 spectra, 1000 channels)
>>> X = scp.NDDataset(np.random.rand(120, 1000))
>>> psd = scp.PSD(n_spectra_per_cycle=60, demodulation='matrix')
>>> result = psd.transform(X)
>>> result.in_phase
>>> result.quadrature
>>> result.amplitude
>>> result.phase

Initialize the BaseConfigurable class.

Parameters:
  • log_level (int, optional) – The log level at startup. Default is logging.WARNING.

  • **kwargs (dict) – Additional keyword arguments for configuration.

Attributes Summary

config

traitlets.config.Config object.

demodulation

An enum whose value must be in a given sequence.

harmonic

Demodulation harmonic index.

integration_rule

An enum whose value must be in a given sequence.

log

Return log output.

n_spectra_per_cycle

Number of spectra per cycle.

name

Object name

phase_unit

An enum whose value must be in a given sequence.

phi

Phase angles for demodulation (in degrees).

Methods Summary

inverse_transform([X_transform])

Inverse transform is not supported for PSD.

parameters([replace, removed, default])

Alias for params method.

params([default])

Return current or default configuration values.

reset()

Reset configuration parameters to their default values.

to_dict()

Return config value in a dict form.

transform(X)

Apply the PSD transform to data X.

Attributes Documentation

config

traitlets.config.Config object.

demodulation

An enum whose value must be in a given sequence.

harmonic

Demodulation harmonic index.

integration_rule

An enum whose value must be in a given sequence.

log

Return log output.

n_spectra_per_cycle

Number of spectra per cycle.

name

Object name

phase_unit

An enum whose value must be in a given sequence.

phi

Phase angles for demodulation (in degrees).

Methods Documentation

inverse_transform(X_transform=None, **kwargs)[source]

Inverse transform is not supported for PSD.

Raises:

NotImplementedError – Always raised as PRS is not invertible.

parameters(replace="params", removed="0.8.0") def parameters(self, default=False)[source]

Alias for params method.

Deprecated since version 0.8.0: Use params instead.

params(default=False)[source]

Return current or default configuration values.

Parameters:

default (bool, optional, default: False) – If default is True, the default parameters are returned, else the current values.

Returns:

dict – Current or default configuration values.

reset()[source]

Reset configuration parameters to their default values.

to_dict()[source]

Return config value in a dict form.

Returns:

dict – A regular dictionary.

transform(X)[source]

Apply the PSD transform to data X.

All inputs are internally normalized into a single cycle-averaged 2D modulation waveform A(t, ν) before demodulation.

This is a pure computation that does not mutate internal state. Repeated calls are independent and thread-safe.

Parameters:

X (NDDataset or array-like) – Input data for PSD.

Returns:

PSDResult – Container with prs, in_phase, quadrature, amplitude, phase, and T.

Examples using spectrochempy.PSD