Find x values where y values are the same from a set of data.
Show older comments
I have 2 datasets from a continuous signal that will display a voltage in 1 set of data (D8) and repeat that voltage in data set D2 after a randomized delay. I need to find the voltage and time these repetitions occur, but I'm unsure of how to do that.
My code finds these repetitions, removes where the 2 datasets intercept as there's no delay going on there, and displays the time of the repetitions. I need the original voltage, the original time from D8, and the delayed time in D2 when the repeated value occurs.
data = load('DataSet2_Test.txt'); %my directory is different but it includes my name so it just calls the attached file
%Characterize columns
t1 = data(:,1)/1000; %convert time from ms to s
%convert from bits to V
resolution = 2^10-1;
%Data as assigned pairs *10^8 to transfer within the MeV to GeV range
D1 = (data(:,2)*5)/resolution*10^8; D2 = (data(:,3)*5)/resolution*10^8;
D3 = (data(:,4)*5)/resolution*10^8; D4 = (data(:,5)*5)/resolution*10^8;
D5 = (data(:,6)*5)/resolution*10^8; D6 = (data(:,7)*5)/resolution*10^8;
D7 = (data(:,8)*5)/resolution*10^8; D8 = (data(:,9)*5)/resolution*10^8; %all in V
c1 = D8(:)==D2 %finds same voltage indep of time occuring
x1values1 = t1(find(c1)); %Gives time of repeated values
r1usure1 = t1(find(intersect(D8,D2))); %checks for intersections as they don't include delay
l1 = setdiff(x1values1, r1usure1); %Gives time of repeated values excluding intersections
This is the code I have so far, but it only checks for similar values and returns repeated time values instead of including the original time, and I've been struggling to find the associated voltages. I have also attached the file with the signals where the first column is time, column 3 is D2 in V, and column 9 is D8 in V.
This might not be well explained so I will answer questions as quickly as possible. Thank you in advance !
1 Comment
You are testing for exact equality between the two signals. If they are continuous signals with noise, their time samples would never normally coincide. Are you actually trying to find the delay between two pulses? For that, you would normally use xcorr. However, It doesn't look like there is any lag between D8 and D2. Their peaks pretty much coincide --
data = load('DataSet2_Test.txt'); %my directory is different but it includes my name so it just calls the attached file
%Characterize columns
t1 = data(:,1)/1000; %convert time from ms to s
%convert from bits to V
resolution = 2^10-1;
D=data(:,2:end)*5/resolution*1e8;
plot(t1,D(:,8),t1,D(:,2)); axis padded
legend('D8','D2', Location = 'best'); xlabel t; ylabel D
Accepted Answer
More Answers (1)
Looking at your plot, the D1 and D8 signals look similar but not the same - not exactly identical like it was just copied to a new location. So I would use cross correlation to find the separation. Try xcorr or normalized cross correlation normxcorr2 (not sure if that one works with 1-D signals). I think there is an example showing how to find the lag/separation between two signals.
help xcorr
Categories
Find more on Integrated Circuits in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!