freq ¶
Frequency-domain analysis of EMG signals.
get_spectrum ¶
get_spectrum(data: ndarray, fs: Optional[int] = 2048) -> Tuple[np.ndarray, np.ndarray]
Compute the single-sided amplitude spectrum of the input data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Input data with shape (samples, channels). |
required |
fs
|
int
|
Sampling frequency in Hz. Default is 2048. |
2048
|
Returns:
| Name | Type | Description |
|---|---|---|
spectrum |
ndarray
|
Amplitude spectrum of the input data with shape (samples//2, channels), in the same units as the data, where the first dimension corresponds to the positive frequencies. |
xf |
ndarray
|
Frequency axis in Hz, with shape (samples//2,). |
Source code in emg_tools/freq.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
get_psd ¶
get_psd(data: ndarray, fs: Optional[int] = 2048, *, welch: Optional[bool] = False, nperseg: Optional[int] = None) -> Tuple[np.ndarray, np.ndarray]
Compute the one-sided Power Spectral Density (PSD) of the input data.
By default the periodogram is used. Welch's method can be requested instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Input data with shape (samples, channels). |
required |
fs
|
int
|
Sampling frequency in Hz. Default is 2048. |
2048
|
welch
|
bool
|
If True, the PSD is estimated with Welch's method. Default is False (periodogram). |
False
|
nperseg
|
int
|
Length of each segment in samples, only used if welch is True. Default is None, which uses scipy's default (256). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
psd |
ndarray
|
One-sided PSD of the input data with shape (freqs, channels), in units of data^2/Hz. |
xf |
ndarray
|
Frequency axis in Hz, with shape (freqs,). |
Source code in emg_tools/freq.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |