简体   繁体   English

如何在 Python 中提取以下频域特征?

[英]How to Extract the following Frequency-domain Features in Python?

Please feel free to point out any errors\/improvements in the existing code请随时指出现有代码中的任何错误\/改进<\/h3>

So this is a very basic question and I only have a beginner level understanding of signal processing.所以这是一个非常基本的问题,我对信号处理只有初级的了解。 I have a 1.02 second accelerometer data sampled at 32000 Hz.我有一个以 32000 Hz 采样的 1.02 秒加速度计数据。 I am looking to extract the following frequency domain features after having performed FFT in python -在 python 中执行 FFT 后,我希望提取以下频域特征 -

Mean Freq, Median Freq, Power Spectrum Deformation, Spectrum energy, Spectral Kurtosis, Spectral Skewness, Spectral Entropy, RMSF (Root Mean Square Freq.), RVF (Root Variance Frequency), Power Cepstrum.平均频率、中值频率、功率谱变形、谱能量、谱峰度、谱偏度、谱熵、RMSF(均方根频率)、RVF(根方差频率)、功率倒谱。

More specifically, I am looking for plots of these features as a final output.更具体地说,我正在寻找这些特征的图作为最终输出。<\/h3>

The csv file containing data has four columns: Time, X Axis Value, Y Axis Value, Z Axis Value (The accelerometer is a triaxial one).包含数据的 csv 文件有四列:时间、X 轴值、Y 轴值、Z 轴值(加速度计是三轴的)。 So far on python, I have been able to visualize the time domain data, apply convolution filter to it, applied FFT and generated a Spectogram that shows an interesting shock到目前为止,在 python 上,我已经能够可视化时域数据,对其应用卷积滤波器,应用 FFT 并生成一个显示有趣冲击的 Spectogram

To Visualize Data可视化数据<\/h1>
#Importing pandas and plotting modules import numpy as np from datetime import datetime import pandas as pd import matplotlib.pyplot as plt #Reading Data data = pd.read_csv('HelicalStage_Aug1.csv', index_col=0) data = data[['X Value', 'Y Value', 'Z Value']] date_rng = pd.date_range(start='1\/8\/2018', end='11\/20\/2018', freq='s') #Plot the entire time series data and show gridlines data.grid=True data.plot()<\/code><\/pre>

enter image description here<\/a>在此处输入图像描述<\/a>

Denoising去噪<\/h1>
# Applying Convolution Filter mylist = [1, 2, 3, 4, 5, 6, 7] N = 3 cumsum, moving_aves = [0], [] for i, x in enumerate(mylist, 1): cumsum.append(cumsum[i-1] + x) if i>=N: moving_ave = (cumsum[i] - cumsum[iN])\/N #can do stuff with moving_ave here moving_aves.append(moving_ave) np.convolve(x, np.ones((N,))\/N, mode='valid') result_X = np.convolve(data[["X Value"]].values[:,0], np.ones((20001,))\/20001, mode='valid') result_Y = np.convolve(data[["Y Value"]].values[:,0], np.ones((20001,))\/20001, mode='valid') result_Z = np.convolve(data[["Z Value"]].values[:,0], np.ones((20001,))\/20001, mode='valid') plt.plot(result_X-np.mean(result_X)) plt.plot(result_Y-np.mean(result_Y)) plt.plot(result_Z-np.mean(result_Z))<\/code><\/pre>

enter image description here<\/a>在此处输入图像描述<\/a>

FFT and Spectogram FFT 和频谱图<\/h1>
import numpy as np import scipy as sp import scipy.fftpack import pandas as pd import matplotlib.pyplot as plt %matplotlib inline df = pd.read_csv('HelicalStage_Aug1.csv') df = df.drop(columns="Time") df.plot() plt.title('Sensor Data as Time Series') signal = df[['Y Value']] signal = np.squeeze(signal) Y = np.fft.fftshift(np.abs(np.fft.fft(signal))) Y = Y[int(len(Y)\/2):] Y = Y[10:] plt.figure() plt.plot(Y)<\/code><\/pre>

enter image description here<\/a>在此处输入图像描述<\/a>

 plt.figure() powerSpectrum, freqenciesFound, time, imageAxis = plt.specgram(signal, Fs= 32000) plt.show()<\/code><\/pre>

enter image description here<\/a>在此处输入图像描述<\/a>

If my code is correct and the generated FFT and spectrogram are good, then how can I graphically compute the previously mentioned frequency domain features?如果我的代码是正确的并且生成的 FFT 和频谱图都很好,那么我如何以图形方式计算前面提到的频域特征呢?

I have tried doing the following for MFCC -我尝试为 MFCC 执行以下操作 -<\/h1>
 import numpy as np import matplotlib.pyplot as plt import scipy as sp from scipy.io import wavfile from python_speech_features import mfcc from python_speech_features import logfbank # Extract MFCC and Filter bank features mfcc_features = mfcc(signal, Fs) filterbank_features = logfbank(signal, Fs) # Printing parameters to see how many windows were generated print('\\nMFCC:\\nNumber of windows =', mfcc_features.shape[0]) print('Length of each feature =', mfcc_features.shape[1]) print('\\nFilter bank:\\nNumber of windows =', filterbank_features.shape[0]) print('Length of each feature =', filterbank_features.shape[1])<\/code><\/pre>

Visualizing filter bank features可视化滤波器组特征<\/h1>
#Matrix needs to be transformed in order to have horizontal time domain mfcc_features = mfcc_features.T plt.matshow(mfcc_features) plt.title('MFCC')<\/code><\/pre>

enter image description here<\/a> enter image description here<\/a>在此处输入图像描述 在此处<\/a>输入图像描述<\/a>

"

我认为您的fft摄取程序不正确,fft输出通常是峰值,而在进行abs吸收时应该是一个峰值, 因为 ,可能应该将其更改为Y = np.fft.fftshift(np.abs(np.fft.fft(signal)))Y=np.abs(np.fft.fftshift(signal)

Did you ever have any luck with generating RMSF, spectral kurtosis and spectral skewness?您是否曾经在生成 RMSF、谱峰度和谱偏度方面遇到过运气? I'm struggling with these two.我正在与这两个斗争。

B

"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM