Effacer les filtres
Effacer les filtres

Anybody here familiar with detrended fluctuation analysis (DFA)?

15 vues (au cours des 30 derniers jours)
lil brain
lil brain le 27 Mai 2022
Modifié(e) : lil brain le 11 Juin 2024
To those who are familiar with detrended fluctuation,

Réponses (1)

Ayush Modi
Ayush Modi le 1 Jan 2024
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.

Community Treasure Hunt

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

Start Hunting!

Translated by