Area under autocorrelation function.
7 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(2 个)
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
0 个评论
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 个评论
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!