TIME SERIES COMPARISON WITH XCORR
    6 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
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 comentarios
  David Goodmanson
      
      
 el 4 de Mzo. de 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.
Respuestas (0)
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


