python jitter,在Python中计算FFT手抖动信号

So,we are working on a signal obtained from hand tremors by using a 3 axis accelerometer.We want to compute FFT of the signal to find out the dominating frequency.The dominating frequency obtained in matlab was upto 10 Hz which was expected.However, the result obtained in python are not as expected.Can someone please let us know the program for computation of FFT in python?

What I have tried:import csv

import numpy as np

#import scipy as sy

#import scipy.fftpack as syfp

#import pylab as pyl

with open('C:\Users\Sharvari Inamdar\Desktop\F0005CH1.CSV') as csvfile:

spamreader=csv.reader(csvfile,delimiter='',quotechar='|')

for row in spamreader:

print(', '.join(row))

#Read in data from file here

array=np.loadtxt("C:\Users\Sharvari Inamdar\Desktop\F0005CH1.CSV")

from scipy.fftpack import fft

#Number of sample points

N = len(array)

#sample spacing

T=1.0/N

x = np.linspace(0.0, 2*np.pi*N*T, N)

#y = np.sin(50.0 * 2.0*np.pi*x) + 0.5*np.sin(80.0 * 2.0*np.pi*x)

yf = fft(array)

xf = np.linspace(0.0, 1.0/(2.0*T), N/2)

import matplotlib.pyplot as plt

plt.plot(xf, 2.0/N * np.abs(yf[0:N/2]))

plt.grid()

plt.show()

program 2

import csv

import numpy as np

import pylab as pyl

with open('C:\Users\Sharvari Inamdar\Desktop\F0005CH1.CSV') as csvfile:

spamreader=csv.reader(csvfile,delimiter='',quotechar='|')

for row in spamreader:

print(', '.join(row))

#Read in data from file here

array=np.loadtxt("C:\Users\Sharvari Inamdar\Desktop\F0005CH1.CSV")

Ts=1.00E-03;

Fs=1/Ts;

Fn=Fs/2;

#np.isnan(array)=[]

#Ly1=array.shape

N=len(array)

T=np.linspace(0,1,N)*Ts

#pyl.plot(T,array)

from scipy.fftpack import fft

FF=fft(array/N);

#Fv=np.linspace(0,1,np.fix(N/2)+1)*Fn;

#Iv=len(Fv)

pyl.plot(T,FF)

we have tried the above 2 programs and many other versions of this program.

解决方案Well, you don't specify what exactly you're seeing that's different... but I'll take a stab at a common problem. The result of an FFT has the DC frequency (i.e. 0) in the first bin, proceeded by the real frequency spectral bins, then proceeded by the negative spectral bins. Use a "shift" function to shift the zero bin to the middle and re-arrange the negative components to be left of zero for plotting:

fftshift - Rearranges the fft output, moving the zero frequency to the center of the spectrum[^]

The spacing of the spectral bins is essentially Fs/N, where Fs is the sampling frequency and N is the FFT size. The larger the FFT size, the tighter your bin spacing for a given sample rate (i.e. you get more frequency resolution). Due to computational complexity, typically N will be a power of 2... if you feed less samples than a power of 2 to an FFT library, they'll zero pad up to the closest power of 2.

As for the magnitude scaling of your graph, well... there's a handful of scaling options but 1/N and 1/sqrt(N) are common options.

Good luck!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值