How to find the error between two plots and plot the error in same diagram

I need to plot error between two plots Ground_truth and Estimated_Long_Lat
Sharing my code here
figure;
Estimated_long = 180 / pi * lon;
Estimated_Lat = 180 / pi * lat;
plot(180 / pi * lon, 180 / pi * lat,'x','Linewidth',0.5);
hold on
Ground_Truth = xlsread('27');
G_Long = Ground_Truth(:,1);
G_Lat = Ground_Truth(:,2);
plot(G_Long,G_Lat,'-x','Linewidth',2)
hold on
hold off
ylabel('Latitude, [deg]','FontSize', 13);
xlabel('Longitude, [deg]','FontSize', 13);
title('Trajectory of vehicle with position close to Lane level','FontSize', 15)
legend('Estimated trajectory', 'Centre nodes of True trajectory','best')
Thanks

4 Comments

The dimensions of (Estimated_long, Estimated_Lat) and (G_Long, G_Lat)are same?
Then find the distance between them, this would give you the error,.
yes, but problem is lat and long combined give me location. for 'n' number of lat _long positions with equal dimensions of ground truth lat_long points...how can i find distance or say difference between them. I am unable to proceed further.

Sign in to comment.

 Accepted Answer

Hi Abdul Sajeed Mohammed,
here some example that is close to what you do:
% example data params (circular trajectory)
R = 1000;
phi = 0:360;
% uniformly distributed noise (signed)
noise = 100 .* (rand(1,length(phi)) - 0.5);
% generate example date
Estimated_long = R .* sind(phi) + noise;
Estimated_Lat = R .* cosd(phi) + circshift(noise,floor(length(phi)/2));
% generate ground truth data
Ground_Truth = R .* [sind(phi); cosd(phi)];
G_Long = Ground_Truth(1,:);
G_Lat = Ground_Truth(2,:);
% Choose whatever error norm is applicable
totalErr = sqrt((Estimated_Lat - G_Lat).^2 + (Estimated_long - G_Long).^2);
% create figure with two subplots
fh = figure;
fh.OuterPosition = fh.OuterPosition .* [0.5 0.5 2 2];
sh{1} = subplot(1,2,1,'Parent',fh);
sh{2} = subplot(1,2,2,'Parent',fh);
hold(sh{1},'on')
axis(sh{1},'equal')
% plot measured and ground truth data into first subplot
plot(sh{1},Estimated_long, Estimated_Lat,'x','Linewidth',0.5);
plot(sh{1},G_Long,G_Lat,'-x','Linewidth',2)
ylabel(sh{1},'x, [m]','FontSize', 13);
xlabel(sh{1},'y, [m]','FontSize', 13);
title(sh{1},'Trajectory of vehicle with position close to Lane level','FontSize', 15)
legend(sh{1},'Estimated trajectory', 'Centre nodes of True trajectory')
% plot total error in second subplot
plot(sh{2},phi,totalErr,'.','MarkerSize',12);
xlabel(sh{2},'phi, [deg]','FontSize', 13);
ylabel(sh{2},'total error, [m]','FontSize', 13);
title(sh{2},'Total error of vehicle','FontSize', 15)
Concerning error norms, have a look here:
Kind regards,
Robert

5 Comments

Hey thank you for the valuable help. Is it possible for you to explain about plot (like what is zero and minus and plus values represent in first plot) and total error of vehicle shown in second plot?
What if trajectory is is something like quadilateral (or rectangle) in shape ? How can i approach ?
Hi Abdul Sajeed Mohammed,
it is a hypothetical example in which a vehicle moves in a circle with a radius of 1 km around a relative center at [0, 0]. The blue dots are measured values (so ground truth + some uniformly distributed noise). The red line is the ground truth.
In my example the error corresponds to the Euclidian distance, i.e. the distance between the measured value to the ground truth value. The data have been recorded along the angle phi (corresponding to the polar coordinate system situated in [0, 0]). The used reference coordinate should be changed according to your trajectory. For a arbitrary trajectory the traveled distance might be more useful.
The error could also be displayed in a color-coded map in the x-y-plane as the plot left. That is up to you which representation suits your needs.
Kind regards,
Robert
Thank you robert for your valuable time and answer.
Hello robert, small query need your help. I was applying your code with my specifications as enclosed below.
Estimated_Lat = 180 / pi * lat; %Dimension of (1x17341)
Estimated_Long = 180 / pi * lon; %Dimension of (1x17341)
figure;
Ground_Truth = xlsread('27');
G_Long = Ground_Truth(:,1); (43x1)
G_Lat = Ground_Truth(:,2); (43x1)
% Plot for error %
Time = 0:17340; ( Distance of travelled trajectory is 2.1 Km, due to dimension issue used time in x-axis)
totalErr = sqrt((Estimated_Lat - G_Lat).^2 + (Estimated_Long - G_Long).^2);
fh = figure;
fh.OuterPosition = fh.OuterPosition .* [0.5 0.5 2 2];
sh{1} = subplot(1,2,1,'Parent',fh);
sh{2} = subplot(1,2,2,'Parent',fh);
hold(sh{1},'on')
axis(sh{1},'equal')
% plot measured and ground truth data into first subplot
plot(sh{1},Estimated_Long, Estimated_Lat,'x','Linewidth',0.5);
plot(sh{1},G_Long,G_Lat,'-x','Linewidth',2)
ylabel(sh{1},'x, [m]','FontSize', 13);
xlabel(sh{1},'y, [m]','FontSize', 13);
title(sh{1},'Trajectory of vehicle with position close to Lane level','FontSize', 15)
legend(sh{1},'Estimated trajectory', 'Centre nodes of True trajectory')
% plot total error in second subplot
plot(sh{2},Time,totalErr,'.','MarkerSize',12);
xlabel(sh{2},'Time, [sec]','FontSize', 13);
ylabel(sh{2},'total error, [m]','FontSize', 13);
title(sh{2},'Total error of vehicle','FontSize', 15)
I have some zig zag manner of error plot which is hard to visualize enclosed in the attachment, can you please help me in this case. Also with distance as 2.1 km can i have something different.
It looks like there is a problem in the error plot. There are way too many curves unless you would have several runs. Can you post your measurement data as mat-file such that your code becomes executable?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!