Skip to main 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 the docs directory. Run it in your browser, no installation needed:

Notebook molab marimo.app
psd2 Open in molab Open with marimo

The notebook name links to a static preview with the outputs; the badges run the notebook in your browser with WebAssembly.

Or run it locally:

uvx marimo edit --sandbox docs/psd2_notebook.py

How to cite this work

Here is a suggestion to cite this GitHub repository:

Marcos Duarte. (2021). psd2: A Python module for estimation of power spectral density characteristics using Welch's method (Version v0.0.4). Zenodo. http://doi.org/10.5281/zenodo.4599105

And a possible BibTeX entry:

@software{marcos_duarte_2021_4599105,
  author       = {Marcos Duarte},
  title        = {{psd2: A Python module for estimation of power spectral density characteristics using Welch's method}},
  month        = mar,
  year         = 2021,
  publisher    = {Zenodo},
  version      = {v0.0.4},
  doi          = {10.5281/zenodo.4599105},
  url          = {https://doi.org/10.5281/zenodo.4599105}
}

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.

Metadata

Release files for psd2 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for psd2 0.0.5
File Size Uploaded Provenance
psd2-0.0.5.tar.gz 7.1 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for psd2 0.0.5
File Interpreter ABI Platform
psd2-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 13.8 kB

Release files / psd2-0.0.5.tar.gz

Download URL psd2-0.0.5.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
6fe4d02cffe6293c2640f0663bbea5c0576a4803eda0e65bbb31760a8fd59d11
BLAKE2b-256 checksum
How to use checksums
d446b9aba0674c63d715b59cbb9663e1721fc626c5e24ccf6587decd5dc0d9d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.

Transparency log

Release files / psd2-0.0.5-py3-none-any.whl

Download URL psd2-0.0.5-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6daa68ed9073a873c5c4b93c155c8d24d68c07dc902ffae09eda62a443f2a8d4
BLAKE2b-256 checksum
How to use checksums
120792bdfe0ae97fa8c30dfdb4d37a237ee2c23d7d9a4d48f3232f5235ec0e58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.

Transparency log

Security for psd2 0.0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for psd2-0.0.5.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page