-
Notifications
You must be signed in to change notification settings - Fork 0
/
treshold.py
60 lines (57 loc) · 2.12 KB
/
treshold.py
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
import numpy as np
import asyncio
import matplotlib.pyplot as plt
import acquisition as acq
#-------------------------------------------
# Treshold Detection
#-------------------------------------------
async def execute():
#__________While loop__________
for i in range(len(acq.data["framesMatrix"])):
acq.data["whileData"].append(0)
for j, jVal in enumerate(acq.data["framesMatrix"][i]):
acq.data["whileData"][i] = pow(acq.data["framesMatrix"][i][j],2) + acq.data["whileData"][i]
#__________Sorting array by ASC__________
whileToMean = []
for item in acq.data["whileData"]:
whileToMean.append(item)
whileToMean.sort()
idx = 14
maxIdx = idx
if idx > len(whileToMean):
maxIdx = len(whileToMean)
firstArray = []
for i in range(maxIdx):
firstArray.append(whileToMean[i])
#__________Estimate mean of firstArray__________
mean = sum(firstArray) / len(firstArray)
#__________Boolean frame energy__________
acq.data["tresholdEnergy"] = mean * 2000
for i in range(len(acq.data["whileData"])):
if acq.data["whileData"][i] > acq.data["tresholdEnergy"]:
acq.data["booleanFrameEnergy"].append(1)
else:
acq.data["booleanFrameEnergy"].append(0)
#__________Finish rest of calculations__________
acq.data["size"] = len(acq.data["whileData"])
acq.data["summary"] = sum(acq.data["whileData"])
#print(acq.data["out"].__dict__)
async def plot():
#__________Energy Graph__________
x = np.arange(len(acq.data["whileData"]))
plt.figure()
plt.plot(x,acq.data["whileData"])
plt.plot([0, len(acq.data["whileData"])], [acq.data["tresholdEnergy"], acq.data["tresholdEnergy"]], '--', label='Treshold Energy')
plt.title("Energy Graph")
plt.ylabel("Amplitude")
plt.xlabel("Sample")
plt.legend()
plt.show()
#__________Boolean Energy Graph__________
x = np.arange(len(acq.data["booleanFrameEnergy"]))
plt.figure()
plt.plot(x,acq.data["booleanFrameEnergy"])
plt.title("Boolean Frame Energy")
plt.ylabel("Amplitude")
plt.xlabel("Sample")
plt.show()