This repository was archived by the owner on Oct 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpower-zcr-entropy_ZSCORES.py
99 lines (76 loc) · 3.21 KB
/
power-zcr-entropy_ZSCORES.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
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
import pandas as pd
import numpy as np
from scipy.stats import f
import matplotlib.pyplot as plt
import os
np.set_printoptions(threshold=np.inf)
targetPath = os.path.abspath("../sounds/sounds/hack-the-talk-exotel-master/training_dataset")
zcrFiles = [os.path.join(path, name)
for path, dirs, files in os.walk(targetPath)
for name in files if ("angry" in name and name.endswith(("-zeroCrossing.csv")))]
powerFiles = [os.path.join(path, name)
for path, dirs, files in os.walk(targetPath)
for name in files if ("angry" in name and name.endswith(("-powerSpectrum.csv")))]
entropyFiles = [os.path.join(path, name)
for path, dirs, files in os.walk(targetPath)
for name in files if ("angry" in name and name.endswith(("-entropy.csv")))]
def splitSignal(powerFile, zcrFile, entropyFile):
power = np.nan_to_num(np.array(pd.read_csv(powerFile, header=None), dtype='float64'))
zcr = np.nan_to_num(np.array(pd.read_csv(zcrFile, header=None), dtype='float64'))
entropy = np.nan_to_num(np.array(pd.read_csv(entropyFile, header=None), dtype='float64'))
zcr = np.ravel(zcr)
entropy = np.ravel(entropy)
divFrames = []
jump = 25
divFrameLength = 100
startIndex = 0
endIndex = divFrameLength
fileLen = len(power)
rangeLen = fileLen // endIndex
if fileLen > rangeLen:
paddingLength = (rangeLen * endIndex) + endIndex - fileLen
power = np.lib.pad(power, ((0, paddingLength), (0, 0)), 'constant', constant_values = 0)
zcr = np.lib.pad(zcr, (0, paddingLength), 'constant', constant_values = 0)
entropy = np.lib.pad(entropy, (0, paddingLength), 'constant', constant_values = 0)
fileLen = len(power)
while (endIndex != fileLen):
tempPower = power[startIndex:endIndex, ]
tempPower = tempPower.sum(axis = 1)
tempZcr = zcr[startIndex:endIndex]
tempEntropy = entropy[startIndex:endIndex]
mpow = np.mean(tempPower)
stdpow = np.std(tempPower)
mzcr = np.mean(tempZcr)
stdzcr = np.std(tempZcr)
ment = np.mean(tempEntropy)
stdent = np.std(tempEntropy)
powerZscr = []
zcrZscr = []
entZscr = []
for p in tempPower:
x = (p - mpow) / stdpow
powerZscr.append(x)
for z in tempZcr:
y = (z - mzcr) / stdzcr
zcrZscr.append(y)
for e in tempEntropy:
q = (e - ment) / stdent
entZscr.append(q)
totalpzscr = sum(i > 3 for i in powerZscr) + sum(i < -3 for i in powerZscr)
totalzcrzscr = sum(i > 3 for i in zcrZscr) + sum(i < -3 for i in zcrZscr)
totalentzscr = sum(i > 3 for i in entZscr) + sum(i < -3 for i in entZscr)
print totalpzscr, totalzcrzscr , totalentzscr
startIndex += jump
endIndex += jump
return divFrames
def main():
allFiles = np.dstack([powerFiles, entropyFiles, zcrFiles])
for File in allFiles:
for f in File:
powerFile = f[0]
entropyFile = f[1]
zcrFile = f[2]
print powerFile, zcrFile, entropyFile
splitSignal(powerFile, zcrFile, entropyFile)
if __name__ == '__main__':
main()