Skip to content

Added FCC Check API calls - #35

Open
hunterhubble wants to merge 2 commits into
HubbleNetwork:mainfrom
hunterhubble:fcc-api-calls
Open

hunterhubble wants to merge 2 commits into
HubbleNetwork:mainfrom
hunterhubble:fcc-api-calls

Conversation

@hunterhubble

Copy link
Copy Markdown
Contributor

No description provided.

- No new tests were designed here
- Add API Call to see if current tone is FCC compliant with
spurious emissions and the occupied bandwidth.
- Previously, this was only visual in the spectrum analyzer view.
- Returns dict with pass/fail, carrier wave stats (frequence, power,
snr, offset), and test stats of occupied bandwidth and spurious
emissions tests

Signed-off-by: hunterhubble <hunter@hubble.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new API response reports an incorrect DC-notch span value and the new endpoint lacks test coverage in a codebase that already tests Flask routes.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR adds a machine-readable FCC 15.247 compliance check endpoint and refactors the spectrum-analyzer overlay logic so both the UI overlay and the new API share a single measurement implementation.

Changes:

  • Introduces evaluate_fcc_compliance() to compute occupied-bandwidth and spur checks (no plotting/I/O).
  • Refactors spectrum averaging/peak-hold computation into spectrum_traces() and reuses it in both rendering and the API.
  • Adds GET /api/fcc_check to capture fresh IQ, compute a spectrum window, and return pass/fail/no-signal results as JSON.
File summaries
File Description
src/stream_web/spectrogram.py Extracts spectrum trace reduction and FCC compliance evaluation into reusable helpers; updates overlay rendering to consume computed results.
src/stream_web/app.py Adds /api/fcc_check endpoint that captures IQ and returns FCC compliance verdict/details using the shared measurement helpers.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/stream_web/app.py
Comment thread src/stream_web/spectrogram.py
Comment thread src/stream_web/app.py
- Added tests to generate artificial signals and verify if they pass/fai
- Testing clean tones, noise only, wide band tone, nearby spurs, and dict formatting

Signed-off-by: hunterhubble <hunter@hubble.com>
Comment thread src/stream_web/app.py
return resp


_FCC_CHECK_DEFAULT_SECONDS = int(config.SPECTRUM_AVG_CHUNKS * config.SPEC_CHUNK_S)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usually constants are placed together for easy readable (at the top of a class for per class constants and top of file for per module constants). Not a big deal in this commit because constants in this file are all over the place, but imo it would make it a bit challenging for new people to pick up the file and have to hunt for the constants.

Comment thread tests/test_spectrum.py
SR = config.SAMPLE_RATE
# Arbitrary test LO -- evaluate_fcc_compliance only cares about frequencies
# relative to it, so this doesn't need to match any real config default.
_TEST_LO_HZ = 903_000_000.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree that it is arbitrary, but it'd be nice to put the LO close to the one our sat signal is at 🙂

# Frequency axis: bins run -fs/2 .. +fs/2 (ascending), centred on the LO.
fs = config.SAMPLE_RATE
freqs_mhz = (np.linspace(-fs / 2.0, fs / 2.0, n_bins) + lo_freq_hz) / 1e6
freqs_hz = np.linspace(-fs / 2.0, fs / 2.0, n_bins) + lo_freq_hz

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I understand linspace correctly, this will produced freq_hz = fs/(n_bins-1), while what we want is fs/(n_bins). Can you double check this please?

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.

3 participants