Example #1
0
exponent = -2

# Simulate powerlaw activity, specifically brown noise
times = create_times(n_seconds, fs)
br_noise = sim.sim_powerlaw(n_seconds, fs, exponent)

###################################################################################################

# Plot the simulated data, in the time domain
plot_time_series(times, br_noise)

###################################################################################################

# Plot the simulated data, in the frequency domain
freqs, psd = spectral.compute_spectrum(br_noise, fs)
plot_power_spectra(freqs, psd)

###################################################################################################
#
# Simulate Filtered 1/f Activity
# ------------------------------
#
# The powerlaw simulation function is also integrated with a filter. This can be useful
# if one wants to filter out the slow frequencies, as is often done with neural signals,
# to remove the very slow drifts that we see in the pure 1/f simulations.
#
# To filter a simulated powerlaw signal, simply pass in a filter range, and the filter will
# be applied to the simulated data before being returned. Here we will apply a high-pass filter.
#
# We can see that the resulting signal has much less low-frequency drift than the first one.
#
###################################################################################################
#
# We can also compare these signals in the frequency.
#
# Notice that the asymmetric oscillation has strong harmonics resulting from the
# non-sinusoidal nature of the oscillation.
#

###################################################################################################

# Plot the simulated data, in the frequency domain
freqs_sine, psd_sine = compute_spectrum(osc_sine, fs)
freqs_shape, psd_shape = compute_spectrum(osc_shape, fs)

plot_power_spectra([freqs_sine, freqs_shape], [psd_sine, psd_shape])

###################################################################################################
# Simulate a Bursty Oscillation
# -----------------------------
#
# Sometimes we want to study oscillations that come and go, so it can be useful to simulate
# oscillations with this property.
#
# You can simulate bursty oscillations with :func:`~neurodsp.sim.periodic.sim_bursty_oscillation`.
#
# To control the bursitness of the simulated signal, you can control the probability
# that a burst will start or stop with each new cycle.
#

###################################################################################################
Example #3
0
###################################################################################################

# Simulate an oscillation over an aperiodic component
signal = sim.sim_combined(n_seconds, fs, components)

###################################################################################################

# Plot the simulated data, in the time domain
plot_time_series(times, signal)

###################################################################################################

# Plot the simulated data, in the frequency domain
freqs, psd = spectral.compute_spectrum(signal, fs)
plot_power_spectra(freqs, psd)

###################################################################################################
#
# We can switch out any components that we want, for example trading the stationary oscillation
# for a bursting oscillation, also with an aperiodic component.
#
# We can also control the relative proportions of each component, by using a parameter called
# `component_variances` that specifies the variance of each component.
#

###################################################################################################

# Define the components of the combined signal to simulate
components = {
    'sim_synaptic_current': {
Example #4
0


#%% Welch frequency distribution
from neurodsp.plts.spectral import plot_power_spectra
plot_power_spectra(freq_mean[:200], psd_mean[:200], 'Welch')


#%% Simple plot 

from neurodsp.plts.time_series import plot_time_series

times = create_times(len(datastruct[subj][ch])/fs, fs)
plot_time_series(times, datastruct[subj][ch], xlim=[0, .8])

#%%
with pd.option_context('display.max_rows', 20
                       , 'display.max_columns', None):    
    print(df)

#%%

import matplotlib.pyplot as plt




plt_time = [0, 5000]

plt.figure(figsize = (20,8));
plt.plot((sig[plt_time[0]:plt_time[1]]),label= 'Raw Signal')
Example #5
0
                                     avg_type='median',
                                     nperseg=fs * 2)

# Median filtered spectrum
freq_mf, psd_mf = compute_spectrum(sig, fs, method='medfilt')

###################################################################################################
#
# You can plot power spectra with :func:`~.plot_power_spectra`.
#

###################################################################################################

# Plot the power spectra
plot_power_spectra([freq_mean[:200], freq_med[:200], freq_mf[100:10000]],
                   [psd_mean[:200], psd_med[:200], psd_mf[100:10000]],
                   ['Welch', 'Median Welch', 'Median Filter FFT'])

###################################################################################################
# Aside: Fitting 1/f and oscillations in power spectra
# ----------------------------------------------------
#
# You might notice in the above power spectra that there are regions of band-specific power,
# reflecting oscillations, as well as regions that show linear decrease when plotted in
# log-log scale, in particular the frequency region between 30-100Hz.
#
# As well as a large body of work investigating oscillations, this "1/f-like" aperiodic
# components has been found to correlate with aging, memory, and cognitive control in several
# previous publications, and has been proposed to reflect the physiological balance between
# excitation and inhibition.
#
Example #6
0
n_seconds = 10
fs = 1000
exponent = -2
times = create_times(n_seconds, fs)
br_noise = sim.sim_powerlaw(n_seconds, fs, exponent)

###################################################################################################

# Plot the simulated data, in the time domain
plot_time_series(times, br_noise)

###################################################################################################

# Plot the simulated data, in the frequency domain
freqs, psd = spectral.compute_spectrum(br_noise, fs)
plot_power_spectra(freqs, psd)

###################################################################################################
#
# Simulate filtered brown noise
# -----------------------------
#
# However, brown noise has a lot of power in very slow frequnecies,
# whereas these slow frequencies are often not present or filtered out
# in neural signals. Therefore, we may desire our brown noise to be
# high-pass filtered. See that the resulting signal has much less
# low-frequency drift.
#
# Note this might not be ideal because it creates an "oscillation" at
# the cutoff frequency.
#