Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions specparam/modes/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
25 changes: 25 additions & 0 deletions specparam/modes/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Loading