RIP
xooorx The problem is that your sample rate is too high for your Savitzky-Golay window length.
Duh, that's obvious in hindsight, thanks for pointing it out to me so clearly.
xooorx The solution is to increase the window length and/or decrease the sample rate so the S-G gets a better look at the signal. e.g. even just dividing the sample rate by 32 and keeping the S-G at 23 starts to look sensible:
Part of the reasons of this exercise is checking if having such a fast sample rate is any useful, so I'll explore with longer window first -- and then compare the results with ones at (artificially) reduced sample rate. One important question to answer is the following. Can a S-G filter with a slower sample rate reproduce all the velocity MIDI values from 1 to 127 (and possibly even some of the higher resolution ones) or will there be gaps? The previous question should be interpreted "with natural key strikes", obviously if the key strikes are artificially slower, then we are just changing the time scale. We know that with the comparator approach, the answer to this question is "no", because there are gaps if the sample rate is too slow (*), since we need the sample rate to be able to reliably measure the small difference in flying time between (e.g.) MIDI velocities 126 and 127.
If with S-G we don't need such a fast sample rate that is great news, since only very few ADC converters support that, and even then with limitations. However I know how to make a back-of-the-envelope estimate of the needed minimum sample rate for the comparator approach (*) but I am not sure how to do that estimate with S-G. Do you?
Thanks again!
(*) here it is, for the ones who may have missed it in previous posts:
- hammer speed at ff 5 m/s (may actually be even faster, probably up to 8 m/s) i.e. 5 mm/ms
- let-off distance: 2 mm (may actually be even shorter, down to 1 mm)
- time to flight: less than 400 us (potentially down to 100 us)
- desired accuracy ~ 1% (to distinguish MIDI velocity 100 from MIDI velocity 101, more if one wants hi resolution velocities)
- needed time resolution: less than 4 us (potentially down to 1 us)
- sampling rate 0.25 MHz (potentially up to 1 MHz).
This sampling rate is ballpark of what I am using for this test, a factor of 10 faster than @JayKominek 's piano-conversion uses (which by the way is what I hope to eventually use).








