luns
RIP luns The 'few points away from strike' boils down to a trade-off. Fewer points = more bandwidth = more noise, but also less latency.
What do you mean less latency? (*) Assuming you have enough compute horsepower to do the math (which I think the STM32 does, perhaps not so on the RPiPico), you can do more points, say 50? 100? Again, these are just "a few".
By latency, I mean the group delay of the filter.
When you're smoothing out a curve, to determine what a given point of the smoothed curve should be, you'd want to look at samples near that point. Not only do the samples before the point inform you of where the point ought to be, but samples afterwards have information too, so it's nice to be able to look into the future. However, if you're processing samples as they come in, you know everything up to and including the present time, but nothing of the future.
Let's say you want to estimate a smoothed value of sample n based on 6 previous samples, and 6 'future' samples, how do you do that? You wait until sample n+6 is available and retroactively figure out based on samples n-6 through n+6 what the smoothed value at sample n ought to be. However, it's now 6 cycles after when sample n was current. Or less hypothetically, you just finished estimating what the hammer position was 6 cycles ago.
This is what FIR filters (finite impulse response) typically do, the default Savitzky-Golay filter included - they look at a finite number of samples symmetrically before and after, together with a delay to make things causal, and this is normally done specifically to allow this symmetry. While it's possible to make asymmetric FIR filters, if you're going to take into account more past samples than future samples, there's no need to limit yourself to a finite window; you can look at samples going infinitely far back into the past. This is known as IIR.
It's not possible to re-evaluate all the (infinitely many) past samples one-by-one at each time step the way you do for FIR. Instead, you maintain a state that captures what you need of all that history, and let that state decay exponentially while you replenish it with information from new samples. The weight with which you consider the past samples falls off exponentially instead of abruptly going to zero at the edge of an FIR window. The time constant of the decay is in some ways comparable to the length of an FIR window, also contributing a group delay (latency) in a similar manner. Also, while the weighting of far past samples necessarily falls off exponentially, that exponent doesn't have to carry all the way up to the present: you can also have what's essentially an FIR filter to shape things closer in.







