How to do autocorrelation with a given data
42 次查看(过去 30 天)
显示 更早的评论
Hi, Could you help me please? I have data (t,A). t stands for time, A for Absorbance, and i have it in txt file. I'd like to analyze it with autocorrelation function. I tried writing the code, I did just like how i understand what i read the mathworks site 'Autocorr'. But simply saying, i'm afraid the data 't' that i have is not included in the process with my coding. Could I get more explanation, or a validation maybe? thank you.
just for example the data is
t = 3:3:30
A = 3.523;3.523;3.43;3.323;3.43;3.43;3.323;2.923;2.723;2.923;
[t,A]=textread('Data.txt')
[acf,lags]=autocorr(A)
0 个评论
采纳的回答
Pavl M.
2024-10-27,13:48
编辑:Pavl M.
2024-10-27,14:09
clc
clear all
close all
stdv = 4;
norm_option = 'normalized'; %unbiasd, biased
t = 3:3:30;
A = [3.523;3.523;3.43;3.323;3.43;3.43;3.323;2.923;2.723;2.923];
%OR:
% [t,A]=textread('Data.txt')
subplot(2, 1, 1);
plot(t, A, 'b-', 'LineWidth', 2);
grid on;
xlabel('t');
ylabel('A')
title('Original Data')
%Next will incorporate in full 't' in the process:
[autoCorrA,l] = autocorr(A,NumLags=length(t)-1,NumSTD=stdv);
autocorrB = xcorr(A,norm_option)
autoCorrA
l
subplot(2, 1, 2);
%original time included
plot(t,autoCorrA, 'b-', 'LineWidth', 2);
grid on;
xlabel('Index');
ylabel('ACF')
title('ACF')
figure
plot(t,autocorrB(1:2:length(autocorrB)), 'b-', 'LineWidth', 2);
grid on;
xlabel('Index');
ylabel('XCorr')
title('Raw normalized auto cross-correlation')
%Constructed from needing help code by
%https://independent.academia.edu/PMazniker
%+380990535261
%https://diag.net/u/u6r3ondjie0w0l8138bafm095b
%https://github.com/goodengineer
%https://orcid.org/0000-0001-8184-8166
%https://willwork781147312.wordpress.com/portfolio/cp/
%https://www.youtube.com/channel/UCC__7jMOAHak0MVkUFtmO-w
%https://nanohub.org/members/130066
%https://pangian.com/user/hiretoserve/
%https://substack.com/profile/191772642-paul-m
更多回答(1 个)
Image Analyst
2024-10-27,13:26
I don't have the Econometric Toolbox so I can't use autocorr but I can use the regular xcorr. Maybe this will help you:
t = 3:3:30;
A = [3.523;3.523;3.43;3.323;3.43;3.43;3.323;2.923;2.723;2.923];
subplot(2, 1, 1);
plot(t, A, 'b-', 'LineWidth', 2);
grid on;
xlabel('t');
ylabel('A')
title('Original Data')
% [t,A]=textread('Data.txt')
% [acf,lags]=autocorr(A)
autoCorrA = xcorr(A);
subplot(2, 1, 2);
plot(autoCorrA, 'b-', 'LineWidth', 2);
grid on;
xlabel('Index');
ylabel('Autocorrelation Value')
title('Autocorrelation Signal')
2 个评论
Image Analyst
2024-10-28,15:37
I'm not really familiar with the autocorrelation function. It seems different than the usual one we all know. They say
"
The autocorrelation function measures the correlation between the univariate time series yt and yt + k, where k = 0,...,K and yt is a stochastic process.
rk=ckc0,
where
- ck=1TT−k∑t=1(yt−‾y)(yt+k−‾y).
- c0 is the sample variance of the time series.
Suppose that q is the lag beyond which the theoretical ACF is effectively 0. Then, the estimated standard error of the autocorrelation at lag k > q is
SE(rk)=⎹⎷1T(1+2q∑j=1r2j).
If the series is completely random, then the standard error reduces to 1/√T.
"
You probably know more about that function than me. Sorry but I don't really know when you'd use that. I'm guessing it's something special for econometrics applications.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Time Series Events 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!