-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkhalgorithm.c
60 lines (50 loc) · 1.41 KB
/
khalgorithm.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* =====================================================================================
*
* Filename: khalgorithm.c
*
* Description:
*
* Version: 1.0
* Created: 2016년 11월 10일 13시 57분 16초
* Revision: none
* Compiler: gcc
*
* Author: Ph.D. Candidate KIM Hyeok (kh), ekh0324@gmail.com
* Company: Konkuk University
*
* =====================================================================================
*/
#include <math.h>
typedef enum { SUCCESS, FAILED,} SUCCESS_TYPE;
SUCCESS_TYPE get_autocorelation_from_seq ( int width, double* seq, int max_diff, double* autoFunction, double* autoError) {
// Init
int count[max_diff] ;
int ii,jj, diff ;
double mul_seq_ii_jj;
for ( diff = 0; diff < max_diff; diff += 1 ){
count[diff] = 0;
autoFunction[diff] = 0.;
autoError[diff] = 0.;
}
// Evaluation
for ( ii = 0; ii < width; ii += 1 )
for ( jj = 0; jj <= ii; jj += 1 )
{
diff = ii-jj;
if(diff<max_diff)
{
count[diff]++;
mul_seq_ii_jj = seq[ii]*seq[jj];
autoFunction[diff] +=mul_seq_ii_jj;
autoError[diff] +=mul_seq_ii_jj*mul_seq_ii_jj;
}
}
// averaging
for ( diff = 0; diff < max_diff; diff += 1 ){
autoFunction[diff] /= count[diff];
autoError[diff] = sqrt( (autoError[diff]/count[diff]
- autoFunction[diff]*autoFunction[diff]) /count[diff]);
}
return SUCCESS ;
}