specparam.sim.sim_power_spectrum

specparam.sim.sim_power_spectrum(freq_range, aperiodic_params, periodic_params, nlv=0.005, freq_res=0.5, f_rotation=None, return_params=False)[source]

Simulate a power spectrum.

Parameters:
freq_rangelist of [float, float]

Frequency range to simulate power spectrum across, as [f_low, f_high], inclusive.

aperiodic_paramslist of float

Parameters to create the aperiodic component of a power spectrum. Length should be 2 or 3 (see note).

periodic_paramslist of float or list of list of float

Parameters to create the periodic component of a power spectrum. Total length of n_peaks * 3 (see note).

nlvfloat, optional, default: 0.005

Noise level to add to generated power spectrum.

freq_resfloat, optional, default: 0.5

Frequency resolution for the simulated power spectrum.

f_rotationfloat, optional

Frequency value, in Hz, to rotate around. Should only be set if spectrum is to be rotated.

return_paramsbool, optional, default: False

Whether to return the parameters for the simulated spectrum.

Returns:
freqs1d array

Frequency values, in linear spacing.

powers1d array

Power values, in linear spacing.

sim_paramsSimParams

Definition of parameters used to create the spectrum. Only returned if return_params is True.

Notes

Aperiodic Parameters:

  • The function for the aperiodic process to use is inferred from the provided parameters.

  • If length of 2, the ‘fixed’ aperiodic mode is used, if length of 3, ‘knee’ is used.

Periodic Parameters:

  • The periodic component is comprised of a set of ‘peaks’, each of which is described as:

    • Mean (Center Frequency), height (Power), and standard deviation (Bandwidth).

    • Make sure any center frequencies you request are within the simulated frequency range.

  • The total number of parameters that need to be specified is number of peaks * 3

    • These can be specified in as all together in a flat list (ex: [10, 1, 1, 20, 0.5, 1])

    • They can also be grouped into a list of lists (ex: [[10, 1, 1], [20, 0.5, 1]])

Rotating Power Spectra:

  • You can optionally specify a rotation frequency, such that power spectra will be simulated and rotated around that point to the specified aperiodic exponent.

    • This can be used so that any power spectra simulated with the same ‘f_rotation’ will relate to each other by having the specified rotation point.

  • Note that rotating power spectra changes the offset.

    • If you specify an offset value to simulate as well as ‘f_rotation’, the returned spectrum will NOT have the requested offset. It instead will have the offset value required to create the requested aperiodic exponent with the requested rotation point.

    • If you return SimParams, the recorded offset will be the calculated offset of the data post rotation, and not the entered value.

  • You cannot rotate power spectra simulated with a knee.

    • The procedure we use to rotate does not support spectra with a knee, and so setting ‘f_rotation’ with a knee will lead to an error.

Examples

Generate a power spectrum with a single peak, at 10 Hz:

>>> freqs, powers = sim_power_spectrum([1, 50], [0, 2], [10, 0.5, 1])

Generate a power spectrum with alpha and beta peaks:

>>> freqs, powers = sim_power_spectrum([1, 50], [0, 2], [[10, 0.5, 1], [20, 0.5, 1]])

Generate a power spectrum, that was rotated around a particular frequency point:

>>> freqs, powers = sim_power_spectrum([1, 50], [None, 2], [10, 0.5, 1], f_rotation=15)

Examples using specparam.sim.sim_power_spectrum

Dealing with Line Noise

Dealing with Line Noise

Exporting Model Results

Exporting Model Results

Manipulating Objects

Manipulating Objects

Aperiodic Parameters

Aperiodic Parameters

Exploring Data Components

Exploring Data Components

Frequency-by-Frequency Errors

Frequency-by-Frequency Errors

Periodic Parameters

Periodic Parameters

Plot Power Spectrum Models

Plot Power Spectrum Models

Plot Power Spectra

Plot Power Spectra

Simulation Parameters

Simulation Parameters

Simulating Neural Power Spectra

Simulating Neural Power Spectra

Transforming Power Spectra

Transforming Power Spectra

01: Model Description

01: Model Description

07: Tuning & Troubleshooting

07: Tuning & Troubleshooting

09: Reporting & Referencing

09: Reporting & Referencing

Band-by-Band

Band-by-Band

Band Ratio Measures

Band Ratio Measures

Conflating Periodic & Aperiodic Changes

Conflating Periodic & Aperiodic Changes