-
Notifications
You must be signed in to change notification settings - Fork 0
/
cepstrogram.py
131 lines (57 loc) · 1.96 KB
/
cepstrogram.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
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
# author : Abhinav Narain
# computes spectral, cepstral and time features
# date : 27 May, 2016
import scipy ,sys, getopt, math
from scipy.fftpack import fft, fftfreq, fftshift
from scipy import signal,arange
from scipy.signal import butter, lfilter, freqz
from configs import *
from cepstrum import complex_cepstrum
import numpy as np
def filereader(filename,fs):
z= scipy.fromfile(open(filename), dtype=scipy.complex64)
print "length of total z= ", len(z)
# dtype with scipy.int16, scipy.int32, scipy.float32, scipy.complex64 or whatever type you were using.
mag, phase,x,y = [], [], [], []
start_sec=0.001
end_sec=0.1
z_needed = z[start_sec*fs: end_sec*fs]
#z_needed = z[600+start_sec*fs: 600+end_sec*fs]
z=z_needed
len_z = int(len(z))
print "length of needed z= ", len(z)
#len_z = int(20.0/6*len(z))
#len_z = int(400.0/6000*len(z))
for i in range(0, len_z):
mag.append(np.absolute(z[i]))
x.append(z[i].real)
y.append(z[i].imag)
phase.append(np.angle(z[i]))
return [x,y,mag, phase,z]
def main(argv):
inputfile=''
noisefile,outputfile='',''
noiseflag,inputflag=0,0
try:
opts, args = getopt.getopt(argv,"h:i:n:o:",["ifile=","nfile=","ofile"])
except getopt.GetoptError:
print 'file.py -i <inputfile> -n <noisefile> -o <outputfile> '
sys.exit(2)
for opt, arg in opts:
print opt ,arg,
if opt == '-h':
print 'file.py -i <inputfile> -n <noisefile> -o <outputfile>'
sys.exit()
elif opt in ("-i", "--ifile"):
inputfile = arg
inputflag=1
elif opt in ("-n", "--nfile"):
noisefile = arg
noiseflag=1
elif opt in ("-o", "--ofile"):
outputfile = arg
else:
print "check help for usage"
sys.exit()
if __name__=='__main__':
main(sys.argv[1:])