Area under autocorrelation function.

7 次查看(过去 30 天)
Pete
Pete 2013-8-23
I need to calculate the area under an autocorrelation function, BUT, only the first positive area. In other words, the area under the graph from y=1 to the first point that y=0.
At the moment I just have
[ACF, lags] = autocorr(u(1,:), 53)
Where u is a 39x54 matrix. (Hence 53=54-1)
Any ideas?

回答(2 个)

kjetil87
kjetil87 2013-9-1
编辑:kjetil87 2013-9-1
Initially i thought the previous answer was ok, but when reading your entire post you specified that you needed the FIRST positive area. Also, just setting negative values to zero introduces additional errors because when going from last positive value to first negative, say eg from 1 to -1 , the zero crossing is actually between the two indexes not on the first negative index. Therefor interpolation will be a better approximation.
%here is your example, note that the interpolation gives only a very small
%improvement here since your first negative value is so close to zero.
y=[1:1:10];
[C,lags]=autocorr(y,9);
lags2=1:0.1:lags(end)+1;
CI=interp1(1+lags,C,lags2); %inperpolate 10 x.
idx1=find(CI>0,1,'first'); %from first positive value
idx2=find(CI(idx1:end)<0,1,'first'); %to first negative after first pos.
Area=trapz(CI(idx1:idx2-1))*0.1 % either give the selected value of lags2 or
% do as here, calculate with unit spacing and
% multiply by the actual increment.
Area =
1.7345
Note that you will still have errors related to the fact that you dont know the actual zero crossings. To illustrate zoom in on this plot:
figure;
plot(lags2,CI,'-x');
hold on
plot(lags2(idx1:idx2-1),CI(idx1:idx2-1),'-rx');
grid minor

Youssef  Khmou
Youssef Khmou 2013-8-24
编辑:Youssef Khmou 2013-8-24
hi,
You evaluate the integral of the auto-correlation function with respect to your boundaries , here is an example :
y=sin(2*pi*4*(0:0.1:10)); % 4 Hz
[C,lags]=xcorr(y,530);
Z=C;
Z(Z<0)=0; % boundaries
Z(Z>1)=0;
figure, plot(lags,Z);
Area01=trapz(lags,Z);
The result can be null; it depends on the number of samples in lags .
  2 个评论
Pete
Pete 2013-8-24
Hi, thanks for your reply.
From looking at the code, won't that just eliminate the values less than 0 and greater than 1? What about the values that are positive after the first negative values?
I need the area under the curve for JUST the first downward sloping part. And I'm not sure if it makes a difference but I'm using autocorr, not xcorr?
Here's an example of what I mean.
y=[1:1:10];
[C,lags]=autocorr(y,9);
plot(lags, C)
If you copy paste that you'll get a curve that crosses the x-axis at about x=3.5
I need the area under that curve up to that point, which from the looks of things would be about (0.5*3.5*1)= 1.75
hugoles
hugoles 2013-9-1
Hello Pete,
Have you found the right way to calculate this ? I have exactly the same problem.
Thanks,

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by