Skip to content
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

Hanning window applied to input data (fftInput, not fftOutput) #491

Merged
merged 2 commits into from
Jan 5, 2021

Conversation

bw1129
Copy link
Contributor

@bw1129 bw1129 commented Jan 4, 2021

This PR is a minor improvement of the Spectrum Graph (PR #322)

A Hanning window is a taper that "tapers" (i.e., smooths) the edges of data segments used for fft, so that the Fourier output does not contain artifacts from the sharp edges at the start and end of data segments. In PR #322, it was incorrectly applied to the output data (processed Fourier data), but in fact was never called, and should have instead been applied to the input data segments ('fftInput'). The result was occasional streak artifacts along the frequency domain (x-axis) of the 'Freq. vs Throttle' plots (see below).

Screen Shot 2021-01-04 at 3 48 31 PM

For this PR, I simply moved the Hanning window portion of the code before fft was computed and applied it to Input data ('fftInput') instead of output data ('fftOutput'). 'fftChunkLength * 2' was changed to just 'fftChunkLength' because it is the correct width for the Hanning window and did not need a multiplier. I also turned on the "use Hanning Window" in the user settings, which was previously off ('false') by default. The improvement of these changes to the spectrogram (using the exact same log file as above) can be seen below.

Screen Shot 2021-01-04 at 3 53 50 PM

This is my first PR so my apologies if I've done something wrong here. Please let me know. thx -Brian

A Hanning window is a taper that "tapers" the edges of data segments before performing fft, so the Fourier output does not contain artifacts from the sharp edges at the start and end of data segments. Here, it was incorrectly applied to the output data (the Fourier data). The result was streak artifacts along the frequency domain of the "Freq. vs Throttle" plots in BBE. Here, I simple moved the Hanning window portion of the code before fft was computed and applied it to Input data ('fftInput') instead of output data ('fftOutput').
Hanning window was defaulted as "false", but should be on by default.
@sonarcloud
Copy link

sonarcloud bot commented Jan 4, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

Copy link
Member

@mikeller mikeller left a comment

Choose a reason for hiding this comment

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

Thanks, this is valuable!

@@ -60,7 +60,7 @@ function UserSettingsDialog(dialog, onLoad, onSave) {
graphExpoOverride : true, // Ability to toggle Expo off=normal/ on=force 100%
graphGridOverride : true, // Ability to toggle Grid off=normal/ on=force disabled
analyserSampleRate : 2000/*Hz*/, // the loop time for the log
analyserHanning : false, // use a hanning window on the analyser sample data
analyserHanning : true, // use a hanning window on the analyser sample data
Copy link
Member

Choose a reason for hiding this comment

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

General remark: This line uses tabs instead of the 4 spaces normally used in this project. Yes, this is not your change, but as in most projects, it is seen as polite if code is left 'at least as good as, if not better' than how it was found, so this could have been fixed as part of the pull request.

@mikeller mikeller added this to the 3.6.0 milestone Jan 5, 2021
@mikeller mikeller merged commit 973f354 into betaflight:master Jan 5, 2021
@McGiverGim
Copy link
Member

I know I arrive late to this, but I was out. Only want to say that I'm not too sure to apply the hanning by default. This hanning is applied to all the spectrum types and the results are very different for some of them (I think remember the standard spectrum).

I don't know nothing about the maths that produce this, so maybe the results are more correct with them applied, but the spectrum will be very different between versions and between the people who upgraded (it will remain disabled) and the people who installed it from zero (it will be enabled).

As I say maybe this is the correct move, but is good that we know the implications. @bw1129 have you verified the other spectrum maths to confirm that the hanning is applied correctly?

@bw1129
Copy link
Contributor Author

bw1129 commented Jan 7, 2021 via email

@mikeller
Copy link
Member

mikeller commented Jan 9, 2021

@McGiverGim: I see your concern about changing the default for new installations, but not for existing ones. But on the other hand I think having the Hanning window applied correctly is a fix, and that it makes sense to have it on by default, as there are some plots that can benefit from this.
My approach would be to mitigate the change of defaults by adding a note about it to the release notes. What do you think about this?

@McGiverGim
Copy link
Member

It's perfect for me. As you know my maths level is very basic, so if you think this is an improvement, it's ok for me.

@bw1129
Copy link
Contributor Author

bw1129 commented Jan 9, 2021 via email

@bw1129
Copy link
Contributor Author

bw1129 commented Jan 9, 2021 via email

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.

3 participants