#plot and calculate rms values of sine, six state trapezoidal etc.

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as pyplot
pyplot.figure()
x=np.arange(360.)
y=np.sin(x/360.*2.*np.pi)
y1=x.copy()
y1[0: 60]=x[0:60]/60
y1[ 60:120]=1
y1[120:180]=1-x[0:60]/60
y1[180:240]=-x[0:60]/60
y1[240:300]=-1
y1[300:360]=-1+x[0:60]/60

y2=x.copy()
y2[0: 30]=0
y2[30:150]=1
y2[150:210]=0
y2[210:330]=-1
y2[330:360]=0

y3=x.copy()
y3[0: 60]=.5
y3[60:120]=1
y3[120:180]=.5
y3[180:240]=-.5
y3[240:300]=-1
y3[300:360]=-.5

pyplot.plot(x,y,x,y1,x,y2,x,y3);pyplot.show()

rms=np.sqrt(np.mean(y**2))
b=np.sqrt(2)/2
rms1=np.sqrt(np.mean(y1**2))
rms2=np.sqrt(np.mean(y2**2))
rms3=np.sqrt(np.mean(y3**2))
print rms,rms1,rms2,rms3,b

print 0.8/rms, 0.8/rms1, 0.8/rms2, 0.8/rms3


#https://e2e.ti.com/blogs_/b/motordrivecontrol/archive/2013/11/08/generate-your-own-commutation-table-trapezoidal-control-3-phase-bldc-motors-using-hall-sensors