def plot_spectra(self, result_index, f_range=(1, 100), figsize=(8, 8)): if self.results[result_index].sig_pe is None or self.results[ result_index].sig_ap is None: self.decompose() # Compute spectra freqs, powers = compute_spectrum(self.sig, self.fs, f_range=f_range) freqs_pe, powers_pe = compute_spectrum( self.results[result_index].sig_pe, self.fs, f_range=f_range) freqs_ap, powers_ap = compute_spectrum( self.results[result_index].sig_ap, self.fs, f_range=f_range) # Plot _, ax = plt.subplots(figsize=figsize) plot_power_spectra(freqs, [powers, powers_pe, powers_ap], title="Reconstructed Components", labels=['Orig', 'PE Recon', 'AP Recon'], ax=ax, alpha=[0.7, 0.7, 0.7], lw=3)
################################################################################################### # Calculate the power spectrum, using a median welch & extract a frequency range of interest freqs, powers = compute_spectrum(sig, fs, method='welch', avg_type='median') freqs, powers = trim_spectrum(freqs, powers, [3, 30]) ################################################################################################### # Check where the peak power is peak_cf = freqs[np.argmax(powers)] print(peak_cf) ################################################################################################### # Plot the power spectra, and note the peak power plot_power_spectra(freqs, powers) plt.plot(freqs[np.argmax(powers)], np.max(powers), '.r', ms=12) ################################################################################################### # Look for Bursts # --------------- # # Now that we have a sense of the main rhythmicity of this piece of data, lets # explore using NeuroDSP to investigate whether this rhythm is bursty. # ################################################################################################### # Burst settings amp_dual_thresh = (1., 1.5) f_range = (peak_cf - 2, peak_cf + 2)
# Define the frequency range of interest for the analysis f_range = (1, 40) # Create the simulate time series sig = sim_combined(n_seconds, fs, components) ################################################################################################### # Compute the power spectrum of the simulated signal freqs, psd = compute_spectrum(sig, fs, nperseg=4 * fs) # Trim the power spectrum to the frequency range of interest freqs, psd = trim_spectrum(freqs, psd, f_range) # Plot the computed power spectrum plot_power_spectra(freqs, psd, title="Original Spectrum") ################################################################################################### # # In the above spectrum, we can see a pattern of power across all frequencies, which reflects # the 1/f activity, as well as a peak at 10 Hz, which represents the simulated oscillation. # ################################################################################################### # IRASA # ----- # # In the analysis of neural data, we may want to separate aperiodic and periodic components # of the data. Here, we explore using IRASA to do so. # # Algorithm Settings