# Anybody here familiar with detrended fluctuation analysis (DFA)?

18 vues (au cours des 30 derniers jours)
lil brain le 27 Mai 2022
To those who are familiar with detrended fluctuation,
I am trying to figure out why the result of running a detrended fluctuation analysis turns out to be either negative or very small. The Hurst exponents I get when running the attached script is seemingly incorrect. The results should be between 0-1 (~0.5) but that is not the case. Unfortunately I dont have any idea on how to solve this issue.
I have attached a script called "dfaedit.m" and a sample time series ("sample_ts") for reference. The time series is that of an acceleration.
So my question is, why does my detrended fluctuation output give me small/negative results?
Thanks!
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponses (1)

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:
% 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
I hope this resolves the issue you were facing.
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Descriptive Statistics dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by