如何在Python中提取以下频域功能?

问题描述 投票:0回答:1

Please feel free to point out any errors/improvements in the existing code

所以这是一个非常基本的问题,我只对初学者有一定的信号处理理解。我有一个1.02秒的加速度计数据采样在32000赫兹。我想在python中执行FFT后提取以下频域特征 -

平均频率,中值频率,功率谱变形,频谱能量,频谱峰度,频谱偏度,频谱熵,RMSF(均方根频率),RVF(根方差频率),功率倒谱。

More specifically, I am looking for plots of these features as a final output.

包含数据的csv文件有四列:时间,X轴值,Y轴值,Z轴值(加速度计是三轴的)。到目前为止,在python上,我已经能够可视化时域数据,对其应用卷积滤波器,应用FFT并生成显示有趣震动的Spectogram

To Visualize Data

#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()

enter image description here

Denoising

# 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[i-N])/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))

enter image description here

FFT and Spectogram

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)

enter image description here

    plt.figure()
powerSpectrum, freqenciesFound, time, imageAxis = plt.specgram(signal, Fs= 32000)
plt.show()

enter image description here

如果我的代码是正确的并且生成的FFT和频谱图是好的,那么我如何以图形方式计算前面提到的频域特征?

I have tried doing the following for MFCC -

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])

Visualizing filter bank features

#Matrix needs to be transformed in order to have horizontal time domain

mfcc_features = mfcc_features.T
plt.matshow(mfcc_features)
plt.title('MFCC')

enter image description here enter image description here

python feature-extraction spectrum frequency-domain
1个回答
0
投票

我认为你的fft服用程序不正确,fft输出通常是峰值,当你服用abs时它应该是一个峰值,as,可能你应该把它改为Y = np.fft.fftshift(np.abs(np.fft.fft(signal)))Y=np.abs(np.fft.fftshift(signal)

© www.soinside.com 2019 - 2024. All rights reserved.