pynapple.process.spectrum#
Functions to compute power spectral density and mean power spectral density.
Functions
|
Compute Fast Fourier Transform over a single epoch. |
|
Compute mean power spectral density over multiple epochs of same size. |
|
Compute Power Spectral Density over a single epoch. |
- pynapple.process.spectrum.compute_fft(sig, fs=None, ep=None, full_range=False, norm=False, n=None)[source]#
Compute Fast Fourier Transform over a single epoch. Perform numpy fft on sig, returns output assuming a constant sampling rate for the signal.
- Parameters:
fs (float, optional) – Sampling rate, in Hz. If None, will be calculated from the given signal
ep (None or 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 the FFT.
- 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.
If full_range is False, the nyquist frequency is excluded in the output due to how computes the FFT frequencies in numpy.fft.fftfreq.
- pynapple.process.spectrum.compute_mean_power_spectral_density(sig, interval_size, fs=None, overlap=0.25, ep=None, full_range=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:
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 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
time_unit (str, optional) – Time units for parameter interval_size. Can be (‘s’[default], ‘ms’, ‘us’)
- Returns:
Return mean power spectral density of the input signal. Indexes are frequencies and values are powers/frequency.
- Return type:
pandas.DataFrame
Notes
The power spectral density is calculated as the square of the absolute value of the FFT, scaled by the sampling rate and length of the signal. See [this tutorial](https://www.mathworks.com/help/signal/ug/power-spectral-density-estimates-using-fft.html) for more information.
- 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, n=None)[source]#
Compute Power Spectral Density over a single epoch. Perform numpy fft on sig and obtain the periodogram, returns output assuming a constant sampling rate for the signal.
- Parameters:
fs (float, optional) – Sampling rate, in Hz. If None, will be calculated from the given signal
ep (None or 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
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:
Power spectral density of the input signal, indexes are frequencies, values are powers/frequency.
- 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.
The power spectral density is calculated as the square of the absolute value of the FFT, scaled by the sampling rate and length of the signal. See [this tutorial](https://www.mathworks.com/help/signal/ug/power-spectral-density-estimates-using-fft.html) for more information.
If full_range is False, the nyquist frequency is excluded in the output due to how computes the FFT frequencies in numpy.fft.fftfreq.