This repository has been archived by the owner on Nov 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Traitement_Spectrum.py
149 lines (131 loc) · 4 KB
/
Traitement_Spectrum.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
# -*- coding: utf-8 -*-
"""
Derniere modification : 23/07/2021 à 10h07
@author: Mathis Briatte
"""
from scipy.signal import butter
import h5py
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
import librosa.display
directory = r"E:\Campagne_2021_FONTE\Acquisition Labjack_SPectrum\FONTE\
Mon_Nov_15_09:55:58"
fich = directory + "spectrum.h5"
fich_h5 = (fich[0:-3])
print(fich_h5)
MechData = h5py.File(fich_h5 + '.h5', 'r')
# Liste des channels utilisés
NAMES = []
for n in range(len(MechData['names'][0:])):
NAMES.append(MechData['names'][n].decode('ascii'))
RecMechChNam = ["Fn(N)", "Ft(N)", "speed(rpm)", "CapB(mm)", "CH1", "CH2"] # , "CapA(mm)", "CapB(mm)"]# ] #"Trig(V)", "top(V)"
# Création de la table de temps
FREQ = MechData['freq']
MechDecim = 1
MechTime = np.arange(0, MechData['table'].shape[0], MechDecim)/FREQ.value
DataChan = {}
for ChN in RecMechChNam:
idx = list(NAMES).index(ChN)
# On applique les facteurs de correction
DataChan[ChN] = MechData['table'][:, idx][::MechDecim] * \
MechData['factor'][idx]
del MechData
# signal - valeur continue pour FCT et Fn
GaussFiltSize = 10000
fs = FREQ.value # fs=10000 initialement
nyquist = fs / 2
order = 3
cutoff = 5
b, a = butter(order, cutoff/nyquist, 'lowpass')
# Capacitif
plt.figure(figsize=(20, 10))
CapB = DataChan['CapB(mm)']
CapB -= np.mean(CapB[200:1000])
plt.plot(MechTime, CapB, label='CapB(mm)')
SigncontCapB = signal.filtfilt(b, a, CapB)
CapB -= SigncontCapB
plt.plot(MechTime, CapB, label='CapB-continue')
plt.plot(MechTime, SigncontCapB, label='SigncontCapB')
plt.legend(loc='upper left', prop={'size': 10})
plt.savefig(fich_h5 + '_CAPB'+'.png',
dpi=300,
bbox_inches='tight',
pad_inches=0.1)
# Force normale
plt.figure(figsize=(20, 10))
Fn = DataChan['Fn(N)']
Fn -= np.mean(Fn[200:1000])
plt.plot(MechTime, Fn, label='Fn')
# SigncontFCTRECH=ndi.filters.gaussian_filter1d(FCTRECH, GaussFiltSize)
SigncontFn = signal.filtfilt(b, a, Fn)
Fn -= SigncontFn
plt.plot(MechTime, Fn, label='Fn-continue')
plt.plot(MechTime, SigncontFn, label='SigncontFn')
plt.legend(loc='upper left', prop={'size': 10})
plt.savefig(fich_h5 + '_Fn'+'.png',
dpi=300,
bbox_inches='tight',
pad_inches=0.1)
plt.clf()
# Particules
plt.figure(figsize=(20, 10))
CH1 = DataChan['CH1']
plt.plot(MechTime, CH1, label='CH1')
plt.legend(loc='upper left', prop={'size': 10})
plt.savefig(fich_h5 + '_CH1'+'.png',
dpi=300, bbox_inches='tight',
pad_inches=0.1)
plt.clf()
# Analyse spectrale
plt.figure(figsize=(20, 10))
sr = 1000
n_fft = 2 ** 14
d = Fn
D = librosa.amplitude_to_db(np.abs(librosa.stft(d, n_fft=n_fft)), ref=np.max)
librosa.display.specshow(D,
sr=sr,
x_axis='s',
y_axis='log',
hop_length=n_fft/4)
plt.colorbar(format='%+2.0f dB')
# plt.setp(ay1.get_xticklabels(), visible=False)
plt.title('Fn')
plt.savefig(fich_h5+'_TF' + '.png',
dpi=300,
bbox_inches='tight',
pad_inches=0.1)
plt.clf()
font = {'family': 'normal', 'weight': 'regular', 'size': 22}
plt.rc('font', **font)
# Informations globales spectrum
plt.figure(figsize=(10, 20))
plt.suptitle('Affichage Spectrum')
plt.subplot(3, 1, 1)
Fn = DataChan['Fn(N)']
Ft = DataChan['Ft(N)']
plt.plot(MechTime, Fn, label='Fn')
plt.plot(MechTime, Ft, label='Ft')
plt.ylabel("Effort (N)")
plt.ylim(0, 2000)
plt.xlim(0,)
plt.legend(loc='upper left', prop={'size': 5})
plt.title('Effort')
plt.subplot(3, 1, 2)
speed = DataChan['speed(rpm)']
plt.plot(MechTime, speed, label='Fn')
plt.ylabel("vitesse rotation (RPM)")
plt.ylim(0, 1500)
plt.xlim(0,)
plt.title('vitesse')
plt.subplot(3, 1, 3)
CH1 = DataChan['CH1']
plt.plot(MechTime, CH1, label='totalconcentration')
plt.title('Concentration Particules')
plt.xlabel("temps [s]")
# plt.xlim(200,400)
# plt.ylim(0,1e6)
plt.ylabel("dN/dlogDp [/cm³]")
plt.savefig(fich_h5+'.png', dpi=300, bbox_inches='tight',
pad_inches=0.1)
plt.clf()