Effacer les filtres
Effacer les filtres

Minimize intersection area between contours

1 vue (au cours des 30 derniers jours)
Carola Forlini
Carola Forlini le 31 Août 2023
Commenté : William Rose le 1 Sep 2023
Hi,
I have obtained contours plotted in the time-frequency domain for two signals (focus on blue and violet contours).
I would like to estimate the timelag which correspond to the "perfect" overlapping of the contours from the two signals.
I am thinking to obtain this value by defining the difference between the overlapping areas and stop when this values is ~ 0.
Any suggestions on how to build the algorithm?
Thank you,
Carola
  2 commentaires
Mathieu NOE
Mathieu NOE le 31 Août 2023
why not take the x distance between the centroids of the areas ?
William Rose
William Rose le 31 Août 2023
@Mathieu NOE, great idea.

Connectez-vous pour commenter.

Réponse acceptée

William Rose
William Rose le 31 Août 2023
What is th eformat of the contour lines? That may affect what algorithm to create.
c1=[90+15*cos(2*pi*(0:20)'/20),.4+.15*sin(2*pi*(0:20)'/20+pi/4)]+randn(21,2)*[1,0;0,.01];
c2=[100+15*cos(2*pi*(0:20)'/20),.4+.16*sin(2*pi*(0:20)'/20+pi/4)]+randn(21,2)*[1,0;0,.01];
c1(21,:)=c1(1,:); c2(21,:)=c2(1,:); % make last point=first, so contour is closed
plot(c1(:,1),c1(:,2),'-r',c2(:,1),c2(:,2),'-b');
xlim([0,200]); ylim([.2,.6]); grid on;
xlabel('Time (s)'); ylabel('Frequency (Hz)')
Find the intersection.
p1=polyshape(c1); p2=polyshape(c2); pInt=intersect(p1,p2);
hold on; plot(pInt,'FaceColor','m')
Compute and display the area of the intersection, just to show it can be done:
aInt=area(pInt); fprintf('Area of intersection=%.2f.\n',aInt);
Area of intersection=2.28.
Vary the time offset and compute area in each case; find the time offset with the maximum area of hte intersection.
tOff=-50:50;
N=length(tOff);
M=length(c2);
aInt=zeros(N,1);
for i=1:N
c2shift=c2+[tOff(i)*ones(M,1),zeros(M,1)]; % shift contour 2
aInt(i)=area(intersect(polyshape(c1),polyshape(c2shift))); % area of intersection
end
figure; plot(tOff,aInt,'-k.'); grid on; xlabel('tOff (s)'); ylabel('Area')
Find the time offset associated with the max area of intersection.
[~,idx]=max(aInt); tBest=tOff(idx);
fprintf('Best time offset of c2=%d.\n',tBest)
Best time offset of c2=-10.
OK.
  5 commentaires
William Rose
William Rose le 31 Août 2023
@Carola Forlini, I am curious: why do you want to find the time offset that maximizes the overlap of the time-frequency (T-F) contours of two signals? What aspect of the signals are you trying to detect? Depending on your answer, there may be better ways of getting the information you want. Would the time at which the corss-correlation is maximal be equally useful?
The total power in the signal for each time slice of your T-F plot is equal to the sum of the T-F values along that "column" (i.e. time slice) of the plot. (This is true due to Parseval's theorem.) You can compute the power-weighted mean "time" of signal x1(t) , whose T-F array is Z1(t,f), from Z1. Or you could find hte mean time by using the time domain signal, x1(t) itself. We assume x1 has mean=0.
Do likewise for t2. Find their difference. Does that get at what you want?
We have discussed three versions of "delta t" which represent something about the time offset of two signals, x1(t) and x2(t), whose T-F arrays are Z1(t,f) and Z2(t,f). The three quantitities are
  • time offset that maximizes overlap of T-F contours
  • time offset that maximizes the cross correlation
  • time difference between the power-weighted mean times
I predict that the three quantities will be quite similar for various signal pairs. But I could be wrong, so you'd have to check it out with real and/or simulated data.
William Rose
William Rose le 1 Sep 2023
@Carola Forlini, you are welcome.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Contour Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by