Ultrasonic Sensor to sense only rapid movements

Hi im new to programming and i need help. So im trying to make a project baby incubator that will alert if a baby moves rapidly inside it, im using a ultrasonic sensor but i dont know how to make it react to rapid movements only ant not to the slow and normal movements of the baby.

newDist = ping

if abs(oldDist - newDist) > threshold
Alarm()

oldDist== newDist

something like this would be my first try

jonasnic:
newDist = ping

if abs(oldDist - newDist) > threshold
Alarm()

oldDist== newDist

something like this would be my first try

…but without all the semantic errors.