-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunc.c
352 lines (246 loc) · 6.05 KB
/
func.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
#include "func.h"
#include "stdbool.h"
#include "arm_math.h"
long yuvarla(float32_t x)
{
if (x >= 0)
return (long) (x+0.5);
else
return (long) (x-0.5);
}
float32_t calculateSD_with_array(float32_t *data) //dizinin standart sapmasini hesaplar
{
float32_t sum = 0.0, mean, standardDeviation = 0.0;
int i;
for(i=0; i<1000; ++i)
{
sum += data[i];
}
mean = sum/1000;
for(i=0; i<1000; ++i)
standardDeviation += pow( (data[i] - mean), 2);
standardDeviation=sqrt(standardDeviation/1000) ;
return standardDeviation;
}
float32_t calculateSD(float32_t data[]) //dizinin standart sapmasini hesaplar
{
float32_t sum = 0.0, mean, standardDeviation = 0.0;
int i;
for(i=0; i<1000; ++i)
{
sum += data[i];
}
mean = sum/1000;
for(i=0; i<1000; ++i)
standardDeviation += pow( (data[i] - mean), 2);
standardDeviation=sqrt(standardDeviation/999) ;
return standardDeviation;
}
float32_t calculateMAV(float32_t data[],uint16_t n) //dizinin MEAN ABSOLUTE VALUE
{
//fILTRELEME KULLNIYORSAN ABS ALMAN GEREKECEK.
float32_t sum = 0.0, mean, MAV = 0.0 ,temp=0.0;
int i;
for(i=0; i<n; ++i)
{
sum += data[i];
}
mean = sum/n;
MAV=mean;
return MAV;
}
float32_t calculateA_with_Array(float32_t* data, uint16_t n) //dizninn ortalamasini hesaplar
{
float32_t sum = 0.0, mean=0;
int i;
for(i=0; i<n; i++)
{
sum += data[i];
}
mean = sum/n;
return mean;
}
float32_t calculateA(float32_t data[], uint16_t n) //dizninn ortalamasini hesaplar
{
float32_t sum = 0.0, mean=0;
int i;
for(i=0; i<n; i++)
{
sum += data[i];
}
mean = sum/n;
return mean;
}
uint8_t enkucuk_array(float32_t sayi[] ,uint8_t n)
{
float32_t kucuk =sayi[0];
uint8_t index =0;
for(int i=0; i<n; i++)
{
if( sayi[i]< kucuk)
{ kucuk=sayi[i];
index=i;
}
}
return index;
}
uint8_t enkucuk(float32_t sayi_0 ,float32_t sayi_1 ,float32_t sayi_2 )//3sayidan en kucugu bulur
{
if(sayi_0<sayi_1 && sayi_0<sayi_2)
return 0; // sayi_0 ;
if(sayi_1<sayi_2 && sayi_1<sayi_0)
return 1; // sayi_1;
else
return 2; //sayi_2;
}
int16_t rolled_abs(float32_t deger)
{
int16_t deger_rolled= yuvarla(deger);
if(deger_rolled<0)
{
deger_rolled=deger_rolled*-1;
}
return deger_rolled;
}
float32_t is_closest( float32_t sw , float32_t sw1, float32_t sw2) { //en yakin degisken hangisi onu bulur
float32_t t=0;
float32_t t1=0;
float32_t t2=0;
t= rolled_abs(sw-sw1);
t1= rolled_abs(sw-sw2);
return enkucuk(t1+t2,t1,t2);
}
/*****************************************************************/
int64_t min = 100000;
int64_t max = -100000;
int64_t counter=0;
float32_t buffer[1000];
void MinMax(float Values, int Window)
{
int64_t bufferSize = Window;
//float32_t buffer[counter];
buffer[counter] = Values;
for (unsigned int i = 0; i < bufferSize; ++i)
{
if (buffer[i] < min)
{
min = buffer[i];
}
else if (buffer[i] > max)
{
max = buffer[i];
}
}
++counter;
counter = counter % bufferSize;
}
//void MinMax::setValues (float Values, int Window)
//{
// min = 100000;
// max = -100000;
//
// bufferSize = Window;
// buffer[counter] = Values;
//
// for (unsigned int i = 0; i < bufferSize; ++i)
// {
// if (buffer[i] < min)
// {
// min = buffer[i];
// }
// else if (buffer[i] > max)
// {
// max = buffer[i];
// }
// }
//
// ++counter;
// counter = counter % bufferSize;
//}
//void MovingAverage::setValue (float Value, int NSamplesAvg)
//{
// nSamplesAvgF = NSamplesAvg;
// inputF[pointerF] = Value;
//
// for (int i = 0; i < nSamplesAvgF; ++i)
// {
// sumF = sumF + inputF[i];
// }
//
// mavgF = sumF / nSamplesAvgF;
//
// sumF = 0;
// ++pointerF;
// pointerF = pointerF % nSamplesAvgF;
//}
//void MovingAverage::setValue (int Value, int NSamplesAvg)
//{
// nSamplesAvgI = NSamplesAvg;
// inputI[pointerI] = Value;
//
// for (int i = 0; i < nSamplesAvgI; ++i)
// {
// sumI = sumI + inputI[i];
// }
//
// mavgI = sumI / nSamplesAvgI;
//
// sumI = 0;
// ++pointerI;
// pointerI = pointerI % nSamplesAvgI;
//
//}
//void SecondOrderDifference::setValue (float Value)
//{
// input = Value;
// sod = (input - (2 * previousInputs[0]) + previousInputs[1]) * scaleFactor;
//
// previousInputs[inputPointer] = input;
// ++inputPointer;
// inputPointer = inputPointer % 2;
//}
//void ZeroCrossing::setValue (float Value, int BufferSize)
//{
// bufferSizeF = BufferSize;
// bufferF[counterF] = Value;
// zeroCrossingRateF = 0;
//
// for (unsigned int i = 0; i < bufferSizeF; ++i)
// {
// if (bufferF[i] > 0 && bufferF[(i + 1) % bufferSizeF] < 0)
// {
// ++zeroCrossingRateF;
// }
// else if (bufferF[i] < 0 && bufferF[(i + 1) % bufferSizeF] > 0)
// {
// ++zeroCrossingRateF;
// }
// else continue;
// }
//
// ++counterF;
// counterF = counterF % bufferSizeF;
//}
//void ZeroCrossing::setValue (int Value, int BufferSize)
//{
// bufferSizeI = BufferSize;
// bufferI[counterI] = Value;
// zeroCrossingRateI = 0;
//
// for (unsigned int i = 0; i < bufferSizeI; ++i)
// {
// if (bufferI[i] > 0 && bufferI[(i + 1) % bufferSizeI] < 0)
// {
// ++zeroCrossingRateI;
// }
// else if (bufferI[i] < 0 && bufferI[(i + 1) % bufferSizeI] > 0)
// {
// ++zeroCrossingRateI;
// }
// else continue;
// }
//
// ++counterI;
// counterI = counterI % bufferSizeI;
//}
/***************************************************************************/