Effacer les filtres
Effacer les filtres


8 vues (au cours des 30 derniers jours)
NATHAN MURRY le 8 Fév 2018
Good afternoon: I have two time series datasets. Thier fields are time (in seconds from 1900) and salinity. The data sets are from sensors (J and G) about 9km apart. The J set is about 8500 samples longer than the G set. I need to correlate the two time find maximum lag at the highest correlation coefficient. The idea is to then use this information to derive velocity of a water parcel. I am using xcorr, and have followed the example on the 'xcorr' doc page closely, as it is a similar application. However, I get a plot that ends up being far too perfect for it to be right, (attached). I believe I need to interpolate time into the calculation somehow (which I have not done), but I am unsure how best to do so. I have researched numerous methods from answered questions up here, including some time interpolation techniques, but I am spinning my wheels.
FsJ = 0.02350 %Samples per second at J over the period
FsG = 0.01975 % Samples per second at G over the period
avFs = (FsJ+FsG)/2
[corr,lag] = xcorr(s_salinityj,s_salinityg);
[~,I] = max(abs(corr));
cor = corr/max(corr);
[MJG,IJG] = max(corr);
tJG = lag(IJG);
lagDiff = lag(I)
timeDiffJ = lagDiff/FsJ
timeDiffG = lagDiff/FsG
timeDiffav = lagDiff/avFs
set(gcf, 'Position',[10 50 2075 1000])
plot(lag,acor,[tJG tJG],[-0.1 1],'r:')
text(tJG+100,0.9,['MAX LAG IS: ' int2str(tJG),' samples'])
ylabel('Correlation Coefficient_{J-G}')
xlabel('Samples, (x10^4)')if true
I could use a shove in the right direction. Thank you.
  8 commentaires
David Goodmanson
David Goodmanson le 4 Mar 2018
Hi Nathan,
that's a nice plot although I don't understand why it shows the J data going all the way to the end of June with a gap in the middle, whereas the text files you provided have the J data ending earlier, with no gap.
The reason you are getting the big triangle is that each data set has an average value around 36, with small variations about that. So you are convoluting together two rectangles, each with a small amount of variation on the top. That gives you a large triangle with some small, hard-to-see variations. If sG and sJ are the two salinity vectors, then if you take away the large constant part with
plot(xcorr(sg-mean(sg), sj-mean(sj)))
you will see something more like what you expect, although it doesn’t look very useful for finding a delay.
NATHAN MURRY le 5 Mar 2018
Modifié(e) : NATHAN MURRY le 5 Mar 2018
Hi David: The reason for the date discrepancy is that I only posted a sample of the data set, not the entire set that covers the entire date range you see in the first plot. Thank you for explaining to me what is going on with the plot. I will run the test code you suggest to see what that looks like, and also do some zooming on the original plot to be able to see the variations you made mention of.
I think I have enough to move forward again. THANK YOU for responding to me, I greatly appreciate it.

Connectez-vous pour commenter.

Réponses (0)


Community Treasure Hunt

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

Start Hunting!

Translated by