raspberry pi - Make Python FFT code faster -
can me make python code faster? @ moment reach 11 meassurements per second. hope faster don't know how it.
import matplotlib.pyplot plt import matplotlib.animation animation import numpy np import time pylab import * ################################################################### import accelneu accel import rpi.gpio gpio scipy.fftpack import fft gpio.setmode(gpio.bcm) high=true low=false ###variablendefinitionen: ##adda wandler: #pins: sclk = 18 #taktuhr mosi = 24 #master-out-slave-in miso = 23 #master-in-slave-out cs1 = 25 #chip-select 1 (a/d) cs2 = 12 #chip-select 2 (d/a) cs3 = 4 #chip-select 2 (acceleration) #sonst infos: numbit1 = 12 # in anzahl bits ic 1 (a/d) numbit2 = 10 # out anzahl bits ic 2 (d/a) #variablendefinition voltagemaxin = 5.000 voltagemaxout = 4.0955 #maximalspannung voltage = 2.500 ##drucksensor: voltageoffset = 0.014652014652014652 #v spannungsoffset typ:20mv pressuresensitivity = 0.0035 #v/kpa empfindlichkeit #accelerationsensitivity = 0.015625 ##gpios gpio.setup(sclk, gpio.out) gpio.setup(mosi, gpio.out) gpio.setup(miso, gpio.in) gpio.setup(cs1, gpio.out) gpio.setup(cs2, gpio.out) gpio.setup(cs3, gpio.out) ####################### xlimit=500 fig=figure(figsize=(8,7),dpi=100) x=[i+1 in range (xlimit)] y=[0 in range (xlimit)] ax1=fig.add_subplot(211) ax2=fig.add_subplot(212) line1, =ax1.plot(x,y,'r-') line2, =ax2.plot(x,y,'g-') ax1.set_ylim([-0.5, 2.5]) ax2.set_ylim([0, 0.4]) ############################################################ #fft: n=xlimit #512#1000 #number of samplepoints/sampling rate spacing=2048 #1024 t=1.0/spacing #sample spacing/sampling interval xf=np.linspace(0.0, 1.0/(2.0*t), n/2) line2.set_xdata(xf[1:n/2-1]) ############################################################ def animate(i): t0=time.time() y[1:]=y[:-1] ##zeitraum 1 t1=time.time() y[0],z=accel.readaxisacceleration(1) ##zeitraum 2 t2=time.time() line1.set_ydata(y) ##zeitraum 3 t3=time.time() ffty=fft(y) ##zeitraum 4 t4=time.time() ffty=ffty[1:n/2-1] ##zeitraum 5 t5=time.time() line2.set_ydata(2.0/n*np.abs(ffty[0:n/2]))#ffty) ##zeitraum 6 t6=time.time() print(t1-t0,t2-t1,t3-t2,t4-t3,t5-t4,t6-t5) return line1, line2 #lines t7=time.time() ani =animation.funcanimation(fig,animate,xrange(1,200),interval=0,blit=true) t8=time.time() print (t8-t7) plt.show()
maybe can tell me how make faster. class accelneu function reads out data acceleration sensor (not source of slow behaviour, profiled this).
Comments
Post a Comment