Time Delay Estimation for Monotonically Increasing Funcitons
4 次查看(过去 30 天)
显示 更早的评论
I am trying to use cross correlation to find the time delay between two signals. Both signals follow a logarithmic growth pattern, but are sampled for the same amount of time and at the same sample rate. The only difference between the two is: 1) random noise, and 2) the time delay of when the delayed signal starts. When trying traditional cross correlation here it is failing to find the shift and only reports a maximum at zero delay. Please see the attached matlab code for full details
for i = 1:5
signal1 = 6 + ...
(-0.1 + (0.1+0.1).*rand([1399,1])); %base signal + noise
%simulates the base noisefloor
timeDelay = randi(700);%quantify a random delay
exponentialContrib = log(1:1399) + ...
(-0.1 + (0.1+0.1).*rand([1399,1]))';
signal1(timeDelay:end,1) = signal1(timeDelay:end,1)' + ...
exponentialContrib(1,1:1399-timeDelay+1);
%Second signal with the exponential starting right away
signal2 = 6 + ...
(-0.1 + (0.1+0.1).*rand([1399,1]));
%aligned to zero time
timeDelay2 = 1;
exponentialContrib = log(1:1399) + ...
(-0.1 + (0.1+0.1).*rand([1399,1]))';
signal2(timeDelay2:end,1) = signal2(timeDelay2:end,1)' + ...
exponentialContrib(1,1:1399-timeDelay2+1);
%Find the delayed time
[acor,lag] = xcorr(signal2',signal1');
[~,Idx] = max(abs(acor));
lagTimeCalculated = lag(Idx);
figure; plot(signal1); hold on; plot(signal2);
legend('signal 1', 'signal 2'); hold off;
pause(2);
disp(['Calculated: ' num2str(lagTimeCalculated) ...
' Actual: ' num2str(timeDelay) ' , ' ...
num2str(lagTimeCalculated - timeDelay)]);
end
I believe I know why this is, I am just unsure about how to fix it. As the non-delayed signal is slid through all possible delays, the large-valued logarithmic tail goes from being multiplied by another, time-delayed logarithmic function (as is the case when shift = 0) to being multiplied partially by zeros. This ensures that the correlation intensity will not be greater when both signals truly overlap.
Any comments or suggestions would be greatly appreciated
0 个评论
采纳的回答
David Goodmanson
2017-7-6
编辑:David Goodmanson
2017-7-6
Hi Stephen,
I don't know how a slope detector on a triggering 'scope works but here is an attempt at something similar. Your signal seems ideal for this and something with a softer leading edge might not work as well. I added some extra baseline to both signals since the method requires it. I don't have xcorr so I use a homemade function called xcor. You will have to go in and change those to xcorr, and I left it that way as a reminder that you may have to swap the two inputs to the function to make it work.
After detection there are two methods to get the time delay and they seem to agree pretty well.
% your signals with baseline
baseline = 32;
signal1 = 6 + ...
(-0.1 + (0.1+0.1).*rand([1399,1])); %base signal + noise
%simulates the base noisefloor
timeDelay = baseline + randi(700);%quantify a random delay
exponentialContrib = log(1:1399) + ...
(-0.1 + (0.1+0.1).*rand([1399,1]))';
signal1(timeDelay:end,1) = signal1(timeDelay:end,1)' + ...
exponentialContrib(1,1:1399-timeDelay+1);
%Second signal with the exponential starting right away
signal2 = 6 + ...
(-0.1 + (0.1+0.1).*rand([1399,1]));
%aligned to zero time
timeDelay2 = baseline;
exponentialContrib = log(1:1399) + ...
(-0.1 + (0.1+0.1).*rand([1399,1]))';
signal2(timeDelay2:end,1) = signal2(timeDelay2:end,1)' + ...
exponentialContrib(1,1:1399-timeDelay2+1);
new part:
s1 = signal1; % easier names
s2 = signal2;
t = 1:length(s1);
figure(1)
plot(t,s1,t,s2)
% slope detector
detec = zeros(size(s1));
detec(1:10) = -1; % 10 somewhat arbitrary but works;
detec(11:20) = 1; % 20 must be < length of baseline
[d1 lag] = (xcor(s1,detec));
d2 = (xcor(s2,detec));
llag = length(lag); % get rid of unwanted detections associated
ind = (llag+1)/2:llag-baseline; % with the ends of the time record
d1 = d1(ind);
d2 = d2(ind);
lag = lag(ind);
figure(2)
plot(lag,d1,lag,d2)
% find the delay time
% method 1
[~, T1] = max(abs(d1));
[~, T2] = max(abs(d2));
Tdelay1 = T1-T2 % delay of s1 (blue) compared to s2 (red)
% method 2, cross correlation
[dcor lag] = xcor(d1,d2);
[~, ind] = max(abs(dcor));
Tdelay2 = lag(ind)
figure(3)
plot(lag,dcor)
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!