I'm smoothing position data read in from an external source then executing a finite difference to get velocity... I am also smoothing both results. The smoothing returns a number for the position but nan for the velocity... Can anyone help me with this? Below is just the relevant portion of code.
@jreef, if you knew this was the "relevant" portion you would have solved the problem, wouldn't you?
Supply a complete compilable example, with input, that reproduces the problem. If the input can only come from a serial port then, nevertheless, supply complete code and we can probably "fake" the input.
Your function (as supplied here) doesn't "return" anything, so what you have written is nonsense. Moreover, we can't see what interaction you have with global variables (because you refuse to supply complete compilable code).
In your function loop() (as supplied here, but who knows if it is your actual function, because you haven't supplied complete code) ps and vs are local variables, so their value isn't going to be known outside that function, irrespective of whether you have yet more variables with the same name outside the function. In particular, you couldn't set psold to the value of ps calculated in loop().
If you think a particular statement produces a NaN then simply print out the value of all variables in it on the line before.
BTW, you are not really "smoothing" data - you are effectively increasing the inertia of the system and making its response more sluggish.