-
Notifications
You must be signed in to change notification settings - Fork 1
/
IAS_RB_surveillance_ACCX_v2_no_down.py
181 lines (159 loc) · 6.48 KB
/
IAS_RB_surveillance_ACCX_v2_no_down.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import os
import sys
Wdir = os.getcwd()
sys.path.append(Wdir+'\functions')# add to path
import numpy as np
import scipy.io as sio # load save matlab files
from scipy.io import wavfile # read wav files
import scipy.signal as sg # signal pack
import matplotlib.pyplot as plt # plotting
from matplotlib.gridspec import GridSpec # easy subplots
from functions.IAS_functions import iaslinearapproxv2,f_est_linear,tTacho_fsig,tTacho_fsigLVA
# function load matfile
def loading_matfile(filed='none'):
mat_contents = sio.loadmat(filed, mdict=None, appendmat=True)
for k, v in mat_contents.items():
try:
if v.size==sum(v.shape)-1:
globals()[k]=v.flatten()
else:
globals()[k]=v
except:
globals()[k]=v
return globals()
# %% loading wav file
lfile = (Wdir+'\Surveillance8 Contest')
data = np.zeros([10240000,3])
fs, data[:,0] = wavfile.read(lfile+'\Acc0.wav')
fs, data[:,1] = wavfile.read(lfile+'\Acc1.wav')
fs, data[:,2] = wavfile.read(lfile+'\Acc2.wav')
fs, tacho = wavfile.read(lfile+'\Tacho.wav')
#data = data[140*fs:160*fs,:]
#tacho = tacho[140*fs:160*fs]
#f_0,_,_ = tTacho_fsig(tacho,fs,PPR=44,isencod=1); del tacho
#f_0 = f_0/60
_,f_0=tTacho_fsigLVA(tacho,fs,TPT=44)
f_0 = f_0*62/61
#%% ---------------------------------------------------------------------------
# No downsampling
fmaxmin = np.r_[170,260]/fs#fmaxmin = np.r_[170,260]/fs
Nw = 2**np.ceil(np.log2(1/fmaxmin[0]*2))
Nw = int(Nw) # 1024 default important parameterS and K
H = Nw/2
# --------------dfac order best identifyed but initial visual exam is requiered
dfac = 62/2 # frequence d'engranement 62
fmaxmin = fmaxmin*dfac
delta = 5/fs*dfac
K = fs/2/max(f_0*dfac); K = np.r_[int(K)] # amount of orders
# No downsampling fliplr ------------------------------------------------------
savename = 'D16_ias_baseline_acc2_nodown_fliplr_dfacf0'
f_alpha_est = np.zeros(data.shape+(K.size*2,))
L = np.r_[2]
for l in L:
tmp = iaslinearapproxv2(np.flipud(data[:,l]),Nw,K,fmaxmin,delta,0,'tmpaccxv3')
if l==L[0]:
f_alpha_est = f_alpha_est[:tmp.shape[0],:,:]
f_alpha_est[:,l,:] = tmp
result_dict = {'f_alpha_est': f_alpha_est,'fs':fs,\
'Nw':Nw, 'K':K}
sio.savemat('Dataz/'+savename+'.mat',result_dict,do_compression=True)
savename = 'D16_ias_linear_acc2_nodown_fliplr_dfacf0'
f_alpha_est = np.zeros(data.shape+(K.size*2,))
L = np.r_[2]
for l in L:
tmp = iaslinearapproxv2(np.flipud(data[:,l]),Nw,K,fmaxmin,delta,1,'tmpaccxv3')
if l==L[0]:
f_alpha_est = f_alpha_est[:tmp.shape[0],:,:]
f_alpha_est[:,l,:] = tmp
result_dict = {'f_alpha_est': f_alpha_est,'fs':fs,\
'Nw':Nw, 'K':K}
sio.savemat('Dataz/'+savename+'.mat',result_dict,do_compression=True)
# ----------------------------------------------------------------------------
savename = 'D16_ias_baseline_acc2_nodown_dfacf0'
f_alpha_est = np.zeros(data.shape+(K.size*2,))
L = np.r_[2]
for l in L:
tmp = iaslinearapproxv2(data[:,l],Nw,K,fmaxmin,delta,0,'tmpaccxv3')
if l==L[0]:
f_alpha_est = f_alpha_est[:tmp.shape[0],:,:]
f_alpha_est[:,l,:] = tmp
result_dict = {'f_alpha_est': f_alpha_est,'fs':fs,\
'Nw':Nw, 'K':K}
sio.savemat('Dataz/'+savename+'.mat',result_dict,do_compression=True)
savename = 'D16_ias_linear_acc2_nodown_dfacf0'
f_alpha_est = np.zeros(data.shape+(K.size*2,))
L = np.r_[2]
for l in L:
tmp = iaslinearapproxv2(data[:,l],Nw,K,fmaxmin,delta,1,'tmpaccxv3')
if l==L[0]:
f_alpha_est = f_alpha_est[:tmp.shape[0],:,:]
f_alpha_est[:,l,:] = tmp
result_dict = {'f_alpha_est': f_alpha_est,'fs':fs,\
'Nw':Nw, 'K':K}
sio.savemat('Dataz/'+savename+'.mat',result_dict,do_compression=True)
#%% No downsampling ACC1
fmaxmin = np.r_[170,260]/fs#fmaxmin = np.r_[170,260]/fs
Nw = 2**np.ceil(np.log2(1/fmaxmin[0]*2))
Nw = int(Nw) # 1024 default important parameterS and K
H = Nw/2
# --------------dfac order best identifyed but initial visual exam is requiered
dfac = 1 # premier harmonic
fmaxmin = fmaxmin*dfac
delta = 5/fs*dfac
K = fs/2/max(f_0*dfac); K = np.r_[int(K)] # amount of orders
savename = 'D16_ias_baseline_acc1_nodown_dfacf0'
f_alpha_est = np.zeros(data.shape+(K.size*2,))
L = np.r_[1]
for l in L:
tmp = iaslinearapproxv2(data[:,l],Nw,K,fmaxmin,delta,0,'tmpaccxv3')
if l==L[0]:
f_alpha_est = f_alpha_est[:tmp.shape[0],:,:]
f_alpha_est[:,l,:] = tmp
result_dict = {'f_alpha_est': f_alpha_est,'fs':fs,\
'Nw':Nw, 'K':K}
sio.savemat('Dataz/'+savename+'.mat',result_dict,do_compression=True)
#%
savename = 'D16_ias_linear_acc1_nodown_dfacf0'
f_alpha_est = np.zeros(data.shape+(K.size*2,))
L = np.r_[1]
for l in L:
tmp = iaslinearapproxv2(data[:,l],Nw,K,fmaxmin,delta,1,'tmpaccxv3')
if l==L[0]:
f_alpha_est = f_alpha_est[:tmp.shape[0],:,:]
f_alpha_est[:,l,:] = tmp
result_dict = {'f_alpha_est': f_alpha_est,'fs':fs,\
'Nw':Nw, 'K':K}
sio.savemat('Dataz/'+savename+'.mat',result_dict,do_compression=True)
#%% No downsampling ACC2
fmaxmin = np.r_[170,260]/fs#fmaxmin = np.r_[170,260]/fs
Nw = 2**np.ceil(np.log2(1/fmaxmin[0]*2))
Nw = int(Nw) # 1024 default important parameterS and K
H = Nw/2
# --------------dfac order best identifyed but initial visual exam is requiered
dfac = 1 # premier harmonic
fmaxmin = fmaxmin*dfac
delta = 5/fs*dfac
K = fs/2/max(f_0*dfac); K = np.r_[int(K)] # amount of orders
savename = 'D16_ias_baseline_acc2_nodown_allorders'
f_alpha_est = np.zeros(data.shape+(K.size*2,))
L = np.r_[2]
for l in L:
tmp = iaslinearapproxv2(data[:,l],Nw,K,fmaxmin,delta,0,'tmpaccxv3')
if l==L[0]:
f_alpha_est = f_alpha_est[:tmp.shape[0],:,:]
f_alpha_est[:,l,:] = tmp
result_dict = {'f_alpha_est': f_alpha_est,'fs':fs,\
'Nw':Nw, 'K':K,'dfac':dfac}
sio.savemat('Dataz/'+savename+'.mat',result_dict,do_compression=True)
#%
savename = 'D16_ias_linear_acc1_nodown_allorders'
f_alpha_est = np.zeros(data.shape+(K.size*2,))
L = np.r_[2]
for l in L:
tmp = iaslinearapproxv2(data[:,l],Nw,K,fmaxmin,delta,1,'tmpaccxv3')
if l==L[0]:
f_alpha_est = f_alpha_est[:tmp.shape[0],:,:]
f_alpha_est[:,l,:] = tmp
result_dict = {'f_alpha_est': f_alpha_est,'fs':fs,\
'Nw':Nw, 'K':K,'dfac':dfac}
sio.savemat('Dataz/'+savename+'.mat',result_dict,do_compression=True)