# Assignment: GUI-Based EKF Localization Using Multiple Landmarks

## Objective

In this assignment, you will develop a MATLAB graphical user interface that demonstrates 2D robot localization using an Extended Kalman Filter with multiple known landmarks.

Your GUI should combine the visualization style of the provided first Kalman filter GUI with the nonlinear EKF localization model from the provided one-landmark-based EKF script.

## Background

A mobile robot moves in a 2D environment using the unicycle motion model:

x=[x y θ]x = \begin{bmatrix} x \\ y \\ \theta \end{bmatrix} x=
​x y θ​
​

where x x x and y y y represent the robot position, and θ\theta θ is the robot heading angle.

The robot receives control inputs:

u=[v ω]u = \begin{bmatrix} v \\ \omega \end{bmatrix} u=[v ω​]

where v v v is the linear velocity and ω\omega ω is the angular velocity.

The environment contains multiple fixed landmarks at known positions. The robot measures its distance to each landmark using noisy range measurements.

## Required Tasks

Students must implement a MATLAB GUI that simulates and visualizes EKF localization using multiple landmarks.

The GUI should include:

1. A 2D plot showing:

   - true robot trajectory
   - estimated robot trajectory
   - landmark locations
   - noisy range measurements
   - uncertainty ellipse of the estimated position

2. A Run Simulation button.

3. A Reset button.

4. User controls for:

   - process noise level
   - measurement noise level
   - number of landmarks
   - Adding landmarks to 2D plot by mouse click or text input
   - simulation duration

5. A live visualization of the robot motion and EKF estimate.

## EKF Requirements

Students should implement the EKF prediction step using the nonlinear unicycle model:

x k+1=x k+v Δ t cos⁡(θ k)x_{k+1} = x_k + v \Delta t \cos(\theta_k) x k+1​=x k​+v Δ t cos(θ k​)

y k+1=y k+v Δ t sin⁡(θ k)y_{k+1} = y_k + v \Delta t \sin(\theta_k) y k+1​=y k​+v Δ t sin(θ k​)

θ k+1=θ k+ω Δ t\theta_{k+1} = \theta_k + \omega \Delta t θ k+1​=θ k​+ω Δ t

They should also compute the motion Jacobian F k F_k F k​.

For each landmark i i i, the range measurement is:

z i=(x−x L i)2+(y−y L i)2 z_i = \sqrt{(x-x_{L_i})^2 + (y-y_{L_i})^2} z i​=(x−x L i​​)2+(y−y L i​​)2
​

For multiple landmarks, students should construct:

z=[z 1 z 2⋮z N]z = \begin{bmatrix} z_1 \\ z_2 \\ \vdots \\ z_N \end{bmatrix} z=
​z 1​z 2​⋮z N​​
​

and the measurement Jacobian:

H=[x−x L 1 r 1 y−y L 1 r 1 0 x−x L 2 r 2 y−y L 2 r 2 0⋮⋮⋮x−x L N r N y−y L N r N 0]H = \begin{bmatrix} \frac{x-x_{L_1}}{r_1} & \frac{y-y_{L_1}}{r_1} & 0 \\ \frac{x-x_{L_2}}{r_2} & \frac{y-y_{L_2}}{r_2} & 0 \\ \vdots & \vdots & \vdots \\ \frac{x-x_{L_N}}{r_N} & \frac{y-y_{L_N}}{r_N} & 0 \end{bmatrix} H=
​r 1​x−x L 1​​​r 2​x−x L 2​​​⋮r N​x−x L N​​​​r 1​y−y L 1​​​r 2​y−y L 2​​​⋮r N​y−y L N​​​​0 0⋮0​
​

The EKF update should use:

S=H P H T+R S = HPH^T + R S=H P H T+R

K=P H T S−1 K = PH^T S^{-1} K=P H T S−1

x=x+K(z−z^)x = x + K(z-\hat{z}) x=x+K(z−z^)

P=(I−K H)P P = (I-KH)P P=(I−KH)P

## Deliverables

Students must submit:

1. MATLAB GUI file

   - One main `.m` file.
   - The code should run without errors.

2. Simulation results

   - At least three screenshots showing the GUI output for different noise levels or landmark configurations.

3. Short report The report should include:

   - discussion of how noise affects localization accuracy
   - comparison between using one landmark and multiple landmarks

## Submission Format

Submit a single compressed folder containing:

    StudentName_EKF_GUI_Assignment/
    │
    ├── main_GUI_file.m
    ├── helper_functions/
    ├── screenshots/
    ├── report.pdf
    └── README.txt

The `README.txt` should briefly explain how to run the GUI.