-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinf127228.py
74 lines (55 loc) · 2.08 KB
/
inf127228.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
import sys # Fetch argv from system
import warnings # Warnings
import soundfile # Read sound file
from scipy import fft # FFT
import matplotlib.pyplot as plt # Plot
from scipy.signal import decimate # Decimate - FFT signal
from scipy.fftpack import fftfreq # FFT frequences
# Disable warnings in code
warnings.filterwarnings("ignore")
def main():
thresh = 700
# Check filename in argv
if len(sys.argv) > 1:
# Read file
signal, sample_rate = soundfile.read(sys.argv[1], dtype='int16')
# Eliminate file to only one dimension
if len(signal.shape) == 2:
signal = [s[0] for s in signal]
# FFT
fft_signal = signal.copy()
fft_signal = fft(fft_signal)
# Reduce data to first half
fft_half = fft_signal[1 : int(len(fft_signal) / 2)]
# ABS
fft_abs = fft_half.copy()
fft_abs = abs(fft_abs) * 2 / len(signal)
# Prepare decimate from fft signal
decimate_2 = fft_abs.copy()
decimate_2 = decimate(decimate_2, 2, n = 8)
decimate_3 = fft_abs.copy()
decimate_3 = decimate(decimate_3, 3, n = 8)
decimate_4 = fft_abs.copy()
decimate_4 = decimate(decimate_4, 4, n = 8)
decimate_5 = fft_abs.copy()
decimate_5 = decimate(decimate_5, 5, n = 8)
# Calculate length of shortest decimate result
decimate_len = len(decimate_5)
# Merge results
result = fft_abs[:decimate_len] * decimate_2[:decimate_len] * decimate_3[:decimate_len] * decimate_4[:decimate_len] * decimate_5[:decimate_len]
# Clear data
result[0 : 100] = 0
maxAmp = max(result)
check = 0
for i in range(len(result)):
if result[i] == maxAmp:
check = i
break
if check > thresh:
print('F')
else:
print('M')
else:
print('>> LOOSER << You mast set filename as parameter')
if __name__ == '__main__':
main()