Spectral utils
Utility functions for spectral analysis. Defaults are chosen to replicate MATLAB's default behavior.
csd
csd(x, y, fs, num_windows=8, window_type='hamming', window_len=None, nfft=None, detrend=False, onesided=True)
Cross spectral density via Welch's method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Two input signals of identical shape; the longest axis is time. |
required |
y
|
ndarray
|
Two input signals of identical shape; the longest axis is time. |
required |
fs
|
float
|
Sampling frequency (Hz). |
required |
num_windows
|
int
|
Number of (50%-overlapping) Welch windows when |
8
|
window_type
|
str
|
Window passed to |
'hamming'
|
window_len
|
int
|
Window length in samples. If None, derived from |
None
|
nfft
|
int
|
FFT length. Defaults to |
None
|
detrend
|
bool
|
If True, detrend each segment before transforming. |
False
|
onesided
|
bool
|
If True, return the one-sided spectrum. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
f |
ndarray
|
Frequency vector (Hz). |
Pxy |
ndarray
|
Complex cross spectral density (units of x*y / Hz). |
Source code in src/pytoast/utils/spectral_utils.py
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 | |
get_frequency_range
get_frequency_range(f, f_low=None, f_high=None)
Index range into f covering [f_low, f_high].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
ndarray
|
Monotonically increasing frequency vector (Hz). |
required |
f_low
|
float
|
Lower frequency bound (Hz). If None, start at index 0. |
None
|
f_high
|
float
|
Upper frequency bound (Hz). If None, end at |
None
|
Returns:
| Type | Description |
|---|---|
tuple of int
|
|
Source code in src/pytoast/utils/spectral_utils.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
get_window_len
get_window_len(N, num_windows)
Welch-method window length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
N
|
int
|
Number of samples in the time series. |
required |
num_windows
|
int
|
Number of (50%-overlapping) windows desired. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Window length in samples. |
Source code in src/pytoast/utils/spectral_utils.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | |
psd
psd(x, fs, num_windows=8, window_type='hamming', window_len=None, nfft=None, detrend=False, onesided=True)
Power spectral density via Welch's method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Input signal. The longest axis is treated as time. |
required |
fs
|
float
|
Sampling frequency (Hz). |
required |
num_windows
|
int
|
Number of (50%-overlapping) Welch windows when |
8
|
window_type
|
str
|
Window passed to |
'hamming'
|
window_len
|
int
|
Window length in samples. If None, derived from |
None
|
nfft
|
int
|
FFT length. Defaults to |
None
|
detrend
|
bool
|
If True, detrend each segment before transforming. |
False
|
onesided
|
bool
|
If True, return the one-sided spectrum. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
f |
ndarray
|
Frequency vector (Hz). |
Pxx |
ndarray
|
Power spectral density (units of |
Source code in src/pytoast/utils/spectral_utils.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |