API Documentation

This is the API reference for the neurodsp module.

Table of Contents

Filtering

Functions and utilities in the filt module, for filtering time series.

General Filter Function

filter_signal(sig, fs, pass_type, f_range[, ...])

Apply a bandpass, bandstop, highpass, or lowpass filter to a neural signal.

FIR Filters

filter_signal_fir(sig, fs, pass_type, f_range)

Apply an FIR filter to a signal.

design_fir_filter(fs, pass_type, f_range[, ...])

Design an FIR filter.

IIR Filters

filter_signal_iir(sig, fs, pass_type, ...[, ...])

Apply an IIR filter to a signal.

design_iir_filter(fs, pass_type, f_range, ...)

Design an IIR filter.

Check Filter Properties

check_filter_definition(pass_type, f_range)

Check a filter definition for validity, and get filter frequency range of the filter.

check_filter_properties(filter_coefs, ...[, ...])

Check a filters properties, including pass band and transition band.

Filter Utilities

compute_frequency_response(filter_coefs, ...)

Compute the frequency response of a filter.

compute_pass_band(fs, pass_type, f_range)

Compute the pass bandwidth of a filter.

compute_transition_band(f_db, db[, low, high])

Compute transition bandwidth of a filter.

compute_nyquist(fs)

Compute the Nyquist frequency.

remove_filter_edges(sig, filt_len)

Drop the edges, by making NaN, from a filtered signal, to avoid edge artifacts.

Time-Frequency Analyses

Functions and utilities in the timefrequency module, for time-frequency analyses.

Hilbert Methods

robust_hilbert(sig)

Compute the Hilbert transform, ignoring any boundaries that are NaN.

phase_by_time(sig, fs[, f_range, remove_edges])

Compute the instantaneous phase of a time series.

amp_by_time(sig, fs[, f_range, remove_edges])

Compute the instantaneous amplitude of a time series.

freq_by_time(sig, fs[, f_range, remove_edges])

Compute the instantaneous frequency of a time series.

Wavelet Methods

compute_wavelet_transform(sig, fs, freqs[, ...])

Compute the time-frequency representation of a signal using morlet wavelets.

convolve_wavelet(sig, fs, freq[, n_cycles, ...])

Convolve a signal with a complex wavelet.

Spectral Analyses

Functions and utilities in the spectral module, for spectral analyses.

Spectral Power

compute_spectrum(sig, fs[, method, avg_type])

Compute the power spectral density of a time series.

compute_spectrum_welch(sig, fs[, avg_type, ...])

Compute the power spectral density using Welch's method.

compute_spectrum_wavelet(sig, fs, freqs[, ...])

Compute the power spectral density using wavelets.

compute_spectrum_medfilt(sig, fs[, ...])

Compute the power spectral density as a smoothed FFT.

Spectral Measures

compute_absolute_power(freqs, powers, band)

Compute absolute power for a given frequency band.

compute_relative_power(freqs, powers, band)

Compute relative power for a given frequency band.

compute_band_ratio(freqs, powers, low_band, ...)

Calculate band ratio measure between two predefined frequency ranges.

Spectral Variance

compute_scv(sig, fs[, window, nperseg, ...])

Compute the spectral coefficient of variation (SCV) at each frequency.

compute_scv_rs(sig, fs[, window, nperseg, ...])

Compute a resampled version of the spectral coefficient of variation (SCV).

compute_spectral_hist(sig, fs[, window, ...])

Compute the distribution of log10 power at each frequency from the signal spectrogram.

Spectral Utilities

trim_spectrum(freqs, power_spectra, f_range)

Extract a frequency range of interest from power spectra.

trim_spectrogram(freqs, times, spg[, ...])

Extract a frequency or time range of interest from a spectrogram.

Burst Detection

Functions and utilities in the burst module, for detection bursts in time series.

Burst Detection Algorithms

detect_bursts_dual_threshold(sig, fs, ...[, ...])

Detect bursts in a signal using the dual threshold algorithm.

Burst Utilities

compute_burst_stats(bursting, fs)

Compute statistics of bursts.

Rhythm Analyses

Functions and utilities in the rhythm module, for finding and analyzing rhythmic and recurring patterns in time series.

Sliding Window Matching

sliding_window_matching(sig, fs, win_len, ...)

Find recurring patterns in a time series using the sliding window matching algorithm.

Lagged Coherence

compute_lagged_coherence(sig, fs, freqs[, ...])

Compute lagged coherence, reflecting the rhythmicity across a frequency range.

Aperiodic Analyses

Functions and utilities in the aperiodic module, for analyzing aperiodic activity in time series.

Auto-correlation Analyses

compute_autocorr(sig[, max_lag, lag_step, ...])

Compute the signal autocorrelation (lagged correlation).

Fluctuation Analyses

compute_fluctuations(sig, fs[, n_scales, ...])

Compute a fluctuation analysis on a signal.

compute_rescaled_range(sig, win_len)

Compute rescaled range of a given time series at a given scale.

compute_detrended_fluctuation(sig, win_len)

Compute detrended fluctuation of a time series at the given window length.

Signal Decomposition

compute_irasa(sig, fs[, f_range, hset, thresh])

Separate aperiodic and periodic components using IRASA.

fit_irasa(freqs, psd_aperiodic)

Fit the IRASA derived aperiodic component of the spectrum.

Conversions

convert_exponent_alpha(exponent)

Convert a powerlaw exponent to the expected DFA alpha value.

convert_alpha_exponent(alpha)

Convert a DFA alpha value to the expected powerlaw exponent.

convert_exponent_hurst(exponent, ...)

Convert a powerlaw exponent to the expected Hurst exponent value.

convert_hurst_exponent(hurst, fractional_class)

Convert a Hurst exponent value to the expected powerlaw exponent.

convert_exponent_hfd(exponent)

Convert exponent to expected Higuchi fractal dimension value.

convert_hfd_exponent(hfd)

Convert Higuchi fractal dimension value to expected 1/f exponent value.

Simulations

Functions and utilities in the sim module, for simulating time series.

Periodic Signals

sim_oscillation(n_seconds, fs, freq[, ...])

Simulate an oscillation.

sim_bursty_oscillation(n_seconds, fs, freq)

Simulate a bursty oscillation.

sim_variable_oscillation(n_seconds, fs, freqs)

Simulate an oscillation that varies in frequency and cycle parameters.

sim_damped_oscillation(n_seconds, fs, freq, ...)

Simulate a damped relaxation oscillation.

Aperiodic Signals

sim_powerlaw(n_seconds, fs[, exponent, f_range])

Simulate a power law time series, with a specified exponent.

sim_poisson_pop(n_seconds, fs[, n_neurons, ...])

Simulate a Poisson population.

sim_synaptic_current(n_seconds, fs[, ...])

Simulate a signal as a synaptic current, which has 1/f characteristics with a knee.

sim_knee(n_seconds, fs, exponent1, ...)

Simulate a signal whose power spectrum has a 1/f structure with a knee.

sim_random_walk(n_seconds, fs[, theta, mu, ...])

Simulate a mean-reverting random walk, as an Ornstein-Uhlenbeck process.

sim_frac_gaussian_noise(n_seconds, fs[, ...])

Simulate a timeseries as fractional gaussian noise.

sim_frac_brownian_motion(n_seconds, fs[, ...])

Simulate a timeseries as fractional brownian motion.

Transients

sim_synaptic_kernel(n_seconds, fs, tau_r, tau_d)

Simulate a synaptic kernel with specified time constants.

sim_action_potential(n_seconds, fs, centers, ...)

Simulate an action potential as the sum of skewed gaussians.

sim_damped_erp(n_seconds, fs, amp, freq[, ...])

Simulate an ERP complex as a decaying (damped) sine wave.

Cycles

sim_cycle(n_seconds, fs, cycle_type[, phase])

Simulate a single cycle of a periodic pattern.

sim_sine_cycle(n_seconds, fs)

Simulate a cycle of a sine wave.

sim_asine_cycle(n_seconds, fs, rdsym[, side])

Simulate a cycle of an asymmetric sine wave.

sim_sawtooth_cycle(n_seconds, fs, width)

Simulate a cycle of a sawtooth wave.

sim_gaussian_cycle(n_seconds, fs, std[, center])

Simulate a cycle of a gaussian.

sim_skewed_gaussian_cycle(n_seconds, fs, ...)

Simulate a cycle of a skewed gaussian.

sim_exp_cos_cycle(n_seconds, fs, exp[, ...])

Simulate an exponential cosine cycle.

sim_asym_harmonic_cycle(n_seconds, fs, phi, ...)

Simulate an asymmetrical cycle as a sum of harmonics.

Combined Signals

sim_combined(n_seconds, fs, components[, ...])

Simulate a signal by combining multiple component signals.

sim_peak_oscillation(sig_ap, fs, freq, bw, ...)

Simulate a signal with an aperiodic component and a specific oscillation peak.

sim_modulated_signal(n_seconds, fs, ...)

Simulate an amplitude modulated signal.

Utilities

rotate_spectrum(freqs, spectrum, delta_exponent)

Rotate the power law exponent of a power spectrum.

rotate_timeseries(sig, fs, delta_exp[, ...])

Rotate a timeseries of data, changing it's 1/f exponent.

modulate_signal(sig, modulation[, fs, ...])

Apply amplitude modulation to a signal.

Random Seed

set_random_seed([seed_val])

Set the random seed value.

Plots

Functions in the plts module, for plotting time series and analysis outputs.

Time Series

plot_time_series(times, sigs[, labels, ...])

Plot a time series.

plot_instantaneous_measure(times, sigs[, ...])

Plot an instantaneous measure, of phase, amplitude or frequency.

plot_bursts(times, sig, bursting[, ax])

Plot a time series, with labeled bursts.

Spectral

plot_power_spectra(freqs, powers[, labels, ...])

Plot power spectra.

plot_scv(freqs, scv[, ax])

Plot spectral coefficient of variation.

plot_scv_rs_lines(freqs, scv_rs[, ax])

Plot spectral coefficient of variation, from the resampling method, as lines.

plot_scv_rs_matrix(freqs, t_inds, scv_rs[, ax])

Plot spectral coefficient of variation, from the resampling method, as a matrix.

plot_spectral_hist(freqs, power_bins, ...[, ...])

Plot spectral histogram.

Filter

plot_filter_properties(f_db, db, fs, ...[, ...])

Plot filter properties, including frequency response and filter kernel.

plot_frequency_response(f_db, db[, ax])

Plot the frequency response of a filter.

plot_impulse_response(fs, impulse_response)

Plot the impulse response of a filter.

Rhythm

plot_swm_pattern(pattern[, ax])

Plot the resulting pattern from a sliding window matching analysis.

plot_lagged_coherence(freqs, lcs[, ax])

Plot lagged coherence values across frequencies.

Time Frequency

plot_timefrequency(times, freqs, powers[, ...])

Plot a time-frequency representation of data.

Utilities

Functions in the utils module, providing general utilities.

Normalization

normalize_sig(sig[, mean, variance])

Normalize the mean and variance of a signal.

demean(array[, mean])

Demean an array, updating to specified mean.

normalize_variance(array[, variance])

Normalize the variance of an array, updating to specified variance.

Data

create_freqs(freq_start, freq_stop[, freq_step])

Create an array of frequencies.

create_times(n_seconds, fs[, start_val])

Create an array of time indices.

create_samples(n_samples[, start_val])

Create an array of sample indices.

compute_nsamples(n_seconds, fs)

Calculate the number of samples for a given time definition.

compute_nseconds(sig, fs)

Compute the length, in time, of a signal.

compute_cycle_nseconds(freq[, fs])

Compute the length, in seconds, for a single cycle at a particular frequency.

split_signal(sig, n_samples)

Split a signal into non-overlapping segments.

Outliers

remove_nans(sig)

Drop any NaNs on the edges of an array.

restore_nans(sig, sig_nans[, dtype])

Restore NaN values to the edges of an array.

discard_outliers(data, outlier_percent)

Discard outlier arrays with high values.