diff --git a/specparam/modes/definitions.py b/specparam/modes/definitions.py index bdb5c8c4..8961d636 100644 --- a/specparam/modes/definitions.py +++ b/specparam/modes/definitions.py @@ -79,6 +79,28 @@ powers_space='log10', ) +## AP - Knee with Constant Mode + +params_knee_constant = ParamDefinition(OrderedDict({ + 'offset' : 'Offset of the aperiodic component.', + 'exponent' : 'Exponent of the aperiodic component.', + 'knee' : 'Knee of the aperiodic component.', + 'constant' : 'Constant value which the aperiodic component decays to, after the exponent.', +})) + +ap_knee_constant = Mode( + name='knee_constant', + component='aperiodic', + description='Fit a Lorentzian function that decays to a constant.', + formula=r'XX', + func=knee_constant_function, + jacobian=None, + params=params_knee_constant, + ndim=1, + freq_space='linear', + powers_space='log10', +) + # Collect available aperiodic modes AP_MODES = { diff --git a/specparam/modes/funcs.py b/specparam/modes/funcs.py index 1d8bd078..dba4aac4 100644 --- a/specparam/modes/funcs.py +++ b/specparam/modes/funcs.py @@ -344,6 +344,31 @@ def double_expo_function(xs, *params): return ys +def knee_constant_function(xs, *params): + """Knee function with a constant, for fitting aperiodic component. + + Parameters + ---------- + xs : 1d array + Input x-axis values. + *params : float + Parameters (offset, exp, knee, constant) that define the function. + + Returns + ------- + ys : 1d array + Output values for the fit function. + """ + + ys = np.zeros_like(xs) + + offset, exp, knee, constant = params + + ys = ys + offset - np.log10(1 / (knee**(exp) + xs**(exp)) + constant) + + return ys + + def linear_function(xs, *params): r"""Linear fitting function.