Skip to content

Add FFT pulse-spectrum analyzer (closes #12)#27

Merged
jack-champagne merged 3 commits into
harmoniqs:mainfrom
Oishi1029:fft-pulse-spectrum-issue-12
Jun 18, 2026
Merged

Add FFT pulse-spectrum analyzer (closes #12)#27
jack-champagne merged 3 commits into
harmoniqs:mainfrom
Oishi1029:fft-pulse-spectrum-issue-12

Conversation

@Oishi1029

Copy link
Copy Markdown
Contributor

Closes #12

What

  • pulse_spectrum(pulse; n_samples=1000) in src/post_process.jl: samples any
    Piccolo.AbstractPulse via Piccolo.sample, computes the one-sided power spectrum of each
    drive channel with FFTW (rfft along the time axis), and returns
    (freqs_GHz, power::Matrix) with one row per drive channel. Durations are in ns, so
    rfftfreq(n, 1/dt) yields GHz directly.
  • plot_pulse_spectrum(pulse; kwargs...): new StrettoMakieExt package extension (Makie as
    a weak dependency, following the PiccoloMakieExt pattern — docstring on a stub in src,
    method added in the extension). Plots all drive channels on a shared axis, frequency in
    GHz vs. power on a log y-axis; extra kwargs forward to the Axis.
  • FFTW added to [deps], Makie to [weakdeps], both with compat entries.

Why these choices

  • rfft/rfftfreq give the one-sided spectrum directly for real-valued controls (no manual
    slicing of a two-sided FFT) — the spec's fftfreq snippet, one-sided.
  • Power is the unnormalized FFTW |X|² (documented in the docstring and pinned by a test).
  • Plotted power is clamped at floatmin(Float64) only inside the plot so an identically-zero
    drive channel can't crash the log axis; returned data is untouched.
  • Per the issue's out-of-scope list: no filtering, no automatic wiring into
    default_post_process, no CompilationReport changes.

Tests

Two new @testitems in src/post_process.jl:

  • a two-channel ZeroOrderPulse with sines at 0.05 GHz and 0.20 GHz produces per-channel
    spectral peaks within one frequency bin of the true frequencies (also pins the return-shape
    contract: n÷2+1 non-negative freqs, (n_drives, n_freqs) power matrix);
  • a constant pulse is pure DC with power (amplitude·n)², pinning the normalization.

Full suite passes locally (Julia 1.12, macOS):

Test Summary: | Pass  Total   Time
Package       |  116    116  47.6s
     Testing Stretto tests passed

Makie extension smoke-tested locally with CairoMakie — peaks land at 0.04995 GHz and
0.1998 GHz for input sines at 0.05 and 0.20 GHz (within one frequency bin). Demo plot attached below.

spectrum_demo

Disclosure

I used Claude (Anthropic) to help draft the implementation and tests, which I then reviewed,
manually verified, and tested locally.

Add pulse_spectrum(pulse; n_samples=1000), which samples a pulse via
Piccolo.sample and returns the one-sided power spectrum of each drive
channel computed with FFTW (frequencies in GHz, durations in ns).

Add plot_pulse_spectrum(pulse; kwargs...) as a stub implemented in a new
StrettoMakieExt package extension (Makie weak dependency), plotting every
drive channel's spectrum on a shared log-scale axis.

Tests verify that sinusoidal pulses at known frequencies produce spectral
peaks at those frequencies and that a constant pulse is pure DC.

Closes harmoniqs#12
@jack-champagne

Copy link
Copy Markdown
Member

Hi @Oishi1029, thanks for your submission to #12 for unitaryHACK! 👋 We've done an initial read-through and it looks like a real, well-formed contribution. We're pulling it down to run the test suite locally tonight and will follow up with detailed feedback in the morning. Appreciate your patience!

@Oishi1029

Copy link
Copy Markdown
Contributor Author

Thanks @jack-champagne ! Happy to answer any questions on the design choices. Looking forward to your feedback.

@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 40.00000% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
ext/StrettoMakieExt.jl 0.00% 9 Missing ⚠️

📢 Thoughts on this report? Let us know!

@jack-champagne jack-champagne merged commit ddee3b1 into harmoniqs:main Jun 18, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add FFT pulse-spectrum analyzer

2 participants