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

Request for sin^4 window + upto 65536 Samples #58

Closed
Sam-Belliveau opened this issue Nov 7, 2023 · 4 comments
Closed

Request for sin^4 window + upto 65536 Samples #58

Sam-Belliveau opened this issue Nov 7, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@Sam-Belliveau
Copy link

My goal is to replicate the graph shown in the following video: https://youtu.be/cIQ9IXSUzuM?si=t4-2h-clXiYK6o0A&t=775

image

Why sin^4

Typically, many window functions, such as Hann, are a "Raised Cosine" functions. Which look like:
image

This is actually just equal to sin^2. On the other hand, sin^4 has the advantage of tapering more on the sides, which looks like:
image

When combined with a large sample window like 65536 samples, this could reduce the noise in the graph, leading to better graphs, and reduce the noise. This would also make the graph less jittery from frame to frame. As you can see from the youtube video, their graph is very smooth, and they are using the same FFT library that this project is.

Replace Exponential Moving Average with time variant version.

The moving average lets you select "gravity," which I assume is just the amount you weight the previous value with the new one. This is in general not a great way to do this because it depends on frame rate. What you should do is replace this with this equation that is calculated on each frame:

image

In code this would be gravity = std::exp(-dt / m_RC). Where dt is the time in seconds between the previous frame and this one. RC can be changed such that higher RC values make the graph smoother and lower RC values make the graph update faster. This would be easier to control than the Gravity knob, while leading to the same smoothing effect.

I would be willing to make a PR that does these if this is too much of a hassle, I was just wondering if these would be easy to implement?

@Sam-Belliveau
Copy link
Author

Sam-Belliveau commented Nov 7, 2023

Frequency Response of Various Windows: Desmos Used in Test

What you will noice is that the different window functions have tradeoffs between the width of the frequency response and the noise floor. I personally prefer a lower noise floor as you can always shrink the frequency response width by increasing the number of samples. (I show this in the last image)

I think that the following images will show that sin^4, and other powers of sin have much lower noise floors than the window functions offered currently.

no window

image

Blackman Harris

image image

sin^1

image

sin^2 (Hann)

image image

sin^4

image image

sin^6

image

sin^8

image

sin^10

image image

sin^10 (2x number of samples)

image image

@phandasm
Copy link
Owner

phandasm commented Nov 8, 2023

Sure, the sin^4 window is no problem.
And I had actually considered replacing the EMA with a time compensated version previously but I don't want to break people's settings so that one would be an addition rather than a replacement.

@phandasm phandasm added the enhancement New feature or request label Nov 8, 2023
@Sam-Belliveau
Copy link
Author

It might be worth adding a sin^10 or sin^16 option that could be combined with 65k samples. That would be for when you want frequency accuracy more than anything else as those windows at that sample size would have a practically zero noise floor. It would be less useful for real time audio though because of the ~0.5s latency it would add. Maybe a warning at high FFT sizes saying something like, "high sample sizes add latency to measurements".

@phandasm
Copy link
Owner

All pushed to master now.
Scaling on the EMA slider probably leaves something to be desired but it at least works for the moment.
Let me know if there's any issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants