MATLAB Radar Filtering Code: 2D Single Radar Tracking and Filtering with EKF Fusion of Radar Distance, Angle, and Target IMU Data

MATLAB Radar Filtering Code: 2D Single Radar Tracking and Filtering with EKF Fusion of Radar Distance, Angle, and Target IMU Data

This MATLAB code implements a 2D radar target tracking system, using the Extended Kalman Filter (EKF) algorithm to process the nonlinear observation data (distance and angle) from the radar.

Table of Contents

  • Program Details
    • Project Overview
    • Code Highlights
    • Analysis of Results
  • Results
  • MATLAB Source Code

Program Details

Project Overview

This code simulates a scenario where a single radar station detects and tracks a maneuvering target in a 2D plane. Since the radar observation data is in polar coordinates of Range and Azimuth, there is a nonlinear relationship with the target’s motion equations in Cartesian coordinates, thus the code uses the Extended Kalman Filter (EKF) for state estimation.

This simulation not only implements the filtering algorithm but also introduces pure inertial navigation for comparison, visually demonstrating the advantages of multi-source data fusion (EKF) in eliminating cumulative errors and observation noise.

Code Highlights

  • Multi-dimensional Comparative Analysis:
    • True Trajectory: The actual motion path of the target (including acceleration).
  • Raw Radar Observations: Directly converting noisy polar measurements to Cartesian coordinates, showcasing the discreteness of the raw measurements.
  • Pure Inertial: Estimating solely based on the initial state, demonstrating the error accumulation (drift) phenomenon without observation correction.
  • EKF Estimation: Fusing predictions and observations to output a smooth and high-precision trajectory.
  • Quantitative Error Assessment:
    • Automatically calculates Mean Error and Root Mean Square Error (RMSE).
    • Quantifies the performance improvement percentage of EKF compared to raw observations and pure inertial navigation.
  • Rich Visualization Outputs:
    • Trajectory Plot: Visually displays the geometric relationships of the four trajectories.
  • Error Curve Plot: Fluctuations of error over time.
  • Statistical Bar Chart: Clearly compares the overall accuracy of the three methods.

Analysis of Results

  1. Trajectory Plot: The pure inertial trajectory gradually deviates from the true trajectory over time (drift); the raw radar observation points jitter around the true trajectory; while the EKF trajectory closely follows the true target and is smoother than the raw observations.
  2. Error Curve: The error of pure inertial navigation diverges (increasing), while the EKF error converges within a smaller stable range.
  3. Performance Metrics: The console output will show that the EKF’s RMSE is significantly lower than the radar observation noise and inertial errors.

Results

Trajectory curve, with the radar position marked:MATLAB Radar Filtering Code: 2D Single Radar Tracking and Filtering with EKF Fusion of Radar Distance, Angle, and Target IMU DataComparison of error curves:MATLAB Radar Filtering Code: 2D Single Radar Tracking and Filtering with EKF Fusion of Radar Distance, Angle, and Target IMU DataSimulation results from the command line output:MATLAB Radar Filtering Code: 2D Single Radar Tracking and Filtering with EKF Fusion of Radar Distance, Angle, and Target IMU Data

MATLAB Source Code

Part of the code is as follows:

% Radar angle and distance positioning - 2D - single radar, trajectory using EKF, observations are distance and angle
% Author: matlabfilter (same WeChat ID), specializing in MATLAB code related to positioning, navigation, and filtering
% 2025-11-25/Ver1

clear; close all; clc;
rng(0);

%% Parameter Settings
dt =0.01;
N =400;

target_position =[100;200];
target_velocity =[2;5];
target_acceleration =[0.5;-0.1];
radar_position =[120;223];

range_noise_std =1;
angle_noise_std =0.2;

%% EKF State Model
F =[10 dt 0;
010  dt;
0010;
0001];

q =0.1;
Q = q *[dt^4/40       dt^3/20;
0       dt^4/40       dt^3/2;
         dt^3/20       dt^20;
0       dt^3/20       dt^2];

% Measurement noise (r, theta)
R =diag([range_noise_std^2, angle_noise_std^2]);

% Initial state estimation
x_est =[target_position; target_velocity];
P =diag([330.50.5]);

%% Pure Inertial
inertial_position = target_position;
inertial_velocity = target_velocity;

%% Data Storage
true_positions =zeros(N,2);
true_velocities =zeros(N,2);
measurements_xy =zeros(N,2);% Only for plotting
estimated_positions =zeros(N,2);
estimated_velocities =zeros(N,2);
inertial_positions =zeros(N,2);
inertial_velocities =zeros(N,2);

fprintf('Starting EKF radar tracking simulation...\n');

for i=1:N

%% ===== True Target Motion =====
    target_position = target_position + target_velocity * dt +0.5* target_acceleration * dt^2;

Full code:

MATLAB Radar Filtering Code: 2D Single Radar Tracking and Filtering with EKF Fusion of Radar Distance, Angle, and Target IMU Data

<span>Or contact the author via WeChat below</span>

MATLAB Radar Filtering Code: 2D Single Radar Tracking and Filtering with EKF Fusion of Radar Distance, Angle, and Target IMU Data

Please open in the WeChat client

Leave a Comment