-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.py
More file actions
96 lines (61 loc) · 1.84 KB
/
test.py
File metadata and controls
96 lines (61 loc) · 1.84 KB
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
import binuralfeature as bf
import numpy as np
import matplotlib.pyplot as plt
from pylab import *
from mpl_toolkits.mplot3d import Axes3D
filename = "/scratch/Datasets/AVASM/annotated_white_noise/Recorded/1.wav"
#filename = "/scratch/Python/BinuralAudio/sf2_cln.wav"
frq, snd = bf.readaudio(filename)
print snd.shape
#bf.plotintime(frq,snd,2)
snd1 = snd[:,0];
fs = 16000.
dnw_snd = bf.downsample(snd1,frq,fs)
print 'New downsampled size:', dnw_snd.shape
bf.plotintime(fs,dnw_snd,0)
plt.show()
# Parameter setting
time_win = 64.
frame_shift = 32.
ns=fs/1000*time_win;
nfft=1024;
no=fs/1000*(time_win-frame_shift);
nzp=ns/2;
zp=np.zeros((nzp,));
XL = bf.myspectrogram(np.hstack((zp,dnw_snd,zp)),nfft,ns,fs,np.hamming,noverlapratio=0.5)
nfreq,nframe =XL.shape
nfreq = nfreq/2;
inside = range(int(np.rint(nzp/(ns-no))),int(np.rint(nframe-nzp/(ns-no))))
XL = XL[0:nfreq,inside];
print 'Spectogram Size:', XL.shape
# plot Spectogram
bf.plotspectrogram(XL,nfft,fs,title='CH-Left')
## RIGHT
#bf.plotintime(frq,snd,2)
snd1 = snd[:,1];
dnw_snd = bf.downsample(snd1,frq,fs)
print 'New downsampled size:', dnw_snd.shape
bf.plotintime(fs,dnw_snd,0)
plt.show()
# Parameter setting
time_win = 64.
frame_shift = 32.
ns=fs/1000*time_win;
nfft=1024;
no=fs/1000*(time_win-frame_shift);
nzp=ns/2;
zp=np.zeros((nzp,));
XR= bf.myspectrogram(np.hstack((zp,dnw_snd,zp)),nfft,ns,fs,np.hamming,noverlapratio=0.5)
nfreq,nframe =XR.shape
nfreq = nfreq/2;
inside = range(int(np.rint(nzp/(ns-no))),int(np.rint(nframe-nzp/(ns-no))))
XR = XR[0:nfreq,inside];
print 'Right Spectogram Size:', XR.shape
# plot Spectogram
bf.plotspectrogram(XR,nfft,fs,title='CH-right')
ILD,IPD = bf.feature_ILDandIPD(XL,XR)
bf.plotIPD_ILD(ILD,'ILD')
bf.plotIPD_ILD(IPD,'IPD')
''' max freq recoveed is f2/2 ==8000hz, using nfft=1024 point the frequency
resolution is fs/2/nfft=7.8hz per frequency bin,
'''