''' ============== 特征提取的类 ===================== 时域特征 :11类 频域特征 : 13类 总共提取特征 : 24类 参考文献 英文文献 016_C_(Q1 时域和频域共24种特征参数 ) Fault diagnosis of rotating machinery based on multiple ANFIS combination with GAs '''
import numpy as np
import scipy.stats
import matplotlib.pyplot as plt
class Fea_Extra():
def __init__(self, Signal, Fs = 25600):
self.signal = Signal
self.Fs = Fs
def Time_fea(self, signal_):
""" 提取时域特征 11 类 """
N = len(signal_)
y = signal_
t_mean_1 = np.mean(y)
t_std_2 = np.std(y, ddof=1)
t_fgf_3 = ((np.mean(np.sqrt(np.abs(y)))))**2
t_rms_4 = np.sqrt((np.mean(y**2)))
t_pp_5 = 0.5*(np.max(y)-np.min(y))
t_skew_6 = scipy.stats.skew(y)
t_kur_7 = scipy.stats.kurtosis(y)
t_cres_8 = np.max(np.abs(y))/t_rms_4
t_clear_9 = np.max(np.abs(y))/t_fgf_3
t_shape_10 = (N * t_rms_4)/(np.sum(np.abs(y)))
t_imp_11 = ( np.max(np.abs(y)))/(np.mean(np.abs(y)))
t_fea = np.array([t_mean_1, t_std_2, t_fgf_3, t_rms_4, t_pp_5,
t_skew_6, t_kur_7, t_cres_8, t_clear_9, t_shape_10, t_imp_11 ])
return t_fea
def Fre_fea(self, signal_):
""" 提取频域特征 13类 :param signal_: :return: """
L = len(signal_)
PL = abs(np.fft.fft(signal_ / L))[: int(L / 2)]
PL[0] = 0
f = np.fft.fftfreq(L, 1 / self.Fs)[: int(L / 2)]
x = f
y = PL
K = len(y)
f_12 = np.mean(y)
f_13 = np.var(y)
f_14 = (np.sum((y - f_12)**3))/(K * ((np.sqrt(f_13))**3))
f_15 = (np.sum((y - f_12)**4))/(K * ((f_13)**2))
f_16 = (np.sum(x * y))/(np.sum(y))
f_17 = np.sqrt((np.mean(((x- f_16)**2)*(y))))
f_18 = np.sqrt((np.sum((x**2)*y))/(np.sum(y)))
f_19 = np.sqrt((np.sum((x**4)*y))/(np.sum((x**2)*y)))
f_20 = (np.sum((x**2)*y))/(np.sqrt((np.sum(y))*(np.sum((x**4)*y))))
f_21 = f_17/f_16
f_22 = (np.sum(((x - f_16)**3)*y))/(K * (f_17**3))
f_23 = (np.sum(((x - f_16)**4)*y))/(K * (f_17**4))
f_fea = np.array([f_12, f_13, f_14, f_15, f_16, f_17, f_18, f_19, f_20, f_21, f_22, f_23])
return f_fea
def Both_Fea(self):
""" :return: 时域、频域特征 array """
t_fea = self.Time_fea(self.signal)
f_fea = self.Fre_fea(self.signal)
fea = np.append(np.array(t_fea), np.array(f_fea))
return fea