-
Notifications
You must be signed in to change notification settings - Fork 18
/
hfd.c
33 lines (23 loc) · 751 Bytes
/
hfd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stdlib.h>
#include <math.h>
int curve_length(size_t *, size_t, double *, size_t, double *);
int curve_length(size_t *k_arr, size_t m, double *data, size_t n, double *Lk)
{
size_t i,j,k;
double Lmk,s;
for(i = 0; i < m; i++){// over array of k's (interval "time")
Lmk = 0.0;
for(j = 0; j < k_arr[i]; j++){// over m's
// Sum over absolute differences
s = 0.0;
for(k = j+k_arr[i]; k < n; k+=k_arr[i]){
s += fabs(data[k] - data[k-k_arr[i]]);
}
// Multiply sum with the normalization term and divide by k_arr[i]
Lmk += ( s * (double)(n-1) / (double)( floor((n-j-1)/k_arr[i]) * k_arr[i] ) ) / k_arr[i];
}
//Average Lmk
Lk[i] = Lmk / (double)k_arr[i];
}
return 0;
}