function alpha = dfaScalingExponent(x, minBoxSize, maxBoxSize, pflag) % % varargout = dfaScalingExponent(xminBoxSize, midBoxSize, maxBoxSize, pflag) % calculates the detrended fluctuation analysis estimate of the scaling % exponent alpha. % % INPUTS % x : A Nx1 vector containing the series to be analyzed % minBoxSize : Smallest box width (default: 4) % maxBoxSize : Largest box width (default: N/4) % pflag : (Optional) pflag=1 plot, pflag=0 % OUTPUTS % alpha : estimate of scaling exponent, + % minBoxSize <= n <= maxBoxSize % % The raw time series x(i) is first integrated to give y(i); i=1,...,N. % For each length scale, n, y(i) is divided into segments of equal length, n. % In each segment, the data is detrended by subtracting the local linear least % squares fit, yn(k). The root-mean-square fluctuation of this integrated % and detrended time series is given by % F(n) = sqrt( (1/N) sum_{k=1}^N [y(k) - yn(k)]^2 ) % We calculate the average fluctuation F(n) for each segment n. % If the scaling approximately given by F(n) = c n^alpha, % we can estimate alpha by calculating the slope of log F(n) versus log n. % Such a linear relationship on a log-log plot indicates the presence of % power law (fractal) scaling. % A log-log plot of F(n) against n is provided when pflag=1. Default: plag=0. % Peng C-K, Buldyrev SV, Havlin S, Simons M, Stanley HE, Goldberger AL. % Mosaic organization of DNA nucleotides. Phys Rev E 1994;49:1685-1689. % % % 09-20-2017 Modified by Giulia Da Poian (GDP) to be included in the Physionet % HRV Toolkit for Matlab. (Original function name: dfa) % % REPO: % https://github.com/cliffordlab/PhysioNet-Cardiovascular-Signal-Toolbox % Copyright (c) 2005 Patrick E. McSharry (patrick@mcsharry.net) % % LICENSE: % This software is offered freely and without warranty under % the GNU (v3 or later) public license. See license file for % more information if nargin < 2 || isempty(minBoxSize) minBoxSize = 4; end if nargin < 3 || isempty(maxBoxSize) maxBoxSize = length(x)/4; end if nargin < 5 pflag = 0; end if size(x,1)