Time-Frequency
Joint time-frequency representations for non-stationary signals.
| Function | Resolution | Cross-terms | Cost |
|---|---|---|---|
stft |
Window-limited | None | O(N log N) |
cwt_scalogram |
Adaptive (log-freq) | None | O(N log N) |
wigner_ville |
Optimal | Yes | O(N²) |
smoothed_pseudo_wv |
Tunable | Reduced | O(N²) |
WVD/SPWVD computation time
Both Wigner-Ville functions are O(N²). For signals longer than ~2048 samples a UserWarning is raised. Use warn_above to adjust the threshold.

STFT
dspkit.timefreq.stft(x, fs, window='hann', nperseg=256, noverlap=None, scaling='spectrum')
Short-Time Fourier Transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
(array_like, shape(N))
|
|
required |
fs
|
float
|
Sampling frequency [Hz]. |
required |
window
|
str
|
Window function (default |
'hann'
|
nperseg
|
int
|
Segment length [samples]. Larger → better frequency resolution, worse time resolution. Default 256. |
256
|
noverlap
|
int or None
|
Overlapping samples between segments. Defaults to
|
None
|
scaling
|
(spectrum, psd)
|
|
'spectrum'
|
Returns:
| Name | Type | Description |
|---|---|---|
freqs |
(ndarray, shape(nperseg // 2 + 1))
|
Frequency vector [Hz]. |
times |
ndarray
|
Time vector [s], centre of each segment. |
Zxx |
(ndarray, shape(len(freqs), len(times)), complex)
|
STFT coefficients. |
Source code in dspkit/timefreq.py
CWT Scalogram
dspkit.timefreq.cwt_scalogram(x, fs, freqs=None, w=6.0)
Continuous Wavelet Transform scalogram using the complex Morlet wavelet.
The Morlet wavelet provides excellent time-frequency localisation for oscillatory signals and is standard in structural dynamics.
The parameter w sets the number of oscillations in the wavelet
(its centre frequency in rad):
- Higher
w→ better frequency resolution, worse time resolution. - Lower
w→ better time resolution, worse frequency resolution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
(array_like, shape(N))
|
|
required |
fs
|
float
|
Sampling frequency [Hz]. |
required |
freqs
|
array_like or None
|
Analysis frequencies [Hz]. Defaults to 50 log-spaced values from
1 Hz to |
None
|
w
|
float
|
Morlet centre-frequency parameter (default 6.0). |
6.0
|
Returns:
| Name | Type | Description |
|---|---|---|
freqs |
ndarray
|
Analysis frequencies [Hz]. |
times |
(ndarray, shape(N))
|
Time vector [s]. |
W |
(ndarray, shape(len(freqs), N), complex)
|
CWT coefficients. |
Source code in dspkit/timefreq.py
Wigner-Ville Distribution
dspkit.timefreq.wigner_ville(x, fs, warn_above=2048)
Wigner-Ville Distribution (WVD).
Computed via the analytic signal (Hilbert transform) to suppress aliasing artifacts. The result is real-valued.
The WVD achieves the highest joint time-frequency resolution of any
bilinear distribution and satisfies both the time and frequency
marginals exactly for single-component signals. However, it produces
oscillatory cross-terms between signal components. For noisy or
multi-component signals, prefer smoothed_pseudo_wv.
.. warning:: Computation is O(N²) in time and memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
(array_like, shape(N))
|
|
required |
fs
|
float
|
Sampling frequency [Hz]. |
required |
warn_above
|
int
|
Emit a warning when |
2048
|
Returns:
| Name | Type | Description |
|---|---|---|
freqs |
(ndarray, shape(N // 2 + 1))
|
Frequency vector [Hz], from 0 to fs / 4. The half-lag autocorrelation limits the representable frequency range to fs/4 (Nyquist of the half-lag domain). |
times |
(ndarray, shape(N))
|
Time vector [s]. |
WVD |
(ndarray, shape(N, N // 2 + 1))
|
Wigner-Ville distribution. May contain negative values (cross-terms or edge effects). Integrating over frequency yields instantaneous power. |
Source code in dspkit/timefreq.py
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 232 233 234 235 236 237 238 239 240 241 242 | |
Smoothed Pseudo WVD
dspkit.timefreq.smoothed_pseudo_wv(x, fs, lag_samples=None, time_samples=None, warn_above=2048)
Smoothed Pseudo Wigner-Ville Distribution (SPWVD).
Suppresses the cross-term interference of the plain WVD by applying:
- A Hann lag window of half-length
lag_samples: limits the autocorrelation lag, smoothing the frequency axis and attenuating cross-terms between components at different frequencies. - A Hann time window of half-length
time_samples: smooths the time axis and attenuates cross-terms between components at different times.
Increasing either window suppresses more cross-terms but reduces the corresponding resolution. Choose window sizes smaller than the signal's characteristic time/frequency separation.
.. warning:: Computation is O(N²) in time and memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
(array_like, shape(N))
|
|
required |
fs
|
float
|
Sampling frequency [Hz]. |
required |
lag_samples
|
int or None
|
Half-length of the Hann lag window [samples].
Full window = |
None
|
time_samples
|
int or None
|
Half-length of the Hann time window [samples].
Defaults to |
None
|
warn_above
|
int
|
Emit a warning when |
2048
|
Returns:
| Name | Type | Description |
|---|---|---|
freqs |
(ndarray, shape(N // 2 + 1))
|
Frequency vector [Hz], from 0 to fs / 4. |
times |
(ndarray, shape(N))
|
Time vector [s]. |
SPWVD |
(ndarray, shape(N, N // 2 + 1))
|
Smoothed distribution. Tends to non-negative after sufficient smoothing. |
Source code in dspkit/timefreq.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | |