Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
96129 views
�
�g�Uc@`s�dZddlmZmZmZmZddlmZmZm	Z	m
Z
ddlmZm
Z
ddd�Zddd�Zd�Zddd	d
�ZdS(u4Copyright 2015 Roger R Labbe Jr.

FilterPy library.
http://github.com/rlabbe/filterpy

Documentation at:
https://filterpy.readthedocs.org

Supporting book at:
https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python

This is licensed under an MIT license. See the readme.MD file
for more information.
i(tabsolute_importtdivisiontprint_functiontunicode_literals(tarraytzerostvstackteye(texpmtinvg�?cC`s�|dks|dkst�|dkrmtd|dd|dgd|d|dggdt�}nbtd|dd|dd|dgd|d|d|gd|d|dggdt�}||S(u� Returns the Q matrix for the Discrete Constant White Noise
    Model. dim may be either 2 or 3, dt is the time step, and sigma is the
    variance in the noise.

    Q is computed as the G * G^T * variance, where G is the process noise per
    time step. In other words, G = [[.5dt^2][dt]]^T for the constant velocity 
    model.

    **Paramaeters**

    dim : int (2 or 3)
        dimension for Q, where the final dimension is (dim x dim)

    dt : float, default=1.0
        time step in whatever units your filter is using for time. i.e. the
        amount of time between innovations

    var : float, default=1.0
        variance in the noise
    iig�?ig�?tdtypei(tAssertionErrorRtfloat(tdimtdttvartQ((s#./filterpy/common/discretization.pytQ_discrete_white_noises''#cC`s�|dks|dkst�|dkrct|dd|ddg|dd|gg�}nvt|dd|dd|ddg|dd|dd|ddg|dd|dd|ggdt�}||S(	u
 Returns the Q matrix for the Discretized Continuous White Noise
    Model. dim may be either 2 or 3, dt is the time step, and sigma is the
    variance in the noise.

    **Paramaeters**

    dim : int (2 or 3)
        dimension for Q, where the final dimension is (dim x dim)

    dt : float, default=1.0
        time step in whatever units your filter is using for time. i.e. the
        amount of time between innovations

    spectral_density : float, default=1.0
        spectral density for the continuous process
    iiiiiiiR
(RRR(R
Rtspectral_densityR((s#./filterpy/common/discretization.pytQ_continuous_white_noise<s'$+cC`s|jd}td|d|f�}|j|�|d|�d|�f<|j|j�j|�|d|�|d|�f<|jj|�||d|�|d|�f<t|�}||d|�|d|�fj}|j|d|�|d|�f�}||fS(u� Discretizes a linear differential equation which includes white noise
    according to the method of C. F. van Loan [1]. Given the continuous
    model

        x' =  Fx + Gu

    where u is the unity white noise, we compute and return the sigma and Q_k
    that discretizes that equation.


    **Example**::

        Given y'' + y = 2u(t), we create the continuous state model of

        x' = | 0 1| * x + |0|*u(t)
             |-1 0|       |2|

        and a time step of 0.1:


        >>> F = np.array([[0,1],[-1,0]], dtype=float)
        >>> G = np.array([[0.],[2.]])
        >>> phi, Q = van_loan_discretization(F, G, 0.1)

        >>> phi
        array([[ 0.99500417,  0.09983342],
               [-0.09983342,  0.99500417]])

        >>> Q
        array([[ 0.00133067,  0.01993342],
               [ 0.01993342,  0.39866933]])

        (example taken from Brown[2])


    **References**

    [1] C. F. van Loan. "Computing Integrals Involving the Matrix Exponential."
        IEEE Trans. Automomatic Control, AC-23 (3): 395-404 (June 1978)

    [2] Robert Grover Brown. "Introduction to Random Signals and Applied
        Kalman Filtering." Forth edition. John Wiley & Sons. p. 126-7. (2012)
    ii(tshapeRtdottTR(tFtGRtntAtBtsigmaR((s#./filterpy/common/discretization.pytvan_loan_discretizationZs/
&50')icC`s�|jd}|dkr(t|�}n|dkrIt||f�}nt||�}td|d|f�}||d|�d|�f<|j|�j|j�|d|�|d|�f<|j||d|�|d|�f<tt||f�t|�f�}t||�j|�}|d|�dd�f}	||d|�dd�f}
|	jt|
��}||fS(Nii(	RtNoneRRRRRRR	(RtLRRRRtphitzotCDtCtDtq((s#./filterpy/common/discretization.pytlinear_ode_discretation�s 
5($ N(t__doc__t
__future__RRRRtnumpyRRRRtscipy.linalgRR	RRRRR&(((s#./filterpy/common/discretization.pyt<module>s""!	C