int xtract_highest_value(const double *data, const int N, const void *argv, double *result) { int n = N; *result = data[--n]; while(n--) *result = XTRACT_MAX(*result, data[n]); return XTRACT_SUCCESS; }
int xtract_peak_spectrum(const double *data, const int N, const void *argv, double *result) { double threshold, max, y, y2, y3, p, q, *input = NULL; size_t bytes; int n = N, rv = XTRACT_SUCCESS; threshold = max = y = y2 = y3 = p = q = 0.0; if(argv != NULL) { q = ((double *)argv)[0]; threshold = ((double *)argv)[1]; } else rv = XTRACT_BAD_ARGV; if(threshold < 0 || threshold > 100) { threshold = 0; rv = XTRACT_BAD_ARGV; } XTRACT_CHECK_q; input = (double *)calloc(N, sizeof(double)); bytes = N * sizeof(double); if(input != NULL) input = memcpy(input, data, bytes); else return XTRACT_MALLOC_FAILED; while(n--) max = XTRACT_MAX(max, input[n]); threshold *= .01 * max; result[0] = 0; result[N] = 0; for(n = 1; n < N; n++) { if(input[n] >= threshold) { if(input[n] > input[n - 1] && n + 1 < N && input[n] > input[n + 1]) { result[N + n] = q * (n + (p = .5 * ((y = input[n-1]) - (y3 = input[n+1])) / (input[n - 1] - 2 * (y2 = input[n]) + input[n + 1]))); result[n] = y2 - .25 * (y - y3) * p; } else { result[n] = 0; result[N + n] = 0; } } else { result[n] = 0; result[N + n] = 0; } } free(input); return (rv ? rv : XTRACT_SUCCESS); }