specparam.sim.transform.rotate_spectrum

specparam.sim.transform.rotate_spectrum(freqs, power_spectrum, delta_exponent, f_rotation)[source]

Rotate a power spectrum about a frequency point, changing the aperiodic exponent.

Parameters:
freqs1d array

Frequency axis of input power spectrum, in Hz.

power_spectrum1d array

Power values of the spectrum.

delta_exponentfloat

Change in aperiodic exponent to be applied, where:

  • positive is clockwise rotation (steepen)

  • negative is counterclockwise rotation (flatten)

f_rotationfloat

Frequency value, in Hz, about which rotation is applied, at which power is unchanged.

Returns:
rotated_spectrum1d array

Rotated power spectrum.

Raises:
ValueError

If the rotation frequency is invalid.

Notes

Rotating in log-log spacing is equivalent to multiplying with a 1/f shaped mask that is:

  • unity at the rotation frequency

  • has an exponent of the desired delta exponent

This mask, when applied to a spectrum as ‘spectrum * mask’, should result in:

  • rotated_spectrum = 1/f^(original_exponent + delta_exponent), where

  • spectrum[rotation_frequency] == rotated spectrum[rotation_frequency]

This mask is defined as:

  • mask = (freqs / rotation_frequency) ** -delta_exponent

Note that this approach / function should only be applied to spectra without a knee:

  • If using simulated data, this is spectra created in ‘fixed’ mode.

  • This is because the rotation applied is inconsistent with the formulation of spectra with a knee. This transformation will change them in an unspecified way, not just limited to doing the rotation.

Examples

Rotate a simulated spectrum, changing the exponent around a rotation point of 25 Hz:

>>> from specparam.sim import sim_power_spectrum
>>> freqs, powers = sim_power_spectrum([1, 50], [1, 1], [10, 0.5, 1])
>>> rotated_powers = rotate_spectrum(freqs, powers, 0.5, 25)

Examples using specparam.sim.transform.rotate_spectrum

Transforming Power Spectra

Transforming Power Spectra