pynapple.process.spectrum#
Functions to compute power spectral density and mean power spectral density.
Functions
|
Compute Mean Power Spectral Density over multiple epochs of same size. |
|
Compute Power Spectral Density over a single epoch. |
- pynapple.process.spectrum.compute_mean_power_spectral_density(sig, interval_size, fs=None, overlap=0.25, ep=None, full_range=False, norm=False, time_unit='s')[source]#
Compute Mean Power Spectral Density over multiple epochs of same size.
The parameter interval_size controls the duration of the epochs.
To improve frequency resolution, the signal is multiplied by a Hamming window.
Note that this function assumes a constant sampling rate for sig.
- Parameters:
sig (pynapple.Tsd or pynapple.TsdFrame) – Signal with equispaced samples
interval_size (Number) – Epochs size to compute to average the FFT across
fs (Number, optional) – Sampling frequency of sig. If None, fs is equal to sig.rate
overlap (float, optional) – Percentage of overlap between successive intervals. 0.0 <= overlap < 1.0. Default is 0.25
ep (None or pynapple.IntervalSet, optional) – The IntervalSet to calculate the fft on. Can be any length.
full_range (bool, optional) – If true, will return full fft frequency range, otherwise will return only positive values
norm (bool, optional) – Whether the FFT result is divided by the length of the signal to normalize the amplitude
time_unit (str, optional) – Time units for parameter interval_size. Can be (‘s’[default], ‘ms’, ‘us’)
- Returns:
Power spectral density.
- Return type:
pandas.DataFrame
Examples
>>> import numpy as np >>> import pynapple as nap >>> t = np.arange(0, 1, 1/1000) >>> signal = nap.Tsd(d=np.sin(t * 50 * np.pi * 2), t=t) >>> mpsd = nap.compute_mean_power_spectral_density(signal, 0.1)
- Raises:
RuntimeError – If splitting the epoch with interval_size results in an empty set.
ValueError – If overlap is not within [0, 1).
- pynapple.process.spectrum.compute_power_spectral_density(sig, fs=None, ep=None, full_range=False, norm=False, n=None)[source]#
Compute Power Spectral Density over a single epoch. Perform numpy fft on sig, returns output assuming a constant sampling rate for the signal.
- Parameters:
sig (pynapple.Tsd or pynapple.TsdFrame) – Time series.
fs (float, optional) – Sampling rate, in Hz. If None, will be calculated from the given signal
ep (None or pynapple.IntervalSet, optional) – The epoch to calculate the fft on. Must be length 1.
full_range (bool, optional) – If true, will return full fft frequency range, otherwise will return only positive values
norm (bool, optional) – Whether the FFT result is divided by the length of the signal to normalize the amplitude
n (int, optional) – Length of the transformed axis of the output. If n is smaller than the length of the input, the input is cropped. If it is larger, the input is padded with zeros. If n is not given, the length of the input along the axis specified by axis is used.
- Returns:
Time frequency representation of the input signal, indexes are frequencies, values are powers.
- Return type:
pandas.DataFrame
Notes
This function computes fft on only a single epoch of data. This epoch be given with the ep parameter otherwise will be sig.time_support, but it must only be a single epoch.