DSPark 1.9.0
Header-only C++20 DSP for real-time and offline audio
Loading...
Searching...
No Matches
dspark::Hysteresis< T > Class Template Reference

Per-channel Jiles-Atherton hysteresis processor (field in, M out). More...

#include <Hysteresis.h>

Public Member Functions

void prepare (double sampleRate)
 Prepares the integrator for the given sample rate. A non-positive or non-finite rate is ignored (NaN used to pass the old <= 0 test and poison the integrator).
 
void reset () noexcept
 Clears magnetization and integrator state. RT-safe.
 
void setParameters (double ms, double a, double alpha, double k, double c) noexcept
 Sets the Jiles-Atherton parameters.
 
void setTolerance (double relative) noexcept
 Where the solver stops: a Newton step under this share of Ms.
 
void setPredictorPeriod (int period) noexcept
 The period of the field in samples, for the predictor (0, the default, for none). With a field that repeats itself every period samples beside a slower programme (a bias carrier), the Newton steps start from dM/dt at the same phase of the last two periods, carried on in a line, in place of the last one: fewer steps, the same answer within the tolerance.
 
int getPredictorPeriod () const noexcept
 
double getSaturation () const noexcept
 Saturation magnetization Ms (A/m).
 
double getSmallSignalSusceptibility () const noexcept
 Small-signal susceptibility dM/dH around the demagnetized state.
 
T processSample (T fieldH) noexcept
 Processes one sample of applied field H, returns magnetization M.
 

Static Public Attributes

static constexpr int kMaxPeriod = 8
 The longest period the predictor follows.
 

Detailed Description

template<FloatType T>
class dspark::Hysteresis< T >

Per-channel Jiles-Atherton hysteresis processor (field in, M out).

Template Parameters
TSample type of the audio interface (internal math is double).

Definition at line 72 of file Hysteresis.h.

Member Function Documentation

◆ getPredictorPeriod()

template<FloatType T>
int dspark::Hysteresis< T >::getPredictorPeriod ( ) const
inlinenoexcept
Returns
The period the predictor follows (0: none).

Definition at line 159 of file Hysteresis.h.

◆ getSaturation()

template<FloatType T>
double dspark::Hysteresis< T >::getSaturation ( ) const
inlinenoexcept

Saturation magnetization Ms (A/m).

Definition at line 162 of file Hysteresis.h.

◆ getSmallSignalSusceptibility()

template<FloatType T>
double dspark::Hysteresis< T >::getSmallSignalSusceptibility ( ) const
inlinenoexcept

Small-signal susceptibility dM/dH around the demagnetized state.

The reversible-branch slope c*chi_an/(1 - c*alpha*chi_an), chi_an = Ms/(3a). Used by consumers (TapeMachine) for exact small-signal gain makeup.

Definition at line 170 of file Hysteresis.h.

◆ prepare()

template<FloatType T>
void dspark::Hysteresis< T >::prepare ( double  sampleRate)
inline

Prepares the integrator for the given sample rate. A non-positive or non-finite rate is ignored (NaN used to pass the old <= 0 test and poison the integrator).

Definition at line 78 of file Hysteresis.h.

◆ processSample()

template<FloatType T>
T dspark::Hysteresis< T >::processSample ( T  fieldH)
inlinenoexcept

Processes one sample of applied field H, returns magnetization M.

Parameters
fieldHApplied magnetic field (A/m scale of the JA parameters).

Definition at line 180 of file Hysteresis.h.

◆ reset()

template<FloatType T>
void dspark::Hysteresis< T >::reset ( )
inlinenoexcept

Clears magnetization and integrator state. RT-safe.

Definition at line 87 of file Hysteresis.h.

◆ setParameters()

template<FloatType T>
void dspark::Hysteresis< T >::setParameters ( double  ms,
double  a,
double  alpha,
double  k,
double  c 
)
inlinenoexcept

Sets the Jiles-Atherton parameters.

Defaults follow the audio-tape calibration from the DAFx literature.

Parameters
msSaturation magnetization (A/m). [3.5e5]
aAnhysteretic shape parameter (A/m). [2.2e4]
alphaInter-domain coupling. [1.6e-3]
kCoercivity / loop-loss parameter (A/m). [2.7e4]
cReversible magnetization fraction [0, 1). [1.7e-1]

A call with any non-finite argument is ignored. Range clamping alone does not reject NaN, which would otherwise poison the integrator.

Definition at line 112 of file Hysteresis.h.

◆ setPredictorPeriod()

template<FloatType T>
void dspark::Hysteresis< T >::setPredictorPeriod ( int  period)
inlinenoexcept

The period of the field in samples, for the predictor (0, the default, for none). With a field that repeats itself every period samples beside a slower programme (a bias carrier), the Newton steps start from dM/dt at the same phase of the last two periods, carried on in a line, in place of the last one: fewer steps, the same answer within the tolerance.

Parameters
period0, or 1 to kMaxPeriod samples (others are ignored).

Definition at line 152 of file Hysteresis.h.

◆ setTolerance()

template<FloatType T>
void dspark::Hysteresis< T >::setTolerance ( double  relative)
inlinenoexcept

Where the solver stops: a Newton step under this share of Ms.

At the default (1e-9) the model is evaluated once more at the point reached. A looser stop takes that last evaluation from the slope of the step just made, and from the second step on stops as well when what is left, read from the rate the steps shrink at (a cube over a square, as Newton's), is under it. A non-finite or non-positive value is ignored.

Parameters
relativeThe share of Ms, 1e-12 to 1e-3.

Definition at line 136 of file Hysteresis.h.

Member Data Documentation

◆ kMaxPeriod

template<FloatType T>
constexpr int dspark::Hysteresis< T >::kMaxPeriod = 8
staticconstexpr

The longest period the predictor follows.

Definition at line 345 of file Hysteresis.h.


The documentation for this class was generated from the following file: