Phase shift of two sine curves
Mostra commenti meno recenti
Hello everyone,
im trying to get the phase shift of two sine curves, one is the perfect sine wave (y=sine(x)) and the other one describes a robot movement. The robot movement is sometimes faster, but often slower than the theoretical sine wave. I'm trying to figure out how to get the phase shift, but I often get the error message "Index exceeds the number of array elements (10)" because the robot movement gives me sometimes more or sometimes less then 10 y-crossings. I'm comparing the nearest numbers to the y Crossing and I think the problem is, that Matlab thinks more numbers are the y Crossing although there only can be 10. Is there a function I can use?
I tried to split the data vector into 10 parts and search for the y-Crossing with mink funktion, but then also I get two points, that are really close to each other. Here a part of my code, the robot movement data is attached. It can be assumed that the first robot data value is the first y-Crossing, it doesn't matter which number the first data value has.
z_irl_temp = z_irl;
anzahl_z_irl = numel(z_irl_temp);
teilbar = round(anzahl_z_irl * 0.1); %Number of elements in vector * 0.1 so I get a Matrix with 10 columns
amnachsten = anzahl_z_irl + (teilbar - rem(anzahl_z_irl,teilbar)); %This is so I can get the number of cevtor rows that are divisible
for i = numel(z_irl):amnachsten
z_irl_temp(i) = 0; %filling the missung elements with zeros
end
z_irl_temp_numel = numel(z_irl_temp);
z_irl_temp_numel = z_irl_temp_numel/10;
neu = reshape(z_irl_temp,teilbar,[]); %reshape the new matrix to a matrix with 10 columns
const_irl = zeros(1,length(teilbar));
for i = 1:length(teilbar)
const_irl(i) = 389.387; %This is where the sine wave crosses the x-axis
end
const = const';
for i = 1:width(neu)
[~,idx_irl(:,i)] = mink(abs(neu(:,i)-const_irl),1);
end
for i = 1:width(neu)
if i > 1
idx_irl_temp(i) = idx_irl(i) + ((i-2) * teilbar);
time_yCrossings(i) = idx_irl_temp(i) * ti;
%idx_
else
time_yCrossings(i) = idx_irl(i) * ti;
end
end
Here's a picture of what exactly I'm trying to find. The green line describes the ideal sine curve, the blue one the real robot data.

I'm using Matlab R2020b for academic use. Thanks for your support, I'm thankful for your help!
1 Commento
dpb
il 30 Giu 2021
This closely mimics a Q? yesterday...see my Answer to
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Mathematics in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

