## 3 Novel Approach EKF Tuning
### Mathematical Modeling
#### 3.1.3 Monte Carlo Simulation  
The algorithm implements [PERSON]'s method [44] for the incremental estimation of the mean and variance of a dataset, incorporating [PERSON]'s correction [45] for samples. These techniques are useful when dealing with large sequential datasets, and when efficient and accurate calculations of means and variances are needed.  
[PERSON]'s mean is calculated incrementally, allowing the mean to be updated as new elements are added to the dataset. The formula is as follows:  
\[\bar{x}_{n}=\bar{x}_{n-1}+\frac{x_{n}-\bar{x}_{n-1}}{n}, \tag{36}\]  
where \(n\) is the number of elements processed so far, \(x_{n}\) is the most recent element, and \(\bar{x}_{n}\) is the mean up to that point.  
[PERSON]'s variance is a natural extension, including [PERSON]'s correction to compensate for bias in the variance estimation when dealing with samples. The formula is as follows:  
\[s_{n}^{2}=\frac{n-1}{n}\cdot s_{n-1}^{2}+\frac{1}{n}\cdot(x_{n}-\bar{x}_{n-1}) ^{2}, \tag{37}\]  
where \(n\) is also the number of elements processed so far, \(s_{n}^{2}\) is the variance up to that point, and \(s_{n-1}^{2}\) is the variance from the previous step.  
By applying all the above equations, which encompass the inertial sensor error model, the INS mechanization equations, and the calculations for means and variances, the algorithm for the novel approach to Kalman filter tuning is described as presented in Algorithm 1:where \(j\) is the index of the Monte Carlo loop, \(k\) is the index for the trajectory samples, and \(c\) is the index used to calculate the means and variances for each trajectory step according to the chosen interval, which in this case is 1 s. Additionally, \(ct\) is an auxiliary index that counts the number of seconds until the specified interval is reached. _totalTrajectorySamples_ represents the total number of samples in the trajectory dataset, _insMechanization_ is a function that calculates the INS states based on the current states, and _diag_ represents a diagonal matrix where the provided elements are placed along the main diagonal, with all off-diagonal elements set to zero.  
The sensor error model is derived from the IMU datasheet, where not all error parameters need to be filled out. However, the more variables from the error equations that are defined, the more accurate the variance calculations will be. To introduce variability in the Monte Carlo simulation, the IMU errors are modeled as normally distributed random variables, each with a variance specific to its corresponding error parameter.  
At the conclusion of the Monte Carlo simulation, the final variance values associated with the inertial sensors, accelerometers, and gyroscopes form the covariance matrix \(\mathbf{Q}\) for the IEKF. Similarly, the final variance values related to navigation parameters, such as positions, velocities, and attitudes, form the covariance matrix \(\mathbf{Q}\) for the DEKF.  
Modeling inertial sensor errors is complex due to their non-Gaussian nature. In many applications, the Monte Carlo method generates samples assuming these errors follow a Gaussian distribution. In reality, inertial sensor errors often exhibit time-correlated characteristics, and a more accurate representation would involve using models such as a Markov process. To explain the accuracy and reliability of statistical analysis in Monte Carlo simulations for a non-Gaussian distribution, fundamental statistical principles are applied, one of which is the CLT.