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

Question: How are the note bandwidths in your readme calculated? #3

Open
aceamarco opened this issue Nov 21, 2022 · 4 comments
Open
Assignees
Labels
question Further information is requested

Comments

@aceamarco
Copy link

aceamarco commented Nov 21, 2022

Hello,

Thank you for making such a detailed README! I've really enjoyed reading through your theory section. However, I'm having trouble intuiting where your values for the 'note bandwidth' column are coming from. I understand where the 'estimated bandwidth' is coming from (if I understand it correctly it is the sample_rate / N. The Wikipedia page you linked with the piano key frequencies does not mention their bandwidths.

@creaktive
Copy link
Owner

Hi @aceamarco! I'm happy you liked it :)

Very interesting question regarding the bandwidth. Conceptually, the musical note frequencies are the centers of the frequency bands. For instance, the center is 440.0Hz for A4, but if you pick a bandwidth wide enough when analyzing the signal, you'll also detect neighbour notes!

So, for detection of notes, you need a bandwidth around the center frequency that does not overlap with the bandwidth of a neighbour note center frequency. The most intuitive value for the bandwidth is the difference (delta) between the center frequencies of 2 adjacent notes.

But here's where it gets confusing: the difference between A4 & A#4 (next note) is ~26.2Hz; and the difference between A4 & G#4 (previous note) is ~24.7Hz! And of course the difference gets smaller for the lower octaves, and bigger for the higher octaves...

On the other hand, what happens when the band around the central frequency is much narrower? Then the detector loses sensitivity for slightly out-of-tune instruments, since it has lower "tolerance", to speak so. Ultimately, very narrow bandwidth of, say, 0.1Hz, would imply very heavy processing, and it would be only good for detecting high-quality pitchforks, as opposed to real musical instruments ¯_(ツ)_/¯

Anyways, what I am actually using as "note bandwidth" is an approximation chosen in such way that it does not overlap with the next/previous note :)

Hope this helps

@creaktive creaktive added the question Further information is requested label Nov 23, 2022
@creaktive creaktive self-assigned this Nov 23, 2022
@creaktive
Copy link
Owner

Again, thanks for making me curious :)
I made the bandwidth adjustable:

  • https://sysd.org/pianolizer/?tolerance=1: this is the default bandwidth per-note
  • https://sysd.org/pianolizer/?tolerance=2: twice the default, frequencies appear to "bleed" to the neighboring bands
  • https://sysd.org/pianolizer/?tolerance=0.2: one fifth of the default bandwidth, band colors are dimmer
    It is not very likely that I will expose this parameter in the UI; it can not be changed dynamically with a slider since adjusting frequencies/bandwidth/samplerate results in recomputing the whole kernel and starting processing anew.
    Also, I advise against trying any tolerance lower than 0.01, since the memory usage is inversely proportional to the bandwidth, and tolerance=0 would actually try to use infinite memory.

@aceamarco
Copy link
Author

Oooh I see @creaktive, thank you for such a thorough explanation, this was really helpful! I hadn't intuited that the piano frequencies aren't evenly spaced on both sides. Would you say that the ideal bandwidth is the smaller of the two distances to a key's neighboring frequencies? For example, with the distances you mentioned for key A4, a bandwidth <= 24.7Hz would be ideal (because is the smaller distance compared to A4 to A#4 of 26.2Hz) since it doesn't overlap with either key.

@creaktive
Copy link
Owner

I wouldn't dare to say it is ideal, but, generally speaking, lowest possible bandwidth that does not overlap with the neighbour frequencies works really well :)
There's one important detail, although: in pianolizer, both frequency & bandwidth values are rounded to the closest value that can be represented for a given sample rate.
For instance, for 44100Hz sample rate, the A4 band will have the central frequency of 439.96Hz and the bandwidth of 25.88Hz. Close enough :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants