2 * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "savitzky_golay_filter15.h"
21 /* length of filter. changing it requires changing coef_array! */
24 /* sum of numerators of elements in coef_array. */
25 #define SUM_COEF 1105.0
27 /* array with coefficients for savitzky-golay filter. must be length of n! */
28 static double coef_array[] = {
29 -78 / SUM_COEF, -13 / SUM_COEF, 42 / SUM_COEF, 87 / SUM_COEF,
30 122 / SUM_COEF, 147 / SUM_COEF, 162 / SUM_COEF, 167 / SUM_COEF,
31 162 / SUM_COEF, 147 / SUM_COEF, 122 / SUM_COEF, 87 / SUM_COEF,
32 42 / SUM_COEF, -13 / SUM_COEF, -78 / SUM_COEF };
34 savitzky_golay_filter15::savitzky_golay_filter15()
37 m_array = (double *)calloc(ARRAY_SIZE, sizeof(double));
40 savitzky_golay_filter15::~savitzky_golay_filter15()
49 double savitzky_golay_filter15::filter(double value)
52 for (int i = 0; i < ARRAY_SIZE; i++)
58 for (int i = 1; i < ARRAY_SIZE; i++)
59 m_array[i - 1] = m_array[i];
60 m_array[ARRAY_SIZE - 1] = value;
63 for (int i = 0; i < ARRAY_SIZE; i++)
64 avrg += m_array[i] * coef_array[i];
68 void savitzky_golay_filter15::reset(void)