Invntr
Source

All instruments

spectrum_fft

Spectrum of an equally sampled signal (inline samples, a csv, or a synthetic test signal): windowed FFT amplitude spectrum, peak frequencies and amplitudes refined between bins by a least-squares sine fit, power spectral density (one periodogram or Welch's average), total harmonic distortion, SNR, SINAD, effective bits, SFDR and the noise floor. Writes the spectrum, PSD, peaks and harmonics as csv.

Field
Measurement and data
Version
0.1.0
Runs as
Compiled (Rust)
Typical run
0.2 s

Compiled from source: run sh packs/install.sh once before admitting it.

Known answers it must pass

Admission replayspectrum_fft 0.1.0 · files 0995ce10bfe6…cc99
  1. r0001hand-written samples 2.5 sin(pi n / 2), 16 points at 1 kHz: tone at fs/4 = 250 Hz, amplitude 2.5, RMS 2.5/sqrt 2, mean square A^2/2 = 3.125 (definition of a sampled sine; rel 1e-9)passed

    fundamental_Hz250 ± 2.5e-07250lockedunder 0.01 % of the tolerance used
    fundamental_amplitude2.5 ± 2.5e-092.5lockedunder 0.01 % of the tolerance used
    fundamental_rms1.76777 ± 1.8e-091.76777lockedunder 0.01 % of the tolerance used
    psd_integral3.125 ± 3.1e-093.125lockedunder 0.01 % of the tolerance used
    signal_power3.125 ± 3.1e-093.125lockedunder 0.01 % of the tolerance used
  2. r0002Parseval on hand-written data: the integers 1..16 have mean 8.5 and variance (n^2-1)/12 = 21.25, and the PSD integrates to it (rel 1e-9)passed

    mean8.5 ± 8.5e-128.5lockedunder 0.01 % of the tolerance used
    variance21.25 ± 2.1e-1121.25lockedunder 0.01 % of the tolerance used
    psd_integral21.25 ± 2.1e-0821.25lockedunder 0.01 % of the tolerance used
  3. r0003sine of amplitude 3 on bin 200 with offset 1.5, Hann window: amplitude 3, RMS 3/sqrt 2, power 4.5, no distortion (a Hann-windowed tone on a bin occupies exactly 3 bins; rel 1e-9)passed

    fundamental_Hz200 ± 2e-07200lockedunder 0.01 % of the tolerance used
    fundamental_amplitude3 ± 3e-093lockedunder 0.01 % of the tolerance used
    fundamental_rms2.12132 ± 2.1e-092.12132lockedunder 0.01 % of the tolerance used
    mean1.5 ± 1.5e-091.5lockedunder 0.01 % of the tolerance used
    signal_power4.5 ± 4.5e-094.5lockedunder 0.01 % of the tolerance used
    psd_integral4.5 ± 4.5e-094.5lockedunder 0.01 % of the tolerance used
    thd≤ 1e-098.97211e-17lockedinside the range
  4. r0004Parseval with Welch (Hann, 1024-sample segments, half overlap): tones of amplitude 2 and 1 on segment bins give variance (2^2+1^2)/2 = 2.5 = integral of the PSD; (16384-1024)/512+1 = 31 segments (rel 1e-9)passed

    psd_integral2.5 ± 2.5e-092.5lockedunder 0.01 % of the tolerance used
    variance2.5 ± 2.5e-092.5lockedunder 0.01 % of the tolerance used
    segment_count= 3131lockedexact match
    fundamental_Hz100 ± 1e-07100lockedunder 0.01 % of the tolerance used
    peak2_frequency_Hz300 ± 3e-07300lockedunder 0.01 % of the tolerance used
    peak2_amplitude1 ± 1e-091lockedunder 0.01 % of the tolerance used
  5. r0005two tones between bins (123.4 Hz amplitude 1 phase 30 deg; 310.7 Hz amplitude 0.25; 4096 points at 1 kHz, Hann): both found at their frequencies and amplitudes (rel 1e-6: the other tone leaks into each fit far below that)passed

    fundamental_Hz123.4 ± 0.00012123.4lockedunder 0.01 % of the tolerance used
    fundamental_amplitude1 ± 1e-061lockedunder 0.01 % of the tolerance used
    fundamental_phase_deg30 ± 0.00130locked0.012 % of the tolerance used
    peak2_frequency_Hz310.7 ± 0.00031310.7lockedunder 0.01 % of the tolerance used
    peak2_amplitude0.25 ± 2.5e-070.25lockedunder 0.01 % of the tolerance used
  6. r0006square wave (Fourier series 4/pi sum sin(n w t)/n over odd n), 8192 points per period: fundamental 4/pi, 3rd and 5th harmonics 1/3 and 1/5, no 2nd, THD = sqrt(pi^2/8 - 1) = 48.34 % (rel 2e-6: sampling moves harmonic n by (n^2-1)(pi/8192)^2/6)passed

    fundamental_Hz1 ± 1e-061lockedunder 0.01 % of the tolerance used
    fundamental_amplitude1.27324 ± 2.5e-061.27324locked1.2 % of the tolerance used
    harmonic_3_rel0.333333 ± 6.7e-070.333333locked9.8 % of the tolerance used
    harmonic_5_rel0.2 ± 4e-070.2locked29 % of the tolerance used
    harmonic_2_rel≤ 1e-090lockedinside the range
    thd0.483426 ± 9.7e-070.483426locked6.5 % of the tolerance used
    thd_percent48.3426 ± 9.7e-0548.3426locked6.5 % of the tolerance used
    rms1 ± 1e-121lockedunder 0.01 % of the tolerance used
  7. r0007ideal 12-bit quantiser on a full-scale sine (1021 cycles in 65536 points): SINAD = 6.02 N + 1.76 dB = 74.008 dB, 12 effective bits (abs 0.1 dB, 0.02 bit: the uniform-error model q^2/12 is an approximation)passed

    sinad_dB74.0081 ± 0.174.0305locked22 % of the tolerance used
    enob_bits12 ± 0.0212.0037locked19 % of the tolerance used
    snr_dB74.0081 ± 0.274.0315locked12 % of the tolerance used
    fundamental_amplitude1 ± 0.00011locked0.86 % of the tolerance used
  8. r0008white Gaussian noise of RMS 0.5 at 1 kHz, 262144 points, Welch 1024: one-sided PSD = sigma^2/(fs/2) = 5e-4 per Hz, integral sigma^2 = 0.25 (statistical: 2 %, about 8 standard errors)passed

    noise_floor_psd0.0005 ± 1e-050.000498536locked15 % of the tolerance used
    psd_integral0.25 ± 0.0050.249394locked12 % of the tolerance used
    rms0.5 ± 0.0050.499539locked9.2 % of the tolerance used
  9. r0009inline samples, no generator: 64 points at 6.4 kHz of 2 sin(2 pi 4n/64 + 30 deg) + 0.5 sin(2 pi 12n/64), rect window: 400 Hz, amplitude 2, phase 30 deg, 3rd harmonic 0.5/2, THD = 0.25, SINAD = SFDR = 20 log10 4, mean square (2^2 + 0.5^2)/2 = 2.125 (Parseval; samples rounded to 1e-12, rel 1e-9)passed

    fundamental_Hz400 ± 4e-07400lockedunder 0.01 % of the tolerance used
    fundamental_amplitude2 ± 2e-092lockedunder 0.01 % of the tolerance used
    fundamental_rms1.41421 ± 1.4e-091.41421lockedunder 0.01 % of the tolerance used
    fundamental_phase_deg30 ± 1e-0630lockedunder 0.01 % of the tolerance used
    peak2_frequency_Hz1200 ± 1.2e-061200lockedunder 0.01 % of the tolerance used
    peak2_amplitude0.5 ± 5e-100.5locked0.016 % of the tolerance used
    harmonic_3_rel0.25 ± 2.5e-100.25lockedunder 0.01 % of the tolerance used
    harmonic_2_rel≤ 1e-093.46945e-18lockedinside the range
    thd0.25 ± 2.5e-100.25lockedunder 0.01 % of the tolerance used
    thd_percent25 ± 2.5e-0825lockedunder 0.01 % of the tolerance used
    sinad_dB12.0412 ± 1e-0612.0412lockedunder 0.01 % of the tolerance used
    sfdr_dB12.0412 ± 1e-0612.0412lockedunder 0.01 % of the tolerance used
    signal_power2 ± 2e-092locked0.013 % of the tolerance used
    variance2.125 ± 2.1e-092.125locked0.014 % of the tolerance used
    rms1.45774 ± 1.5e-091.45774lockedunder 0.01 % of the tolerance used
    psd_integral2.125 ± 2.1e-092.125locked0.014 % of the tolerance used
    mean-1e-09 to 1e-091.51788e-17lockedinside the range
  10. r0010inline samples, no generator: 64 points at 64 Hz of 0.75 + 1.5 cos(2 pi 5n/64) + 0.3 sin(2 pi 10n/64) + 0.15 sin(2 pi 15n/64), Hann window: 5 Hz, amplitude 1.5, phase 90 deg, harmonics 0.2 and 0.1, THD = sqrt(0.2^2 + 0.1^2) = sqrt 0.05, SFDR = 20 log10 5, mean 0.75, variance (1.5^2 + 0.3^2 + 0.15^2)/2 = 1.18125 = PSD integral, Hann noise bandwidth 1.5 bins (samples rounded to 1e-12, rel 1e-9)passed

    fundamental_Hz5 ± 5e-095lockedunder 0.01 % of the tolerance used
    fundamental_amplitude1.5 ± 1.5e-091.5lockedunder 0.01 % of the tolerance used
    fundamental_phase_deg90 ± 1e-0690lockedunder 0.01 % of the tolerance used
    peak2_frequency_Hz10 ± 1e-0810lockedunder 0.01 % of the tolerance used
    peak2_amplitude0.3 ± 3e-100.3lockedunder 0.01 % of the tolerance used
    harmonic_2_rel0.2 ± 2e-100.2lockedunder 0.01 % of the tolerance used
    harmonic_3_rel0.1 ± 1e-100.1locked0.021 % of the tolerance used
    thd0.223607 ± 2.2e-100.223607lockedunder 0.01 % of the tolerance used
    sinad_dB13.0103 ± 1e-0613.0103lockedunder 0.01 % of the tolerance used
    sfdr_dB13.9794 ± 1e-0613.9794lockedunder 0.01 % of the tolerance used
    mean0.75 ± 7.5e-100.75lockedunder 0.01 % of the tolerance used
    variance1.18125 ± 1.2e-091.18125lockedunder 0.01 % of the tolerance used
    signal_power1.125 ± 1.1e-091.125lockedunder 0.01 % of the tolerance used
    psd_integral1.18125 ± 1.2e-091.18125lockedunder 0.01 % of the tolerance used
    enbw_bins1.5 ± 1.5e-091.5lockedunder 0.01 % of the tolerance used
    resolution_Hz1 ± 1e-121lockedunder 0.01 % of the tolerance used
  11. r0011inline samples, no generator: +1.5, -1.5 alternating, 16 points at 1 kHz, is 1.5 cos(pi n): a line at the Nyquist frequency fs/2 = 500 Hz of in-phase amplitude 1.5 and RMS 1.5, mean 0, mean square 1.5^2 = 2.25 = PSD integral (definition; rel 1e-9)passed

    fundamental_Hz500 ± 5e-07500lockedunder 0.01 % of the tolerance used
    fundamental_amplitude1.5 ± 1.5e-091.5lockedunder 0.01 % of the tolerance used
    variance2.25 ± 2.3e-092.25lockedunder 0.01 % of the tolerance used
    psd_integral2.25 ± 2.3e-092.25lockedunder 0.01 % of the tolerance used
    signal_power2.25 ± 2.3e-092.25lockedunder 0.01 % of the tolerance used
    mean-1e-12 to 1e-120lockedinside the range
    thd≤ 1e-090lockedinside the range
    fundamental_rms1.5 ± 1.5e-091.5lockedunder 0.01 % of the tolerance used
  12. r0012white Gaussian noise of RMS 0.5 at 1 kHz, 262144 points, one periodogram: the noise floor (median / ln 2, the median of an exponential distribution) is the one-sided PSD sigma^2/(fs/2) = 5e-4 per Hz (statistical: 3 %, about 6 standard errors of the median of 131072 Hann-correlated bins)passed

    noise_floor_psd0.0005 ± 1.5e-050.00049532locked31 % of the tolerance used
    psd_integral0.25 ± 0.0050.249042locked19 % of the tolerance used
    segment_count= 11lockedexact match
12 of 12 cases passed · sandbox macos-seatbeltrecorded from the kernel in a fresh lab

Each line is one reading the kernel checked. The bright band is the tolerance; the needle is the value the instrument actually returned when it was admitted. A needle near the centre line used little of its tolerance.

Inputs

NameUnitDefaultMeaning
samples[]Equally spaced samples, oldest first (16 to 1048576). Give exactly one of samples, csv_text/csv_file, synth.
csv_textThe samples as csv text: one row per sample, one header line allowed, # comments skipped.
csv_fileThe same csv as a file, e.g. "@r0003/trace.csv".
column1-1csv column holding the signal, counted from 0 (-1: the last column).
time_column1-1csv column holding time in seconds, counted from 0; the sample rate is then read from it and the steps must be equal to 0.1 % (-1: none, use sample_rate_Hz).
sample_rate_HzHz1.0Samples per second.
unit1Unit of the samples (V, m/s^2, 1). Amplitudes are in it; the PSD is in its square per Hz.
windowhannWindow over the record (periodic cosine-sum form). rect only when the record holds a whole number of periods.
detrendmeanmean: subtract the record's mean before the transform.
segment_length10Welch segment length in samples for the PSD (0: one periodogram of the whole record). Peaks and tone figures always use the whole record.
overlap10.5Share of each Welch segment shared with the next.
fundamental_HzHzOptional: the fundamental to measure distortion against (left out: the largest peak).
harmonics110Highest harmonic order counted as distortion; harmonics above Nyquist are folded back. 0: every harmonic below Nyquist.
n_peaks15Largest number of peaks reported.
min_peak_ratio10.001Peaks below this share of the largest amplitude are not reported.
synth{}A synthetic signal instead of data: n samples of dc + tones (amplitude sin(2 pi f t + phase)) + a square wave (+amplitude for the first half period) + Gaussian noise (seeded), then an ideal mid-tread quantiser of quantise_bits over +-full_scale.

Readings

NameUnitMeaning
sourcesamples, csv or synth
unitthe unit amplitudes are in
sample_count1
sample_rate_HzHz
record_length_ss
resolution_HzHzbin width of the whole-record spectrum
enbw_bins1equivalent noise bandwidth of the window, in bins
mean
rmsroot mean square after detrending
variancepopulation variance, in the unit squared
peak_to_peak
fundamental_HzHzrefined between bins
fundamental_amplitudepeak amplitude of the fitted sine
fundamental_rms
fundamental_phase_degdegphase of A sin(2 pi f t + phase), t = 0 at the first sample
fundamental_bin1
fundamental_bin_offset1
peak_count1
peak2_frequency_HzHzthe second largest peak, if any
peak2_amplitude
peaksthe fundamental, then the other peaks by size
harmonics_counted1
harmonicsfirst 20 harmonics (all in out/harmonics.csv); relative is amplitude over the fundamental's
harmonic_2_rel1
harmonic_3_rel1
harmonic_5_rel1
thd1sqrt(harmonic power / fundamental power)
thd_percent%
thd_dBdB relative to the fundamental
snr_dBfundamental over everything that is not DC, fundamental or a counted harmonic, in dB
sinad_dBfundamental over noise plus harmonics, in dB
enob_bits1(SINAD - 10 log10 1.5) / (20 log10 2)
sfdr_dBfundamental over the largest other spectral line, in dB
signal_powermean square held by the fundamental, unit squared
harmonic_power
noise_power
psd_methodperiodogram or welch
segment_length1
segment_count1
psd_resolution_HzHz
psd_integralthe PSD summed over frequency: the mean square, unit squared
noise_floor_psdnoise level of the PSD, unit squared per Hz: the median over frequency (tones do not move it), divided by ln 2 for one periodogram or by (1 - 1/(9 K))^3 for a Welch average of K segments, which is what the median of Gaussian noise falls short of its mean by
warnings
spectrum.csv
psd.csv
peaks.csv
harmonics.csv

Try the call

Change a value and the command updates. Nothing runs here; paste it into your terminal or give it to your agent.

Terminal
MCP call