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,

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by