How to filter a linear potentiometer analog input? Simulink Real Time

조회 수: 5 (최근 30일)
Magne Kloster
Magne Kloster 2017년 5월 11일
댓글: Jeff Dillon 2019년 8월 6일
Hi, I am using a linear potentiometer to measure distance with Simulink Real Time, via an analog input. I want to find the derivative of the input to measure speed, but the analog input value is too noisy to get a good derivative.
So my question is two-fold, How do I design a smoothing filter for my potentiometer, do I use some kind of average filter? and Can I put an averaging filter after the derivative?

답변 (1개)

Gautham Sholingar
Gautham Sholingar 2017년 5월 16일
You can use smoothing functions such as 'smoothdata' to create a moving average filter with a specified window length. The following documentation link explains this in detail:
However, it is important to note that when implementing this in a practical setting, you will need to buffer the data which is being streamed in and then apply this smoothing to that data. This will introduce a delay in the measurements of the velocity as the moving average filter will need a set of values from time instant 1 to say time t.
Another useful approach to handle such scenarios is to build an estimator using a Kalman filter. The estimator will estimate the velocity from the distance measured and this will perform well even with measurement noise or at least converge to good measurements over time. Since the relationship between velocity and distance is known you can design a set of equations which will model this behavior.
The following documentation links are a good starting point to understand Kalman filters and tools available for you to design an estimator:
  댓글 수: 1
Jeff Dillon
Jeff Dillon 2019년 8월 6일
How would you apply the smoothdata function inside a Simulink Function Block? I'm not clear how to pass in the input array, etc to a MATLAB function being called in Normal mode in Simulink. If I'm smoothing across 5 readings for example from an Arduino, I'm aware of the time delay. I was able to implement my own trivial "timestwo" function for learning but of course operates on each incoming value.

댓글을 달려면 로그인하십시오.


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by