Changelog¶
All notable changes to this project are documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
Unreleased¶
Added¶
spec_analysishas abwargument, likeharm_analysis: only tones up tobware reported andnoise_dbis the noise from DC tobw, e.g. the in-band noise of a sigma-delta converter. Also available as--bwin thespec-analysiscommand and asbwin the MCP toolrun_spec_analysis.harm-analysiscommand:--bwoption, passed toharm_analysis(bw=...).
Documentation¶
README and docs front page: one-line summary, install command at the top, a “Why harm-analysis?” section and a runnable example with its output.
2.0.0 - 2026-11-10¶
This release contains breaking changes; see Changed (breaking) below.
Changed (breaking)¶
harm_analysisandspec_analysisnow always return aHarmResult/SpecResultobject instead of adict, or a(dict, Axes)tuple whenplot=True. Access results as attributes (results.snr_db) or convert them withresults.to_dict(). Withplot=Truethe spectrum is drawn on theaxyou pass in, which is no longer returned. (#27)HarmResult.harm_freqis an empty array instead ofNonewhen there are no harmonics. (#27)Invalid inputs now raise
ValueError/TypeErrorwith a clear message instead of failing inside numpy, being silently accepted, or exiting the process:xmust be real, 1-D, at least 32 samples long and finite;fsmust be positive;windowmust match the length ofx;bwmust be in(0, fs / 2];n_harmmust not be negative. Complex input is not supported. (#30)HarmResult.total_noise_and_dist_dbis renamed tototal_noise_db: it is the noise integrated over the whole spectrum (DC to fs/2, also beyondbw) and never included the analyzed harmonics, so the old name was misleading. The value is unchanged.plot=Truewithout anaxraises aValueError. (#27)
Changed¶
Restyled the spectrum plots (
plot=Trueand the CLI’s--plot): the noise is a thin gray background trace, the fundamental/tones and harmonics stand out in colors that are distinguishable with color-vision deficiencies, peaks are labeled with their level (e.g. “H2 -43.0 dB”), and the legend shows the integrated noise values (atbwwhen it is given, matchingnoise_db). Only the givenaxis styled.Harmonics in the plots are numbered by their order, as in MATLAB: the 2nd harmonic is “H2” (it was labeled “H1”).
Added¶
Documentation: “How it works” (the algorithm and the definition of every metric), “Corner cases” (interferers, shaped noise, noise-free tones, fs/2, false tones, invalid input) with figures generated from the code at build time, CLI examples with real output, an API overview and a table of contents on the home page.
An overview figure and a code snippet at the top of the README and the documentation home page, showing what
harm_analysisandspec_analysismeasure.fund_freqparameter ofharm_analysis(and--fund-freqfor theharm-analysiscommand,fund_freqfor the MCP tool): the expected frequency of the injected tone, so a stronger interferer is no longer taken as the fundamental. It raises aValueErrorif there is no tone near that frequency. (#42)false_alarm_rateparameter ofspec_analysis(default1e-3): the target probability that noise alone produces a false tone in a spectrum.HarmResultandSpecResultare exported fromharm_analysis. (#27)--sfactoraccepts arithmetic expressions: numbers (including1e5),+ - * /, parentheses andlog2. (#22)py.typedmarker, so type checkers use the package’s type hints.--jsonoption forharm-analysisandspec-analysisto print the results as JSON (non-finite values asnull).llms.txtandllms-full.txt(see llmstxt.org) at the root of the documentation site, so LLMs and AI tools can read the docs, including the API reference, as plain text.Runnable examples in the
harm_analysisandspec_analysisdocstrings, tested as doctests.MCP server for AI assistants (
harm-analysis-mcp, optional extraharm-analysis[mcp]) withrun_harm_analysisandrun_spec_analysistools, and a skill file (skills/harm-analysis/SKILL.md) describing how to use the package.
Fixed¶
The
spec-analysistones table header showed “Amplitude” instead of “Amplitude [dB]” (rich read “[dB]” as a style tag); it is now “Power [dB]”, which is what the column holds.harm_analysisandspec_analysiscrashed with aTypeErroron a noise-free tone that is not on an FFT bin, for signals of up to 256 samples: the tone’s peak grew over the whole spectrum (DC included) and left no noise bins. Peaks no longer extend into the DC bins, and when no noise bins are left the noise power is 0 (-infdB, infinite SNR). Harmonics no longer reuse bins of the fundamental, which counted its leakage as distortion in short signals (THD of −20 dB for a pure tone of 32 samples). (#41)Components exactly at fs/2 (a tone in
spec_analysis, or a harmonic such as the 2nd harmonic of a fundamental at fs/4 inharm_analysis) were measured 2.2 dB too high, because the fs/2 bin of even-length signals was doubled like the other bins. In that casetotal_noise_dbwas alsonanwith a warning. A tone at fs/2 is now reported at exactly fs/2. (#49)harm_analysisreporteddc_dbtoo high by the window’s equivalent noise bandwidth (+1.76 dB with the default Hann window, +3.02 dB with Blackman-Harris). DC detection also stopped after the first bin for windows with a flat main lobe, which madespec_analysisreport DC 5.76 dB too low with the flat-top window. DC power is now correct for any window and for even and odd lengths. (#48)spec_analysisoccasionally reported a noise peak as a tone (about 1 in 300 spectra of 2^18 samples). The default detection threshold is now derived fromfalse_alarm_rateand the number of bins (about 13.5 dB above the local noise floor for 1024 samples, 15 dB for 2^18), and the noise floor is estimated over 101 bins instead of 51. Weak tones are detected about 1.5-2 dB closer to the noise floor than with the previous fixed 16 dB threshold. (#43)harm_analysiscrashed withValueError: need at least one array to concatenatewhen all harmonics were outside the band (abovebworfs / 2); it now returnsthd_db = nanand empty harmonic arrays. (#39)harm_analysiscalledsys.exitwhenbwfell inside the DC component of the spectrum, terminating the whole process; it now raises aValueError. (#40)--sfactorwas evaluated witheval(), allowing arbitrary code execution. (#22)harm_analysiscrashed with unhelpful errors on all-zero or DC-only input; it now raises a clearValueError. Powers of zero are reported as-infdB without numpy warnings. (#23)spec-analysisprinted the raw tone arrays in the parameters table and showed no results when no tones were detected. (#24)Docstrings: THD uses
n_harmharmonics (not five), parameter defaults and units,spec_analysispeak-detection parameters. (#28)
Internal¶
1.4.1 - 2025-10-31¶
Fixed¶
1.4.0 - 2025-10-04¶
Changed¶
Harmonic markers in plots start with
H. (#14)
Fixed¶
1.3.0 - 2025-09-28¶
Added¶
Earlier releases¶
See the GitHub releases.