TIME SERIES COMPARISON WITH XCORR
7 ビュー (過去 30 日間)
古いコメントを表示
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.
% XCORR
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
figure
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 件のコメント
David Goodmanson
2018 年 3 月 4 日
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.
回答 (0 件)
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!