code: def Q_continuous_white_noise(
      dim, dt=1.0, spectral_density=1.0, block_size=1, order_by_dim=True
  ):
      """
      Returns the Q matrix for the Discretized Continuous White Noise
      Model. dim may be either 2, 3, 4, dt is the time step, and sigma is the
      variance in the noise.
  
      Parameters
      ----------
  
      dim : int (2 or 3 or 4)
          dimension for Q, where the final dimension is (dim x dim)
          2 is constant velocity, 3 is constant acceleration, 4 is
          constant jerk
  
      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
  
      block_size : int >= 1
          If your state variable contains more than one dimension, such as
          a 3d constant velocity model [x x' y y' z z']^T, then Q must be
          a block diagonal matrix.
  
      order_by_dim : bool, default=True
          Defines ordering of variables in the state vector. `True` orders
          by keeping all derivatives of each dimensions)
  
          [x x' x'' y y' y'']
  
          whereas `False` interleaves the dimensions
  
          [x y z x' y' z' x'' y'' z'']
  
      Examples
      --------
  
      >>> # constant velocity model in a 3D world with a 10 Hz update rate
      >>> Q_continuous_white_noise(2, dt=0.1, block_size=3)
      array([[0.00033333, 0.005     , 0.        , 0.        , 0.        , 0.        ],
             [0.005     , 0.1       , 0.        , 0.        , 0.        , 0.        ],
             [0.        , 0.        , 0.00033333, 0.005     , 0.        , 0.        ],
             [0.        , 0.        , 0.005     , 0.1       , 0.        , 0.        ],
             [0.        , 0.        , 0.        , 0.        , 0.00033333, 0.005     ],
             [0.        , 0.        , 0.        , 0.        , 0.005     , 0.1       ]])
      """
  
      if dim not in [2, 3, 4]:
          raise ValueError("dim must be between 2 and 4")
  
      if dim == 2:
          Q = [
              [(dt**3) / 3.0, (dt**2) / 2.0],
              [(dt**2) / 2.0, dt],
          ]
      elif dim == 3:
          Q = [
              [(dt**5) / 20.0, (dt**4) / 8.0, (dt**3) / 6.0],
              [(dt**4) / 8.0, (dt**3) / 3.0, (dt**2) / 2.0],
              [(dt**3) / 6.0, (dt**2) / 2.0, dt],
          ]
  
      else:
          Q = [
              [
                  (dt**7) / 252.0,
                  (dt**6) / 72.0,
                  (dt**5) / 30.0,
                  (dt**4) / 24.0,
              ],
              [
                  (dt**6) / 72.0,
                  (dt**5) / 20.0,
                  (dt**4) / 8.0,
                  (dt**3) / 6.0,
              ],
              [
                  (dt**5) / 30.0,
                  (dt**4) / 8.0,
                  (dt**3) / 3.0,
                  (dt**2) / 2.0,
              ],
              [(dt**4) / 24.0, (dt**3) / 6.0, (dt**2 / 2.0), dt],
          ]
  
      if order_by_dim:
          return block_diag(*[Q] * block_size) * spectral_density
  
      return (
          order_by_derivative(array(Q), dim, block_size)
          * spectral_density
      )
  
file_path: filterpy/filterpy/common/discretization.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  from numpy import zeros, vstack, eye, array
  from numpy.linalg import inv
  from scipy.linalg import expm, block_diag
label_desc: Use image node_id 3 for calling a global function with example usage: Q_continuous_white_noise(dim, dt, spectral_density, block_size, order_by_dim) and returns: unknown, unknown