The key goal of this project is to get an understanding of the properties of Kalman filters and Particle filters for state estimation. You will be implementing an Extended Kalman Filter (EKF) and a Particle Filter (PF) for landmark based localization. You will also analyze their performance under various conditions.

run.m-- Main update loop, should call ekfUpdate and pfUpdateekfUpdate.m-- EKF updatepfUpdate.m-- Particle filter updateresample.m-- Particle filter resampling, called by pfUpdaterunExperiments.m-- Useful later for running multiple experiments

generateScript.m-- Generates data according to initial mean and noise parametersgenerateMotion.m-- Simulates simple motion commands

prediction.m-- Move robot according to specified motionobservation.m-- Returns the observation of the specified marker given the current statesampleOdometry.m-- Implements Table 5.6sample.m-- Samples from a covariance matrixmeanAndVariance.m-- Returns mean and variance for a set of unweighted samples (illustrates handling of angles)getfieldinfo.m-- gets field informationminimizedAngle.m-- Normalizes an angle to [-pi, pi]endPoint.m-- Returns the location of an observationnoiseFromMotion.m-- Get variance based on alphasmatlab.el-- Customization file for emacs

plotcircle.m-- Draws a circleplotcov2d.m-- Draws a 2-D covariance matrixplotfield.m-- Draws the field with landmarksplotmarker.m-- Draws an 'x' at a specified point (useful for drawing samples)plotrobot.m-- Draws the robotplotSamples.m-- Plots particles from the pfplotLine.m-- Plot a ray (origin, angle, length)

State: [x,y,theta];Observation: [bearing to landmark, landmark ID];Control: [drot1,trans,drot2];

The script generates motion information according to the odometry-based motion model (rotation first, then translation followed by another rotation). Observations are landmark detections. Each landmark has a unique ID. At each timestep, the robot starts from the current state and moves according to the control input. The robot then receives a landmark observation from the world. This information needs to be used by you to localize the robot over the whole time-sequence, by using an EKF or a PF.

In addition to implementing the required EKF and PF functionality, we will ask you to generate a writeup including several plots.

As a way to check that you have implemented the filters correctly, you can set the variable `fixSeed`
to `true`. This ensures that all random steps will happen the same way on multiple runs.

*On Octave, you should get the following values:*

**EKF:**

run(200, false, 0.001, true) --> meanPositionError = 5.2527 meanMahalanobisError = 1.9864 ANEES = 0.66212 meanPOfZ = 2.1756

**PF:**

run(200, true, 0.001, true) --> meanPositionError = 7.1791 meanMahalanobisError = 7.5702 ANEES = 2.5234 meanPOfZ = 2.1626

*On MATLAB, because the random number generator works differently, you should get the following values:*

**EKF:**

run(200, false, 0.001, true) --> meanPositionError = 7.2436 meanMahalanobisError = 3.0394 ANEES = 1.0131 meanPOfZ = 2.1214

**PF:**

run(200, true, 0.001, true) --> meanPositionError = 8.2722 meanMahalanobisError = 8.2194 ANEES = 2.7398 meanPOfZ = 2.1447

Please provide a typeset writeup analyzing the performance of your filters under various conditions. The file `runExperiments.m` can be quite useful for generating these tables and plots. Your writeup *must* include the following:

- A plot showing the noise free path, real robot path, and filter path for each filter under the default (provided) parameters. (2 plots total).
- A table of values and corresponding plots of the mean position error as the alpha and beta factors range over
`range = [1/64,1/16,1/4,1,4,16,64]`(note that this is between 1/8 and 8 times the default noise values) for both filters. This means that one run should be, for example,`run(200, false, 0.001, true, false, [1/64,1/64,1/64,1/64])`. (2 tables, 2 plots). - Tables and plots for both filters of mean position error, ANEES, and pOfZ in which the actual data has the default noise, but the filter noise estimates range over
`range`. For example, one run should be`run(200, false, 0.001, true, false, [1,1/64,1,1/64])`. (6 tables, 6 plots). - Tables and plots of mean position error and ANEES as noise for data + filter vary over
`range`and the number of particles varies over`[20,100,300]`. For example, one run should be`run(200, true, 0.001, true, false, [1/64,1/64,1/64,1/64], 20)`. Note that you have already produced values for`numParticles=100`earlier. (2 additional tables, 2 additional plots). - For each set of tables and plots, you should comment on what you see! What trends do you see? Which filters perform better under which conditions?

- Make sure to call
`minimizedAngle()`any time an angle or angle difference could exceed`[-pi,pi]`. - Try visualizing the extra covariance matrices returned by the EKF.
- Turn off plotting for a significant speedup. Enclose all plotting commands within blocks so they can be turned off with the run parameter.
- It's easy to visualize multiple plots. You can also zoom in on a plot (when it's static, for example when the pause time is negative).
- Make sure to use the low variance sampler from the textbook / slides. It gives you smoother particle distribution, and also requires only a single random number per resampling step. This will make your runs consistent with the reference implementation.