-
-
Notifications
You must be signed in to change notification settings - Fork 152
Resolved issue of magnitude computing at the spectrum charts #821
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
base: master
Are you sure you want to change the base?
Conversation
""" WalkthroughThe internal implementations of Changes
Suggested labels
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 (1)
src/graph_spectrum_calc.js (1)
466-466
: Consider explaining the 100Hz constantThe value
100
in the noise index calculation appears to be a frequency threshold in Hz. Consider extracting this as a named constant to improve code readability.+const NOISE_LOW_END_FREQUENCY = 100; // Hz -const noiseLowEndIdx = 100 / maxFrequency * magnitudeLength; +const noiseLowEndIdx = NOISE_LOW_END_FREQUENCY / maxFrequency * magnitudeLength;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/graph_spectrum_calc.js
(1 hunks)
🧰 Additional context used
🪛 ESLint
src/graph_spectrum_calc.js
[error] 467-468: Missing semicolon.
(semi)
🔇 Additional comments (4)
src/graph_spectrum_calc.js (4)
461-464
: Improved FFT handling for spectrum calculation!This change correctly acknowledges that FFT output consists of complex value pairs (real, imaginary) representing a two-sided spectrum. Computing magnitudes for just one side of the spectrum is the right approach as the other side is redundant for real input signals.
471-479
: Correctly calculating magnitude from complex valuesThis implementation properly computes the magnitude from the complex FFT output using
Math.hypot(re, im)
, which is equivalent tosqrt(re² + im²)
. This gives the true amplitude of each frequency component rather than using real and imaginary parts separately.
481-481
: Properly scaling maxNoiseIdx to frequencyThe calculation now correctly scales the maximum noise index using the magnitude length instead of the full FFT length, which aligns with the reduced spectrum size.
486-488
: Returning the correct magnitude array and lengthThe return object now includes the magnitudes array and updated length, ensuring downstream code receives properly normalized FFT data.
The last commit restores spectrum chart points count, because magnitudes have half points count than it were before. |
please post the BBL used for these screenshots. |
|
The GraphSpectrumCalc._dataLoadFrequencyVsX method what is used in throttle and rpm spectrum has this issue too. Will improve soon. |
Yes, it is interesting. I'll figure it out. |
Seems, PTB has not spectrum by RPM. I have bin checked. The issues at the spectrums top are not just math error. But its have some reasons.
What can try to do:
|
needs to be clarified:
|
|
Will try to use fft with samples segmentation for current chart and will try PSD values too. |
This PR resolves some math issues only. But the charts view change looks as cosmetic. |
The current spectrum has a small issue. The FFT method returns complex output for two-side spectrum. It includes Re and Im complex values parts. The current release get half of complex FFT output and uses it as magnitude data directly. The current algorithm find maximum frequency amplitude value from Re and Im values too. This math is not proper. The spectrum chart shows Re and Im values with wrong 2x frequency resolution instead of true magnitudes.
This PR resolves this issue.
The test log:
btfl_all.txt
The unfiltered roll gyro spectrum before PR:




The unfiltered roll gyro spectrum by using this PR:
The unfiltered pitch gyro spectrum before PR:
The unfiltered pitch gyro spectrum by using this PR:
The different is not big for this spectrum, but this is correct computing.
Summary by CodeRabbit