Skip to content

ke4ahr/pydiffsa

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pydiffsa

Periodic windowed frequency (spectral) analysis of WAV files.

pydiffsa applies a Hann-windowed FFT at regular hop intervals across one or two WAV files and prints the frequency bin magnitudes in dBFS for each window. When two files are given, it can compute the averaged per-bin dB difference (B − A) across all windows — useful for comparing a reference signal against a synthesised or processed version of it.


Requirements

  • Python 3.8+
  • numpy (optional but recommended — falls back to a pure-Python DFT if absent)

No other dependencies. numpy is used when available for fast FFT computation; without it a pure-Python O(N²) DFT is used, which is noticeably slow for large frame sizes.


Installation

# No install step needed — run directly
python3 pydiffsa.py file.wav

# Optional: install the man page
sudo install -m 644 pydiffsa.1 /usr/local/share/man/man1/

Quick Start

# Spectrum of a single file (per-window + average)
python3 pydiffsa.py file.wav

# Averaged spectrum only
python3 pydiffsa.py file.wav --avg

# Compare two files
python3 pydiffsa.py ref.wav gen.wav --avg

# Compare two files and show per-bin dB difference
python3 pydiffsa.py ref.wav gen.wav --avg --diff

# Larger window, specific hop, lower noise floor
python3 pydiffsa.py ref.wav gen.wav --frame-size 512 --hop 256 --avg --diff --floor -96

# Suppress bar charts
python3 pydiffsa.py file.wav --avg --no-bar

# Save difference report
python3 pydiffsa.py ref.wav gen.wav --avg --diff > report.fa

Options

Option Default Description
--frame-size N 256 FFT window size in samples
--hop N frame-size/2 Hop size between successive windows
--top N 15 Number of highest-magnitude bins to print per window
--floor dB -80.0 Noise floor in dBFS — bins at or below this are suppressed
--avg off Print only the averaged spectrum; suppress per-window output
--diff off Show per-bin dB difference (B − A); requires two files
--no-bar off Suppress ASCII bar charts
--version Print version and exit
-h, --help Print usage summary and exit

Frame size should be a power of two for best performance with numpy (e.g., 128, 256, 512, 1024).


Output Format

Per-window spectrum

t= 0.0000s  [file.wav]
   Freq (Hz)    dBFS
      440.0    -12.34  ################
     1320.0    -18.76  ###########
     ...

Averaged spectrum

=== Average spectrum [file.wav] (47 windows) ===
   Freq (Hz)    dBFS
      250.0    -22.10  ########
      ...

Difference report (--diff)

=== Spectrum difference (gen.wav − ref.wav), averaged over 47 windows ===
  (positive = gen.wav louder, negative = ref.wav louder)
   Freq (Hz)    ΔdB
      500.0     +3.21  +++
     4000.0     -1.87  -
      ...

Bins whose absolute difference is less than 0.5 dB are suppressed in the difference report.


WAV File Support

  • Sample widths: 8-bit (unsigned) and 16-bit (signed PCM)
  • Channels: mono and stereo (stereo is mixed down to mono before analysis)
  • Sample rates: any rate; a warning is printed if two files have different rates and --diff is used

Man Page

A pydiffsa.1 man page is included. Install it or view it with:

man ./pydiffsa.1

License

Copyright (C) 2026 Kris Kirby, KE4AHR.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. See COPYING or https://www.gnu.org/licenses/ for details.

About

Python diff(1) and Spectrum Analyzer for comparing WAV files.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors