LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help to accomplish Detrended Fluctuation Analysis (DFA) analysis

Solved!
Go to solution

Hello,

I am tryting to accomplish one graph DFA of time series.

I have ECG signal, where I got the RR intervals. To accomplish the DFA analysis I need to do:

 

The method of detrended fluctuation analysis has proven useful in revealing the extent of long-range correlations in time series. Briefly, the time series to be analyzed (with N samples) is first integrated. Next, the integrated time series is divided into boxes of equal length, n. In each box of length n, a least squares line is fit to the data (representing the trend in that box). The y coordinate of the straight line segments is denoted by yn(k).

Next, we detrend the integrated time series, y(k), by subtracting the local trend, yn(k), in each box. The root-mean-square fluctuation of this integrated and detrended time series is calculated by

F(n) = ((1/N)(Sum (from k=1 to N) of ((y(k) - yn(k))**2)))**.5

This computation is repeated over all time scales (box sizes) to characterize the relationship between F(n), the average fluctuation, and the box size, n. Typically, F(n) will increase with box size. A linear relationship on a log-log plot indicates the presence of power law (fractal) scaling. Under such conditions, the fluctuations can be characterized by a scaling exponent, the slope of the line relating log F(n) to log n.

 

 

In the first step, First, we compute the integrated signal according to the formula       

where Bave is the mean value of the signal. Ok, I tried to integrate the signal subtracting the mean value of signal but It seems I dont do it correctly. It doesnst seem well done.
 
In this links you can get more data and example of what to do:
 
Any help is aprecitate.
Regards, Fred.
0 Kudos
Message 1 of 11
(5,874 Views)

Fred,

     Call the input Array in your VI B(i).  To the right of B(i), you compute Bave.  In the For loop above, you compute Sum(B(i)), and if you subtract Bave from this (instead of subtracting it from B(i), you would get y(k).

 

     Now if you plot B(i) and y(k) on the same graph, you'll see that B is more-or-less flat, and y is more-or-less linearly increasing.  This is why you "detrend" y.  Here's one way to detrend --

  1. Pick the "box length", n.
  2. Reshape y(k) into a 2D array having n rows and as many columns as "fits".
  3. Create a 1D array of X values corresponding to the column count.  The easiest way to do this is to wire the number of columns to a For loop and pass the index, "i", out, converting it to a 1D array of Dbl.
  4. Pass the 2D array into a For loop, which will work on a row-at-a-time.  Also pass in (through a tunnel) the array of columns (step 3).
  5. Use the Linear Fit function from the Math sub-palette to get the best linear fit from the block of y data.  Subtract this fit from the input y array.
  6. Pass this out of the For loop, making the output tunnel be a "Concatenating" tunnel (rather than the default Indexing tunnel).  This gives you back the original, now transformed, detrended 1D array for box length n.

I'm not sure what you do with these data.  It seems that you need to do this for many (all?) values of n, but you would be the better judge of this.

 

Here is a graph of your original data (white) and the detrended data (red) with a box length of 10.

Detrend.png

Bob Schor

 

0 Kudos
Message 2 of 11
(5,849 Views)

Hi Bob, 

 

Thanks for reply and sorry por late answer!

 

Ok, if I undertand well, you mean I need to subtract the sum(B(i)). But I dont understand if I need only to substract or I need do the  numerical integration.

 

In the first step it would be:

Sin título.png

The bottom graph would be y(k), correct?.

 

The rest of parts, I think in part 5 I dont have clear. The graph should look so:

graph1.png

 

The graph you send me, i seems like integrated signal with trends

 

signals.png

 

Can you show me the vi?, please. 

Thanks for help!.

Fred

 

 

0 Kudos
Message 3 of 11
(5,814 Views)

I made a mistake in my earlier code -- I didn't subtract the mean Bave from the integrand (sum) being developed to create y(k), so my y(k) had a definite "trend".  I fixed it here.

 

I noticed you referenced the LabVIEW Biomedical Toolkit -- are you trying to duplicate their DFA code?

 

I think where you (or, perhaps, where I) went astray was when "integration" is mentioned.  I believe this simply refers to the summation step that produces y(k) -- I don't think there is any need for another explicit integration.

 

Give this a try --

Detrend.png

Bob Schor

 

0 Kudos
Message 4 of 11
(5,801 Views)

Thank you so much Bob,

 

Yes, now I got it.

Yes, I want duplicate the DFA graph of biomedical. I checked it but this feature is no open.

 

Yes, I think you are right and the integration is not requested.

 

The root-mean-square fluctuation of this integrated and detrended time series is calculated by

F(n) = ((1/N)(Sum (from k=1 to N) of ((y(k) - yn(k))**2)))**.5

This computation is repeated over all time scales (box sizes) to characterize the relationship between F(n), the average fluctuation, and the box size, n. Typically, F(n) will increase with box size. A linear relationship on a log-log plot indicates the presence of power law (fractal) scaling. Under such conditions, the fluctuations can be characterized by a scaling exponent, the slope of the line relating log F(n) to log n.

 

We have the y(k)- yn(k). For get the F(n).  1/N = n box length?. It lacks the root-mean-square and TWO SQUARED. 

For finally, log F(n) o log n.

 

 

0 Kudos
Message 5 of 11
(5,791 Views)

The root-mean-square fluctuation of this integrated and detrended time series is calculated by

F(n) = ((1/N)(Sum (from k=1 to N) of ((y(k) - yn(k))**2)))**.5

This computation is repeated over all time scales (box sizes) to characterize the relationship between F(n), the average fluctuation, and the box size, n. Typically, F(n) will increase with box size. A linear relationship on a log-log plot indicates the presence of power law (fractal) scaling. Under such conditions, the fluctuations can be characterized by a scaling exponent, the slope of the line relating log F(n) to log n.

 

We have the y(k)- yn(k). For get the F(n).  1/N = n box length?. It lacks the root-mean-square and TWO SQUARED. 

For finally, log F(n) o log n.  


I believe that N is the number of points in the Y series.  F is a function of box length, "n", based on a set of "N" data points.  Note that N is not necessarily the size of your data array, it is the number of points that went into calculating the particular value of F(n).  For example, assume you have 250 points, and you set n = 10.  You will divide your points into 25 groups of 10 points, compute y(k) and y10(k) for all 250 points and take the RMS.  Now consider n=100.  You only have 2 sets of 100 points, so here N = 2*100 = 200, not 250.

 

Bob Schor

0 Kudos
Message 6 of 11
(5,784 Views)

Hi Bob,

 

Yes, It seems N is the values x1 and x2 boxes for select number of samples, in DFA biomedical, yo can see in attached image, they use from 10 to 40 samples and for x2= 70 to 300 samples.

 

I dont understand how they decide what value to use and how get the correct values of log n. 

I attached the graph that we would get with the current data input, using the 2000 readings beats.

 

sample_graph.png

 

I tried but I dont have it clear. Any advise more?.

Thanks for your time.

Fred

0 Kudos
Message 7 of 11
(5,753 Views)
Solution
Accepted by topic author Fonsi

Hi, DFA fustrated me for a long time. My issue was repeating the box segment analyisis for each window in the series. Meaning that if there are 300 beats then the 4 beat interval is repaeted 75 times whilst the 64 beat segment is repeated 4 times with the RMS for each window length being F(n).  See my solution below. MinN and MaxN are the minimum and maximum window lengths.

 

This is able to repoduce the same result as Kubios for the DFA.

 

Hope this is of some use.

 

Cheers

Kevin.

DFA.jpg

Message 8 of 11
(5,674 Views)

Hi Kevin,

 

Thank you so much!!. I was crazy with this, some weeks ago I tried again but I didnt get the way to do... Now I see correctly.

 

I attached one example compare kubios and your vi and works fine.

I only see diferent the a1 and a2. In kubios a1 is the higher.

 

Thank you and regards.

 

0 Kudos
Message 9 of 11
(5,647 Views)

hi

 

thanks for information

 

but sorry i am unable to understand breakpoint significance in this vi. how its value is decided?

kindly help

thanks

0 Kudos
Message 10 of 11
(5,442 Views)