了解卡尔曼过滤器,第7部分:如何在simulink中使用扩展的卡尔曼过滤器万博1manbetx
来自该系列:了解卡尔曼过滤器
Melda Ulusoy, MathWorks
该视频演示了如何使用Simulink中的扩展Kalman滤波器估算非线性摆系统的角度位置万博1manbetx®。
在此视频中,使用SIMScape MultiBody™在Simulink中建模了一个简单的摆系统。万博1manbetx使用Control System Toolbox™中可用的扩展Kalman滤波器块估算非线性摆系统的角位置。该视频显示了如何指定扩展的Kalman滤波器块参数,例如状态过渡和测量功能,初始状态估计和噪声特征。如果您想实时对硬件进行状态估计,可以从Simulink中的扩展Kalman滤波器块中生成C/C ++代码,并将其部署到硬件。万博1manbetx
Download this virtual labto study linear and extended Kalman filter design with interactive exercises.
在此视频中,我们将演示如何在Simulink中使用扩展的Kalman过滤器。万博1manbetx以前,我们已经使用了一个简单的摆系统,并假设摆锤的角位置Theta是用传感器测量的。为了滤除嘈杂的测量,我们使用了卡尔曼过滤器,并表明当Theta的初始条件很小时,它提供了良好的估计。但是,当我们将theta的值提高到90度时,我们无法准确估计,因为摆模模型非线性地用于较大的theta值。因此,为了估计该非线性系统的theta,我们将使用扩展的卡尔曼过滤器。
We’ll start by adding the Extended Kalman Filter block from Control System Toolbox to our model. Remember that in the previous videos we’ve discussed that state transition and measurement functions might be nonlinear, and how the extended Kalman filter algorithm uses linear approximations to these nonlinear functions to compute the state estimates. Now, in the Extended Kalman Filter block, we will specify these functions. Here, we’ll use MATLAB functions to create f and g, but note that you can also use Simulink function blocks. The state transition function uses the current state and the input to determine how the states of the next time step will be calculated. Here, any input to the state transition function other than the states and process noise is connected through an input port. So, we connect u as the first input to the block. We first discretize this signal using a zero-order hold as the Extended Kalman Filter block estimates states of a discrete nonlinear system.
在我们的示例中,我们不会指定Jacobian,因为它将通过数值计算。但是,如果有分析性的Jacobian,您可以创建一个函数来计算它并在此处输入该功能的名称。接下来,我们输入流程噪声协方差,我们先前在脚本中定义了该协方差。我们还输入状态的初始值。在摆模型中,以90度和0速度初始化theta。我们在扩展的Kalman滤波器块中使用相同的值。由于我们知道初始状态值,因此我们将将初始状态估计误差协方差设置为小值。但是,如果您对初始状态值没有信心,则可以为协方差指定高价值。
接下来,我们指定的测量功能,再次sing a MATLAB function. Then we connect the measured theta corresponding to the measurement function that we’ve just specified in the block. And we enter the measurement covariance whose value has been previously defined in the script. Remember that a Kalman filter is also referred to as a sensor fusion algorithm, since it combines measurements from multiple sensors to reduce the uncertainty in the state estimate. So, if you have multiple measurements, you can enter them by clicking “Add Measurement.” And different sensors may have different sampling rates, so you can specify the sample times of measurements and the state transition under the “Multirate” tab. And lastly, we enter the sample time.
现在,我们指定了扩展的Kalman滤波器块的参数,我们可以运行此模拟并查看结果。在这里,蓝色信号显示了实际的theta,嘈杂的信号显示了测量值,绿线是估计的theta。该结果表明,尽管摆系统是非线性的,但使用扩展的卡尔曼滤波器可以很好地估计theta。但是,请注意,如果您的系统中有更严重的非线性,则扩展的卡尔曼过滤器可能不足以处理系统中的非线性。但是在这种情况下,您可以使用无气味的卡尔曼过滤器,您可以在控制系统工具箱中找到该过滤器。
In this simulation, we showed how to estimate states of a nonlinear system using the extended Kalman filter. If you’re interested in running state estimation on your hardware in real time, you can generate code from this block and deploy it to your hardware. Remember that Kalman filter algorithm consists of two steps: the prediction and the correction. If you look at the generated code, you’ll recognize functions that take care of the calculation of these algorithm steps. This code snippet for example shows how the correction is calculated.
在这里,我们总结了有关卡尔曼过滤器的讨论。在本系列中,我们讨论了为什么您会使用Kalman过滤器,它们是什么,如何处理非线性系统中的状态估计,并且我们还显示了Simulink中的示例。万博1manbetx我们将继续进行控制科技谈判,讨论不同的控制主题。同时,请随时发表任何评论,并分享有关未来主题的建议。
下载代码和文件
Related Products
Learn More
Featured Product
Control System Toolbox
选择一个网站
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:。
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
美洲
- América Latina(Español)
- 加拿大(英语)
- 美国(英语)
Europe
- Netherlands(英语)
- Norway(英语)
- Österreich(Deutsch)
- 葡萄牙(英语)
- 瑞典(英语)
- Switzerland
- United Kingdom(英语)
亚太地区
- Australia(英语)
- 印度(英语)
- New Zealand(英语)
- 中国
- 日本日本人(日本語)
- 한국Korean(한국어)