Skip to the content.

psd2

PyPI version DOI

Estimation of power spectral density characteristics using Welch’s method

The function psd2.py from Python module psd2 estimates power spectral density characteristics using Welch’s method. This function is just a wrap of the scipy.signal.welch function with estimation of some frequency characteristics and a plot. The psd2.py returns power spectral density data, frequency percentiles of the power spectral density (for example, Fpcntile[50] gives the median power frequency in Hz); mean power frequency; maximum power frequency; total power, and plots power spectral density data.

Installation

pip install psd2

The plots (parameter show=True, the default) require matplotlib, which can be installed together with:

pip install "psd2[plot]"

Or

conda install -c duartexyz psd2

Examples

>>> import numpy as np
>>> from psd2 import psd2
# Generate a test signal, a 2 Vrms sine wave at 1234 Hz, corrupted by
# 0.001 V**2/Hz of white noise sampled at 10 kHz and calculate the PSD:
>>> fs = 10e3
>>> N = 100000
>>> amp = 2*np.sqrt(2)
>>> freq = 1234.0
>>> noise_power = 0.001 * fs / 2
>>> time = np.arange(N) / fs
>>> x = amp*np.sin(2*np.pi*freq*time)
>>> x += np.random.normal(scale=np.sqrt(noise_power), size=time.shape)
>>> fpcntile, mpf, fmax, Ptotal, f, P = psd2(x, fs=fs, nperseg=1024)

More examples are in a marimo notebook in docs/. Click the notebook name to open its editable GitHub Pages version. Click Run all, then edit and rerun cells to experiment. Download the Python file to keep changes; browser edits do not update this repository.

The notebook links to its Read saved outputs version in docs/html/. Saved text and plots can be read without running Python; their controls cannot recompute results. Both modes are hosted on this repository’s GitHub Pages site independently of molab and marimo.app. The badges provide alternative interactive services; molab uses its standard execution mode.

Editable Pages runs Python through WebAssembly and downloads its runtime and packages. Saved pages load display assets, so both modes need an Internet connection. GitHub Actions refreshes saved outputs and publishes editable notebooks on every push to master. See scripts/README.md for local updates and previews.

Or run it locally:

uvx marimo edit --sandbox docs/psd2_notebook.py

How to cite this work

Here is a suggestion to cite this software, with its concept DOI, which always resolves to the latest version (to cite a specific version, use its DOI listed on Zenodo):

Marcos Duarte. (2026). psd2: A Python module for estimation of power spectral density characteristics using Welch’s method (v0.0.5). Zenodo. https://doi.org/10.5281/zenodo.4599104

And a possible BibTeX entry:

@software{duarte_psd2,
  author       = {Duarte, Marcos},
  title        = ,
  year         = 2026,
  publisher    = {Zenodo},
  version      = {v0.0.5},
  doi          = {10.5281/zenodo.4599104},
  url          = {https://doi.org/10.5281/zenodo.4599104}
}

License

The non-software content of this project is licensed under a Creative Commons Attribution 4.0 International License, and the software code is licensed under the MIT license.