# Import required code for visualizing example models
from fooof import FOOOF
from fooof.sim.gen import gen_power_spectrum
from fooof.sim.utils import set_random_seed
from fooof.plts.spectra import plot_spectra
from fooof.plts.annotate import plot_annotated_model
Aperiodic exponent example
Let’s try this example code.
# Set random seed, for consistency generating simulated data
21)
set_random_seed(
# Simulate example power spectra
= gen_power_spectrum([3, 40], [1, 1],
freqs1, powers1 10, 0.2, 1.25], [30, 0.15, 2]])
[[= gen_power_spectrum([1, 150], [1, 125, 1.25],
freqs2, powers2 8, 0.15, 1.], [30, 0.1, 2]]) [[
# Initialize power spectrum model objects and fit the power spectra
= FOOOF(min_peak_height=0.05, verbose=False)
fm1 = FOOOF(min_peak_height=0.05, aperiodic_mode='knee', verbose=False)
fm2
fm1.fit(freqs1, powers1) fm2.fit(freqs2, powers2)
# Plot one of the example power spectra
=True,
plot_spectra(freqs1, powers1, log_powers='black', label='Original Spectrum') color
# Plot an example power spectrum, with a model fit
='shade', peak_kwargs={'color' : 'green'}) fm1.plot(plot_peaks
# Plot an annotated version of the power spectrum model
=False) plot_annotated_model(fm1, annotate_aperiodic
# Report: fit the model, print the resulting parameters, and plot the reconstruction
fm1.report()