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

5 次查看(过去 30 天)
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Spectral Analysis 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by