|
| 1 | +""" |
| 2 | +Periodic Parameters |
| 3 | +=================== |
| 4 | +
|
| 5 | +Exploring properties and topics related to peak parameters. |
| 6 | +""" |
| 7 | + |
| 8 | +################################################################################################### |
| 9 | + |
| 10 | +from fooof import FOOOF, FOOOFGroup |
| 11 | +from fooof.plts.spectra import plot_spectra |
| 12 | +from fooof.plts.periodic import plot_peak_params |
| 13 | +from fooof.sim.utils import set_random_seed |
| 14 | +from fooof.sim.params import Stepper, param_iter |
| 15 | +from fooof.sim import gen_power_spectrum, gen_group_power_spectra |
| 16 | +from fooof.plts.annotate import plot_annotated_model |
| 17 | +from fooof.utils.params import compute_time_constant, compute_knee_frequency |
| 18 | + |
| 19 | +################################################################################################### |
| 20 | +# Gaussian Peak Model |
| 21 | +# ------------------- |
| 22 | +# |
| 23 | +# By default, the spectral parameterization model fits Gaussians to any detected peaks. |
| 24 | +# |
| 25 | +# These Gaussians are defined by a mean, height, and standard deviation, which we in turn |
| 26 | +# interpret as the center frequency (CF), power (PW), and bandwidth (BW) of the putative |
| 27 | +# oscillation. |
| 28 | +# |
| 29 | +# In this example, we will further explore these peak parameters and some topics and |
| 30 | +# limitations related to their use and interpretations. |
| 31 | +# |
| 32 | + |
| 33 | +################################################################################################### |
| 34 | + |
| 35 | +# Simulate an example power spectrum |
| 36 | +freqs, powers = gen_power_spectrum([3, 40], [0, 1], [10, 0.3, 1.], freq_res=0.25) |
| 37 | + |
| 38 | +################################################################################################### |
| 39 | + |
| 40 | +# Initialize model object and fit power spectrum |
| 41 | +fm = FOOOF(min_peak_height=0.1) |
| 42 | +fm.fit(freqs, powers) |
| 43 | + |
| 44 | +################################################################################################### |
| 45 | + |
| 46 | +# Plot annotated model labelling the peaks |
| 47 | +plot_annotated_model(fm, annotate_peaks=True, annotate_aperiodic=False, plt_log=True) |
| 48 | + |
| 49 | +################################################################################################### |
| 50 | +# |
| 51 | +# In the above we can see an example of the fit peak parameters |
| 52 | +# |
| 53 | + |
| 54 | +################################################################################################### |
| 55 | +# Overlapping Peaks |
| 56 | +# ----------------- |
| 57 | +# |
| 58 | +# Let's now consider some features of fitting Gaussian peaks, and how this relates to |
| 59 | +# the neural data under study. In particular, Gaussian's are symmetric and while they do |
| 60 | +# seem to approximate the peaks we observe in emprical data quite well, not all peaks |
| 61 | +# in empirical power spectra are quite symmetric. |
| 62 | +# |
| 63 | +# To deal with this, the model sometimes fits overlapping peaks, whereby two or more peaks |
| 64 | +# are used by the model to capture the shape of what otherwise looks like a single peak. |
| 65 | +# |
| 66 | +# We can explore this in a simplified simulation. |
| 67 | +# |
| 68 | + |
| 69 | +################################################################################################### |
| 70 | + |
| 71 | +# Set the random seed |
| 72 | +set_random_seed(10) |
| 73 | + |
| 74 | +################################################################################################### |
| 75 | + |
| 76 | +# Simulate an example power spectrum created with an asymmetric peak |
| 77 | +freqs, powers = gen_power_spectrum([3, 40], [0, 1], [[10, 0.3, 1.], [11.25, 0.175, 0.5]], freq_res=0.25) |
| 78 | + |
| 79 | +################################################################################################### |
| 80 | + |
| 81 | +# Initialize model object and fit power spectrum |
| 82 | +fm = FOOOF(min_peak_height=0.1) |
| 83 | +fm.report(freqs, powers) |
| 84 | + |
| 85 | +################################################################################################### |
| 86 | +# |
| 87 | +# As we can see in the above model solution, in the data, it looks like there is a single |
| 88 | +# oscillatory peak, and yet the model has captured this peak with two Gaussians. |
| 89 | +# |
| 90 | +# This example serves to demonstrate two key points. First, not all Gaussians fit in the model |
| 91 | +# necessary reflect separate peaks, as some may overlap. Second, when peaks overlap, |
| 92 | +# the parameters of each individually may accurately capture a peak in the data, as the |
| 93 | +# overall shape of the peak may be captured as the interaction across multiple Gaussians |
| 94 | +# (this is most common / notable for the bandwidth measure, whereby the width of the peak is |
| 95 | +# best described as the combined width of the two adjacent peaks). |
| 96 | +# |
| 97 | +# Note that, by construction, this simulated example was created by simulating two overlapping |
| 98 | +# peaks, and so in that sense the model is actually correct in it's solution. In empirical |
| 99 | +# data, we do not know if a power spectrum that looks like this does reflect two underlying |
| 100 | +# oscillatory processes, or perhaps a single oscillatory process that happens to be asymmetric |
| 101 | +# in the frequency domain. |
| 102 | +# |
0 commit comments