# Calculating velocity from position in a noisy enviroment

• posted

Hi,

I've got a problem with calculating velocity from position data. Here's what I've got

• A variable resistor that tells you the position of the object to be tracked
• An A-D converter that samples the resistor every 10ms
• I can track the position of the object and output a control signal to my motor to stop it at the desired point
• Inertia keeps the object moving and I get oscillations
• I believe I can calculate velocity simply by saying V = ( Position(Current) - Position(Previous) ) / Sampling Time
• When I examine my calculation by outputing it to a port I get wild positive and negative variations due to noise from the variable resistor
• I can't add an external filter to the system, I must deal with the noise in software.
• I've tried a several types of filter (Averaging and simple low pass filters) but the signal is still too noisy.

Do you have any suggestions?

• posted

A more typical filter would be the alpha beta (gamma) filter

Not more complicated then a simple IIR and therefore appropriate for a microprocessor.

MfG JRD

• posted

That's what we used to use to filter sensor values back when I worked on fire control firmware for a DoD contractor.

Not all hardware people believe that. ;)

```--
Grant```
• posted

It's as simple an an IIR filter because it _is_ an IIR filter -- it's just done with a formulation to make it easier to apply to problems like this.

OP: If you do this, pay attention to how you could use your drive command for your velocity update.

No, but it can mask a lot of problems until after you've fielded systems :-(.

```--
http://www.wescottdesign.com```
• posted

1: Change the plant. Sometimes a mechanical arrangement just isn't controllable in a satisfactory way, and you need to do something about it. 1a: Use a better pot.

1b: Use a different position sensor, such as an encoder, an RVDT, or a resolver.

1c: Put a tachometer or an encoder on the motor itself (this has advantages beyond just using a better sensor, if your motor has to go through any sort of a reduction drive).

2: Filter more. I assume that you've already tried this, and can't find a good tradeoff between how heavy a filter you need for noise suppression vs. how light a filter you need for good control, but I thought I'd toss out the suggestion.

2a: Knowing the relevant theory can help in cases like this:

3: If you need snappy positioning but can get away without the worlds best disturbance rejection, consider using feed forward.

3a: Cleverly applied, the alpha-beta filter cited in another response will let you construct a gizmo called an "observer" that gives you a nice structured way to make a system with lots of feed forward that does what you want -- but it helps to know your control theory.

4: Change your amplifier. If you're driving the motor with a current amplifier then try changing it to a voltage amplifier -- this has the effect of making the motor more of a constant-velocity device which adds some nice damping, at the cost of not being able to directly limit current to the motor.

4a: If you arrange your amplifier with just the right level of negative resistance you can _really_ make it a constant velocity drive, with a whole big pile of caveats. Do a web search on "tape capstan drive" to see how it's done.

5: Ask questions like this on sci.engr.control. There's folks there with lots of experience; if you make sure to explain your circumstance they'll help you out as much as they can.

```--
http://www.wescottdesign.com```
• posted

Since the OP can (and it seems to me, should) prepare a process/system model for his case, the Kalman filter seems better in this case. (And more work to do.)

Jon

• posted

Kalman filters work great when you can get an exact model of the system and the noise, and the noise is Gaussian.

If you can't then by the time you get done with all the approximations the "Kalman" filter for such a simple system will look an awful lot like an alpha-beta filter -- so why not go there from the get-go?

```--
www.wescottdesign.com```
• posted

Alpha-beta appears inferior to me if the OP can work out a model. If not, then it all boils down to an ad-hoc, static arrangement anyway and I agree.

Jon

• posted

Is the A/D under software control?

Regards,

-- Walter Banks Byte Craft Limited

• posted

Hi Walter,

The A/D converter is built into the microcontroller so I guess that yes it is under software control.

• posted

Which processor a/d ? Where I am coming from is it is possible in some cases to build some filtering into the analog conversion from the pot. This makes the problem both earlier ad likely have a better frequency response than more complex processing after the conversion.

Feel free to contact me off line

Regards,

-- Walter Banks Byte Craft Limited

```--