Add FFT pulse-spectrum analyzer (closes #12)#27
Merged
jack-champagne merged 3 commits intoJun 18, 2026
Conversation
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
This was referenced Jun 11, 2026
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! |
Contributor
Author
|
Thanks @jack-champagne ! Happy to answer any questions on the design choices. Looking forward to your feedback. |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #12
What
pulse_spectrum(pulse; n_samples=1000)insrc/post_process.jl: samples anyPiccolo.AbstractPulseviaPiccolo.sample, computes the one-sided power spectrum of eachdrive channel with FFTW (
rfftalong the time axis), and returns(freqs_GHz, power::Matrix)with one row per drive channel. Durations are in ns, sorfftfreq(n, 1/dt)yields GHz directly.plot_pulse_spectrum(pulse; kwargs...): newStrettoMakieExtpackage extension (Makie asa weak dependency, following the
PiccoloMakieExtpattern — 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.[deps], Makie to[weakdeps], both with compat entries.Why these choices
rfft/rfftfreqgive the one-sided spectrum directly for real-valued controls (no manualslicing of a two-sided FFT) — the spec's
fftfreqsnippet, one-sided.|X|²(documented in the docstring and pinned by a test).floatmin(Float64)only inside the plot so an identically-zerodrive channel can't crash the log axis; returned data is untouched.
default_post_process, noCompilationReportchanges.Tests
Two new
@testitems insrc/post_process.jl:ZeroOrderPulsewith sines at 0.05 GHz and 0.20 GHz produces per-channelspectral peaks within one frequency bin of the true frequencies (also pins the return-shape
contract:
n÷2+1non-negative freqs,(n_drives, n_freqs)power matrix);(amplitude·n)², pinning the normalization.Full suite passes locally (Julia 1.12, macOS):
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.
Disclosure
I used Claude (Anthropic) to help draft the implementation and tests, which I then reviewed,
manually verified, and tested locally.