Spectrum
pynapple.process.spectrum
This module contains functions to compute power spectral density and mean power spectral density.
Function | Description |
---|---|
compute_power_spectral_density |
Compute Power Spectral Density over a single epoch |
compute_mean_power_spectral_density |
Compute Mean Power Spectral Density over multiple epochs |
compute_power_spectral_density
Perform numpy fft on sig, returns output assuming a constant sampling rate for the signal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sig |
Tsd or TsdFrame
|
Time series. |
required |
fs |
float
|
Sampling rate, in Hz. If None, will be calculated from the given signal |
None
|
ep |
None or IntervalSet
|
The epoch to calculate the fft on. Must be length 1. |
None
|
full_range |
bool
|
If true, will return full fft frequency range, otherwise will return only positive values |
False
|
norm |
Whether the FFT result is divided by the length of the signal to normalize the amplitude |
False
|
|
n |
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. |
None
|
Returns:
Type | Description |
---|---|
DataFrame
|
Time frequency representation of the input signal, indexes are frequencies, values are powers. |
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.
Source code in pynapple/process/spectrum.py
compute_mean_power_spectral_density
compute_mean_power_spectral_density(
sig,
interval_size,
fs=None,
overlap=0.25,
ep=None,
full_range=False,
norm=False,
time_unit="s",
)
Compute mean power spectral density by averaging FFT over 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:
Name | Type | Description | Default |
---|---|---|---|
sig |
Tsd or TsdFrame
|
Signal with equispaced samples |
required |
interval_size |
Number
|
Epochs size to compute to average the FFT across |
required |
fs |
Number
|
Sampling frequency of |
None
|
overlap |
float
|
Percentage of overlap between successive intervals.
|
0.25
|
ep |
None or IntervalSet
|
The |
None
|
full_range |
bool
|
If true, will return full fft frequency range, otherwise will return only positive values |
False
|
norm |
Whether the FFT result is divided by the length of the signal to normalize the amplitude |
False
|
|
time_unit |
str
|
Time units for parameter |
's'
|
Returns:
Type | Description |
---|---|
DataFrame
|
Power spectral density. |
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:
Type | Description |
---|---|
RuntimeError
|
If splitting the epoch with |
ValueError
|
If overlap is not within [0, 1). |
Source code in pynapple/process/spectrum.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
|