How can I add angular noise to my vector?

6 ビュー (過去 30 日間)
JAEWOO KIM
JAEWOO KIM 2021 年 4 月 9 日
編集済み: Tanner Jones 2024 年 3 月 1 日
For example, there is an unit vector X
X = [p q r]; % norm(X) = 1
And what I wanna do is to make some vectors which have the contained angle with X less than certain degree. Additionally, I want them to be distributed normally. How can I do this?

回答 (2 件)

KSSV
KSSV 2021 年 4 月 9 日
Read about rand.
X = X+rand(size(X)) ;

Tanner Jones
Tanner Jones 2024 年 3 月 1 日
編集済み: Tanner Jones 2024 年 3 月 1 日
If I understand the question, you want to perturb a unit vector, , by some random angle, θ, sampled from a normal distribution many times?
Start by creating an orthogonal vector, . This can be done by generating a random unit vector, , and calculating the cross product of the two vectors: .
Then rotate about an axis defined as by θ. To do this first create a Direction Cosine Matrix (DCM) from and θ, by the following formula: , where I is the identity matrix, and is a function which produces a cross product or skew matrix (see Cross product section). Once you have calculated the DCM you will multiply it by (the DCM must be on the left to perform this multiplication) to get the desired vector.
I have implemented a solution below:
N = 100; % number of output vectors
results = zeros(3,N); % allocate memory for the resulting vectors
angleErrors = zeros(N); % allocate memory for resulting angle errors
X = sqrt(3)/3*ones(3,1); % given unit normal vector X
thetaSTD = deg2rad(1.0); % error has a standard deviation of 1 degree
for i = 1:N
result = perturbVector(X, thetaSTD);
angleErrors(i) = acos(dot(X, result)); % calculate error
results(:,i) = result; % record result
end
plot(rad2deg(angleErrors))
function x_hat = perturbVector(x, sigma)
theta = sigma*randn; % noise sample
v = rand(3,1); % random vector
v = v/norm(v); % normalize to a unit vector
y = cross(v,x); % calculate cross product
DCM = eye(3) - sin(theta) * skew(y) + (1 - cos(theta)) * skew(y)^2;
x_hat = DCM * x;
end
function vSkew = skew(v)
vSkew = zeros(3,3);
vSkew(1,2,:) =-v(3,:);
vSkew(1,3,:) = v(2,:);
vSkew(2,1,:) = v(3,:);
vSkew(2,3,:) =-v(1,:);
vSkew(3,1,:) =-v(2,:);
vSkew(3,2,:) = v(1,:);
end

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by