Harmonic Analysis package
THD, SNR, SINAD and THD+N of a signal in one call, from its FFT spectrum.
pip install harm-analysis
Introduction
The harmonic analysis package uses FFT to estimate parameters of an input signal. The package provides two main functions:
harm_analysis: for simulations with an injected tone, returning SNR, THDN, Noise, etc.spec_analysis: for cases without an injected tone, that auto-detects DC, tones, and noise from the spectrum.
Why harm-analysis?
- One call, all the metrics: fundamental, harmonics, DC, noise, THD, SNR, SINAD and THD+N.
- Works on real data: no coherent sampling needed; windowing and spectral leakage are handled for you.
- No known tone?
spec_analysisfinds DC, tones and the noise floor by itself. - Plots included: pass
plot=Trueto draw the annotated spectrum. - Command line too:
harm-analysisandspec-analysisanalyze a text file directly.
Example
A 1 kHz tone with a -60 dB second harmonic and some noise:
import numpy as np
from harm_analysis import harm_analysis
rng = np.random.default_rng(0)
fs = 48000
t = np.arange(4096) / fs
x = np.sin(2 * np.pi * 1000 * t) + 1e-3 * np.sin(2 * np.pi * 2000 * t) + 1e-4 * rng.standard_normal(t.size)
r = harm_analysis(x, fs=fs)
for name, value in r.to_dict().items():
print(f"{name:>15}: {np.round(value, 2)}")
Output:
fund_db: -3.01
fund_freq: 1000.0
harm_freq: [1999.97 3022.05 4023.99 4958.22 5971.06]
harm_db: [ -63. -107.8 -103.57 -105.74 -103.45]
dc_db: -109.41
noise_db: -79.32
thd_db: -59.99
snr_db: 76.31
sinad_db: 59.89
thdn_db: -59.89
total_noise_db: -79.32
Powers are in dB (a unit-amplitude sine is -3 dB); thd_db, snr_db, sinad_db
and thdn_db are relative to the fundamental.
See usage for examples.
AI assistants (Claude, GitHub Copilot, ...) can run the analyses through the included MCP server; see AI assistants.
Installation
pip install harm-analysis
Metadata
Release files for harm-analysis 2.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| harm_analysis-2.1.0.tar.gz | 37.4 kB | Without provenance | Details for harm_analysis-2.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| harm_analysis-2.1.0-py3-none-any.whl | Python 3 | none | any | Details for harm_analysis-2.1.0-py3-none-any.whl |
Total release size: 70.6 kB
Release files / harm_analysis-2.1.0.tar.gz
| Download URL | harm_analysis-2.1.0.tar.gz |
|---|---|
| Size | 37.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d89d3642052b1e77f042fe7e27d3d42cf2232c061b9ec47c77910cacbf6a61ee
|
|
BLAKE2b-256 checksum How to use checksums |
d3458d99230aa3c1200aa45d5c7badca3d38a90475ebab55efe4304564e36e58
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
pdm/2.29.7 CPython/3.15.2 Linux/7.0.0-1020-azure
|
Release files / harm_analysis-2.1.0-py3-none-any.whl
| Download URL | harm_analysis-2.1.0-py3-none-any.whl |
|---|---|
| Size | 33.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e07b44f8330138ec0a6bc334d742e43292a9ca67c7a96924bac638f2e42f1a79
|
|
BLAKE2b-256 checksum How to use checksums |
599f3c44c61bc5b56f5f87198ee20c112e07915fa59388ec67eb8cfb3be8a5cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
pdm/2.29.7 CPython/3.15.2 Linux/7.0.0-1020-azure
|
Security for harm-analysis 2.1.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.