Skip to content

Instantly share code, notes, and snippets.

@Steboss
Created February 25, 2021 09:32
Show Gist options
  • Save Steboss/386953c294ed6e58b5334c685a16340b to your computer and use it in GitHub Desktop.
Save Steboss/386953c294ed6e58b5334c685a16340b to your computer and use it in GitHub Desktop.
First step of the dfa function
void dfa(float* X, int n_elems, int* scales, int scales_len, float* fluct, float* coeffs){
/* Main DFA function
Parameters
----------
X: float*
input signal vector
n_elems: int
number of elements in vector X
scales: float*
vector of scales, start from scale_low to scale_max with scale_dens as range
created in python -- explanation here:
scale_low: int
first scale value
scale_max: int
last scale value
scale values will be converted to an interval range
from 2^scale_low up to 2^scale_max
scale_dens; float
how dense should be the scale_low -- scale_max interval
range. E.g.:
scale_low = 5, scale_max = 9, scale_dens=0.25 :
intervalsfrom 2^5 to 2^9 with 0.25
step between values
Return
------
*/
// linear fitting only
int fitting_order = 1;
// define the averaged cumsum
float* Xcumsum;
Xcumsum = (float*)malloc(n_elems*sizeof(float));
// average of the vector X
float avg = vector_avg(X, n_elems);
Xcumsum = cumsum_averaged(X, n_elems, avg, Xcumsum);
// final results will be stored in rms vector
// rms vector has the dimension of len of scale --> scales_len
// scales_len is how many samples we have subdivided the signal
float * rms; //vector whose dimensions are as the same as xcumsum
rms = (float*) malloc(scales_len*sizeof(int));
// initialize to 0
for (int i=0; i<scales_len;i++){
rms[i]= 0.0;
}
// initialize the coefficient vector
// initialize a vector whose shape is fitting_Order+1 to store the coefficient of the fitting
// as a matter of fact the polynomial fitting is ax + b = y
// as you can see we have 2 coeffs, a and b
float* tmpCoeff;
tmpCoeff = (float*)malloc((fitting_order+1)*sizeof(float)); //2 is 1 + 1 where 1 is the order of th epolynomiaal fitting
for (int h=0; h<(fitting_order+1);h++){
tmpCoeff[h]=0.0;
}// for example if we had order 3, we would have had 4 as malloc(4*sizeof(float))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment