| 
									
										
										
										
											2014-02-10 09:34:18 +08:00
										 |  |  | function h = covarianceEllipse(x,P,color, k)
 | 
					
						
							| 
									
										
										
										
											2012-09-08 13:28:25 +08:00
										 |  |  | % covarianceEllipse plots a Gaussian as an uncertainty ellipse | 
					
						
							| 
									
										
										
										
											2012-07-28 03:02:11 +08:00
										 |  |  | % Based on Maybeck Vol 1, page 366 | 
					
						
							|  |  |  | % k=2.296 corresponds to 1 std, 68.26% of all probability | 
					
						
							|  |  |  | % k=11.82 corresponds to 3 std, 99.74% of all probability | 
					
						
							|  |  |  | % | 
					
						
							| 
									
										
										
										
											2013-10-29 22:34:41 +08:00
										 |  |  | % covarianceEllipse(x,P,color,k) | 
					
						
							| 
									
										
										
										
											2012-07-28 03:02:11 +08:00
										 |  |  | % it is assumed x and y are the first two components of state x | 
					
						
							| 
									
										
										
										
											2013-10-29 22:34:41 +08:00
										 |  |  | % k is scaling for std deviations, defaults to 1 std | 
					
						
							| 
									
										
										
										
											2012-07-28 03:02:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-23 09:39:02 +08:00
										 |  |  | hold on | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-28 03:02:11 +08:00
										 |  |  | [e,s] = eig(P(1:2,1:2)); | 
					
						
							|  |  |  | s1 = s(1,1); | 
					
						
							|  |  |  | s2 = s(2,2); | 
					
						
							| 
									
										
										
										
											2013-10-29 22:34:41 +08:00
										 |  |  | if nargin<4, k = 2.296; end; | 
					
						
							| 
									
										
										
										
											2012-07-28 03:02:11 +08:00
										 |  |  | [ex,ey] = ellipse( sqrt(s1*k)*e(:,1), sqrt(s2*k)*e(:,2), x(1:2) ); | 
					
						
							| 
									
										
										
										
											2014-02-10 09:34:18 +08:00
										 |  |  | h = line(ex,ey,'color',color); | 
					
						
							| 
									
										
										
										
											2012-07-28 03:02:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     function [x,y] = ellipse(a,b,c); | 
					
						
							|  |  |  |         % ellipse: return the x and y coordinates for an ellipse | 
					
						
							|  |  |  |         % [x,y] = ellipse(a,b,c); | 
					
						
							|  |  |  |         % a, and b are the axes. c is the center | 
					
						
							|  |  |  |          | 
					
						
							|  |  |  |         global ellipse_x ellipse_y | 
					
						
							|  |  |  |         if ~exist('elipse_x') | 
					
						
							|  |  |  |             q =0:2*pi/25:2*pi; | 
					
						
							|  |  |  |             ellipse_x = cos(q); | 
					
						
							|  |  |  |             ellipse_y = sin(q); | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |          | 
					
						
							|  |  |  |         points = a*ellipse_x + b*ellipse_y; | 
					
						
							|  |  |  |         x = c(1) + points(1,:); | 
					
						
							|  |  |  |         y = c(2) + points(2,:); | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-23 09:39:02 +08:00
										 |  |  | end |