ezmsg.sigproc.spectrum#

Functions

spectrum(axis=None, out_axis='freq', window=WindowFunction.HANNING, transform=SpectralTransform.REL_DB, output=SpectralOutput.POSITIVE, norm='forward', do_fftshift=True, nfft=None)[source]#

Calculate a spectrum on a data slice.

Returns:

A SpectrumTransformer object that expects an AxisArray via .(axis_array) (__call__) containing continuous data and returns an AxisArray with data of spectral magnitudes or powers.

Parameters:
Return type:

SpectrumTransformer

Classes

class OptionsEnum(new_class_name, /, names, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: Enum

classmethod options()[source]#
class SpectralOutput(*values)[source]#

Bases: OptionsEnum

The expected spectral contents.

FULL = 'Full Spectrum'#
POSITIVE = 'Positive Frequencies'#
NEGATIVE = 'Negative Frequencies'#
class SpectralTransform(*values)[source]#

Bases: OptionsEnum

Additional transformation functions to apply to the spectral result.

RAW_COMPLEX = 'Complex FFT Output'#
REAL = 'Real Component of FFT'#
IMAG = 'Imaginary Component of FFT'#
REL_POWER = 'Relative Power'#
REL_DB = 'Log Power (Relative dB)'#
class Spectrum(*args, settings=None, **kwargs)[source]#

Bases: BaseTransformerUnit[SpectrumSettings, AxisArray, AxisArray, SpectrumTransformer]

Parameters:

settings (Settings | None)

SETTINGS#

alias of SpectrumSettings

class SpectrumSettings(axis=None, out_axis='freq', window=WindowFunction.HAMMING, transform=SpectralTransform.REL_DB, output=SpectralOutput.POSITIVE, norm='forward', do_fftshift=True, nfft=None)[source]#

Bases: Settings

Settings for Spectrum. See :obj:`spectrum for a description of the parameters.

Parameters:
axis: str | None = None#

The name of the axis on which to calculate the spectrum. Note: The axis must have an .axes entry of type LinearAxis, not CoordinateAxis.

out_axis: str | None = 'freq'#

The name of the new axis. Defaults to “freq”. If none; don’t change dim name

window: WindowFunction = 'Hamming'#

The WindowFunction to apply to the data slice prior to calculating the spectrum.

transform: SpectralTransform = 'Log Power (Relative dB)'#

The SpectralTransform to apply to the spectral magnitude.

output: SpectralOutput = 'Positive Frequencies'#

The SpectralOutput format.

norm: str | None = 'forward'#

Normalization mode. Default “forward” is best used when the inverse transform is not needed, for example when the goal is to get spectral power. Use “backward” (equivalent to None) to not scale the spectrum which is useful when the spectra will be manipulated and possibly inverse-transformed. See numpy.fft.fft for details.

do_fftshift: bool = True#

Whether to apply fftshift to the output. Default is True. This value is ignored unless output is SpectralOutput.FULL.

nfft: int | None = None#

The number of points to use for the FFT. If None, the length of the input data is used.

__init__(axis=None, out_axis='freq', window=WindowFunction.HAMMING, transform=SpectralTransform.REL_DB, output=SpectralOutput.POSITIVE, norm='forward', do_fftshift=True, nfft=None)#
Parameters:
Return type:

None

class SpectrumState[source]#

Bases: object

f_sl: slice | None = None#
freq_axis: LinearAxis | None = None#
fftfun: Callable | None = None#
f_transform: Callable | None = None#
new_dims: list[str] | None = None#
window: ndarray[tuple[Any, ...], dtype[_ScalarT]] | None = None#
class SpectrumTransformer(*args, **kwargs)[source]#

Bases: BaseStatefulTransformer[SpectrumSettings, AxisArray, AxisArray, SpectrumState]

class WindowFunction(*values)[source]#

Bases: OptionsEnum

Windowing function prior to calculating spectrum.

NONE = 'None (Rectangular)'#

None.

HAMMING = 'Hamming'#

numpy.hamming

HANNING = 'Hanning'#

numpy.hanning

BARTLETT = 'Bartlett'#

numpy.bartlett

BLACKMAN = 'Blackman'#

numpy.blackman

class OptionsEnum(new_class_name, /, names, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: Enum

classmethod options()[source]#
class WindowFunction(*values)[source]#

Bases: OptionsEnum

Windowing function prior to calculating spectrum.

NONE = 'None (Rectangular)'#

None.

HAMMING = 'Hamming'#

numpy.hamming

HANNING = 'Hanning'#

numpy.hanning

BARTLETT = 'Bartlett'#

numpy.bartlett

BLACKMAN = 'Blackman'#

numpy.blackman

class SpectralTransform(*values)[source]#

Bases: OptionsEnum

Additional transformation functions to apply to the spectral result.

RAW_COMPLEX = 'Complex FFT Output'#
REAL = 'Real Component of FFT'#
IMAG = 'Imaginary Component of FFT'#
REL_POWER = 'Relative Power'#
REL_DB = 'Log Power (Relative dB)'#
class SpectralOutput(*values)[source]#

Bases: OptionsEnum

The expected spectral contents.

FULL = 'Full Spectrum'#
POSITIVE = 'Positive Frequencies'#
NEGATIVE = 'Negative Frequencies'#
class SpectrumSettings(axis=None, out_axis='freq', window=WindowFunction.HAMMING, transform=SpectralTransform.REL_DB, output=SpectralOutput.POSITIVE, norm='forward', do_fftshift=True, nfft=None)[source]#

Bases: Settings

Settings for Spectrum. See :obj:`spectrum for a description of the parameters.

Parameters:
axis: str | None = None#

The name of the axis on which to calculate the spectrum. Note: The axis must have an .axes entry of type LinearAxis, not CoordinateAxis.

out_axis: str | None = 'freq'#

The name of the new axis. Defaults to “freq”. If none; don’t change dim name

window: WindowFunction = 'Hamming'#

The WindowFunction to apply to the data slice prior to calculating the spectrum.

transform: SpectralTransform = 'Log Power (Relative dB)'#

The SpectralTransform to apply to the spectral magnitude.

output: SpectralOutput = 'Positive Frequencies'#

The SpectralOutput format.

norm: str | None = 'forward'#

Normalization mode. Default “forward” is best used when the inverse transform is not needed, for example when the goal is to get spectral power. Use “backward” (equivalent to None) to not scale the spectrum which is useful when the spectra will be manipulated and possibly inverse-transformed. See numpy.fft.fft for details.

do_fftshift: bool = True#

Whether to apply fftshift to the output. Default is True. This value is ignored unless output is SpectralOutput.FULL.

nfft: int | None = None#

The number of points to use for the FFT. If None, the length of the input data is used.

__init__(axis=None, out_axis='freq', window=WindowFunction.HAMMING, transform=SpectralTransform.REL_DB, output=SpectralOutput.POSITIVE, norm='forward', do_fftshift=True, nfft=None)#
Parameters:
Return type:

None

class SpectrumState[source]#

Bases: object

f_sl: slice | None = None#
freq_axis: LinearAxis | None = None#
fftfun: Callable | None = None#
f_transform: Callable | None = None#
new_dims: list[str] | None = None#
window: ndarray[tuple[Any, ...], dtype[_ScalarT]] | None = None#
class SpectrumTransformer(*args, **kwargs)[source]#

Bases: BaseStatefulTransformer[SpectrumSettings, AxisArray, AxisArray, SpectrumState]

class Spectrum(*args, settings=None, **kwargs)[source]#

Bases: BaseTransformerUnit[SpectrumSettings, AxisArray, AxisArray, SpectrumTransformer]

Parameters:

settings (Settings | None)

SETTINGS#

alias of SpectrumSettings

spectrum(axis=None, out_axis='freq', window=WindowFunction.HANNING, transform=SpectralTransform.REL_DB, output=SpectralOutput.POSITIVE, norm='forward', do_fftshift=True, nfft=None)[source]#

Calculate a spectrum on a data slice.

Returns:

A SpectrumTransformer object that expects an AxisArray via .(axis_array) (__call__) containing continuous data and returns an AxisArray with data of spectral magnitudes or powers.

Parameters:
Return type:

SpectrumTransformer