Skip to content

Added Power Spectral Density curves at the spectrum chart (Completion of #820 PR) #826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 36 commits into
base: master
Choose a base branch
from

Conversation

demvlad
Copy link
Contributor

@demvlad demvlad commented May 5, 2025

Completion of #820 PR "Added power spectral density curves at the spectrum chart"

Power spectral density curve at the spectrum chart.

  1. Select "Power spectral density" type of spectrum chart.
  2. Use vertical scale slider to change curves smooth.
  3. Use mouse cursor by pressing Shift key to look digital values at the chart.
    image
    Default vertical slider position:
    PSD_new
    The maximal vertical slider position:
    PSD_new2

Summary by CodeRabbit

  • New Features

    • Added support for Power Spectral Density (PSD) analysis and visualization in the spectrum graph.
    • Introduced a new "Power spectral density" option in the spectrum type dropdown menu.
    • PSD graphs now display frequency and power values with improved axis labeling and a "Max noise" marker.
  • Style

    • Enhanced graph background contrast for fullscreen mode.
    • Standardized labeling for noise markers on spectrum graphs.

demvlad and others added 30 commits April 30, 2025 17:01
Co-authored-by: Mark Haslinghuis <[email protected]>
Co-authored-by: Mark Haslinghuis <[email protected]>
Copy link

coderabbitai bot commented May 5, 2025

Walkthrough

A new "Power spectral density" spectrum type was added to the application's spectrum analysis features. This includes updates to the HTML dropdown, data loading logic, PSD calculation methods, and graph rendering to fully support PSD visualization and user interaction within the existing spectrum analysis workflow.

Changes

File(s) Change Summary
index.html Added "Power spectral density" (value="4") as an option to the spectrum type dropdown menu.
src/graph_spectrum.js Added logic to load and update PSD data when the new spectrum type is selected and when the vertical zoom changes.
src/graph_spectrum_calc.js Introduced dataLoadPSD, _psd, and _fft_segmented methods for PSD calculation; updated _getFlightSamplesFreq to support unscaled sample retrieval.
src/graph_spectrum_plot.js Added POWER_SPECTRAL_DENSITY to spectrum type enum; implemented _drawPowerSpectralDensityGraph for PSD visualization; updated mouse interaction and margin logic for the new type.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI (index.html)
    participant FlightLogAnalyser
    participant GraphSpectrumCalc
    participant GraphSpectrumPlot

    User->>UI (index.html): Select "Power spectral density" from dropdown
    UI->>FlightLogAnalyser: Notify spectrum type change
    FlightLogAnalyser->>GraphSpectrumCalc: dataLoadPSD(analyserZoomY)
    GraphSpectrumCalc->>GraphSpectrumCalc: _getFlightSamplesFreq(false)
    GraphSpectrumCalc->>GraphSpectrumCalc: _psd(samples, ...)
    GraphSpectrumCalc-->>FlightLogAnalyser: Return PSD data
    FlightLogAnalyser->>GraphSpectrumPlot: setData(PSD data)
    GraphSpectrumPlot->>GraphSpectrumPlot: _drawPowerSpectralDensityGraph()
    GraphSpectrumPlot-->>User: Render PSD graph
Loading

Possibly related PRs

Suggested reviewers

  • haslinghuis

Poem

A new spectrum hops into view,
Power spectral density—fresh and new!
With graphs that sparkle, data that sings,
Zoom and pan with spectral wings.
From dropdowns bright to plots so neat,
This bunny’s code makes PSD complete!
🐇✨📊


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 86423e9 and ee5e5ca.

📒 Files selected for processing (1)
  • src/graph_spectrum_calc.js (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/graph_spectrum_calc.js
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@haslinghuis haslinghuis added this to the 4.0.0 milestone May 5, 2025
@demvlad demvlad changed the title Completion of Power spectral density chart PR Completion of #820 PR "Added power spectral density curves at the spectrum chart" May 5, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (4)
src/graph_spectrum.js (1)

192-199: Debounced PSD recalculation is still expensive – consider caching

Every Y-zoom slider tick recomputes the entire PSD. With long logs the Welch routine is O(N·log N) per segment and can become sluggish even with the 100 ms debounce.
You could short-circuit if analyserZoomY hasn’t crossed a power-of-two boundary (because pointsPerSegment only changes at those thresholds) or memoise the last (zoomY → psd) pair.

src/graph_spectrum_calc.js (3)

109-135: Segment-length heuristic: works but can mis-scale on fine zoom levels

multipiler = Math.floor(1 / analyserZoomY) gives the same value for a large range of zooms (e.g. 1.01-1.99 all map to 0/1/2).
Two suggestions:

  1. Use Math.round() so each 25 % zoom step changes the segment size more smoothly.
  2. Guard against pointsPerSegment < 128 – below that, Welch PSD becomes very noisy.

573-594: Variable shadowing and small optimisation in inner loops

Nested for (let i …) shadows the outer loop index twice (_psd and _fft_segmented).
It’s legal but hurts readability and prevents some JS engines from hoisting. Consider distinct names (j, k) for the inner loops.

Also, computing freqScale = 2 * WIDTH / PLOTTED_BLACKBOX_RATE once outside the loop would avoid recomputing per-point.


610-630: Minor readability nit – reuse loop variables

In _fft_segmented the outer index is i, and an inner loop re-declares i, which is easy to mis-read. Renaming the inner one (for (let k = 0; k < n_per_seg / 2; k++)) makes the control flow clearer.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 20cec88 and b3c4abf.

📒 Files selected for processing (4)
  • index.html (1 hunks)
  • src/graph_spectrum.js (2 hunks)
  • src/graph_spectrum_calc.js (4 hunks)
  • src/graph_spectrum_plot.js (10 hunks)
🔇 Additional comments (4)
index.html (1)

462-462: Add "Power spectral density" option to spectrumTypeSelect
The new <option value="4">Power spectral density</option> correctly enables the PSD view in the dropdown. Please verify that the JavaScript handling (e.g., the enum or switch cases for value 4) is updated to map this option to the POWER_SPECTRAL_DENSITY logic.

src/graph_spectrum.js (1)

119-122: PSD branch wired-up correctly

The new case statement cleanly delegates to GraphSpectrumCalc.dataLoadPSD and guarantees that the returned structure is stored in fftData. No issues spotted here.

src/graph_spectrum_plot.js (2)

1075-1093: Vertical-grid refactor looks good

Allowing variable tick counts makes the helper reusable and doesn’t break existing callers. Nice improvement.


1447-1454: Mouse-over label unit is correct for PSD

Good catch adding "dBm/Hz" and extending the spectrum check – the UX remains consistent across modes.

Also applies to: 1482-1484

@demvlad demvlad changed the title Completion of #820 PR "Added power spectral density curves at the spectrum chart" Added Power Spectral Density curves at the spectrum chart (Completion of #820 PR) May 6, 2025
Copy link

sonarqubecloud bot commented May 7, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants