Anybody here familiar with detrended fluctuation analysis (DFA)?

조회 수: 3 (최근 30일)
lil brain
lil brain 2022년 5월 27일
편집: lil brain 2024년 6월 11일
To those who are familiar with detrended fluctuation,

답변 (1개)

Ayush Modi
Ayush Modi 2024년 1월 1일
Hi Hunter,
As per my understanding, you are trying to perform a Detrended Fluctuation Analysis on a sample data but getting negative or very small value. The attached script, when executed is throwing an error saying “Invalid data type. First input argument must be numeric or logical”.
Assuming first argument “file_name” is a string, it is assigned to variable x which is used as an input to “cumsum” function. “cumsum” function requires vector or matrix as an input.
Here is an example showing how you can perform the detrended Fluctuation Analysis:
x = load(file_name);
% Number of points in the time series
numberpoints = length(x);
% Define the minimum and maximum box sizes
MinBox = 4;
MaxBox = floor(0.25 * numberpoints);
BoxSizeDensity = 4;
LogScaleFactor = 2^(1/BoxSizeDensity);
% Initialize arrays to store the results
log_points_in_box = [];
log_Q = [];
% Perform DFA
BoxSize = MinBox;
while BoxSize <= MaxBox
% Initialize fluctuation for this box size
F = 0;
% Number of boxes at this box size
numBoxes = floor(numberpoints / BoxSize);
for i = 1:numBoxes
% Indices for the data in this box
idxStart = (i - 1) * BoxSize + 1;
idxEnd = i * BoxSize;
% Data in the box
boxData = x(idxStart:idxEnd);
% Linear detrend the box data
p = polyfit((1:BoxSize)', boxData, 1);
boxDataDetrended = boxData - polyval(p, (1:BoxSize)');
% Calculate fluctuation for this box
F = F + sqrt(mean(boxDataDetrended .^ 2));
end
% Average fluctuation over all boxes
F = F / numBoxes;
% Store the results
log_points_in_box = [log_points_in_box; log10(BoxSize)];
log_Q = [log_Q; log10(F)];
% Update the box size for the next iteration
BoxSize = BoxSize * LogScaleFactor;
BoxSize = round(BoxSize);
end
% Perform linear regression on log-log data
coeffs = polyfit(log_points_in_box, log_Q, 1);
H = coeffs(1); % Slope of the line is the Hurst exponent
r_line = polyval(coeffs, log_points_in_box);
r2 = corrcoef(log_points_in_box, log_Q);
r2 = r2(1, 2)^2; % Coefficient of determination
Please refer to the following MathWorks documentation for more information on “cumsum” function:
I hope this resolves the issue you were facing.

카테고리

Help CenterFile Exchange에서 Fractals에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by