1 /******************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
22 #include "tizen_log.h"
23 #include "lib_proximity.h"
26 // Proximity code start
27 float CalculateExponentialAverage(int numberOfSamples, int *array, int startindex, int flag)
30 float denominator = 0;
34 if (flag < arraysize / RSSI_EA) // first loop buffer full
37 for (int i = 0; i < startindex; i++)
42 if (startindex == 0) {}
45 average = average / startindex;
48 DBG("average1 : %f", average);
52 for (int i = 0; i < arraysize; i++)
57 for (int i = startindex; i < startindex + RSSI_EA; i++)
62 average = average / (arraysize - numberOfSamples);
65 DBG("average2 : %f", average);
68 //exponential moving average
70 //CHANGE THIS FOR DIFFERENT SMOOTHING EFFECT
72 for (i = startindex + numberOfSamples - 1; i >= startindex; i--)
74 double temp = pow(beta, startindex + numberOfSamples - i - 1);
75 numerator += array[i] * (float)temp;
76 denominator += (float)temp;
82 numerator += average * pow(beta, offset + numberOfSamples);
83 denominator += pow(beta, offset + numberOfSamples);
86 return numerator / denominator;
90 float calculateDistance(float avgRSSI, float txPower)
97 float ratio = avgRSSI * 1.0 / txPower;
100 return pow(ratio, 10);
104 float distance = (0.7) * pow(ratio, 10) + 0.024;
109 // proximity code end