Welch-averaged one-sided PSD via stats::spec.pgram() on overlapping
detrended segments. Same algorithm as SciPy's welch so band powers
agree to ~1e-3 for typical EEG/ECG inputs.
Usage
rgpsd(x, fs = 1, nperseg = NULL, window = "hann")
morie_rangayyan_psd(x, fs = 1, nperseg = NULL, window = "hann")
Arguments
- x
Numeric vector.
- fs
Sampling frequency (Hz).
- nperseg
Segment length (default min(N, 256)).
- window
Window name ("hann" default).
Value
Named list freqs, psd, fs, nperseg, peak_freq,
total_power.
References
Welch (1967); Rangayyan Ch 4.
Examples
# \donttest{
set.seed(0)
fs <- 100
t <- seq(0, 10, length.out = 1000)
x <- sin(2 * pi * 10 * t)
r <- rgpsd(x, fs = fs, nperseg = 256)
abs(r$peak_freq - 10) < 1
#> [1] TRUE
# }