1
我正在做電壓和電流有效值的som計算,並且剛剛獲得了一種更精確的新方法。 它適用於所設計的全週期值,但它對於半期值不起作用。電壓和電流有效值計算python
spp = 200,輸入是一個Nx200值的數組(週期)。
所以我得到充分的230 V當我這樣做的整段時間的版本,但只能從半週期的版本得到100V左右
整段時間的計算:
k = np.arange(spp) #
v_samples = np.vstack((np.zeros(spp), data_u_periods))
#print ("v_samples", v_samples)
v_samples = np.diff(v_samples, axis=0)
#print ("v_samples :", v_samples)
v_cossum = np.cumsum(v_samples * np.cos(2*np.pi/spp*k)) * np.sqrt(2)/spp
v_sinsum = np.cumsum(v_samples * np.sin(2*np.pi/spp*k)) * np.sqrt(2)/spp
print ("fp", 2*np.pi/spp*k)
v_complex = v_cossum + 1j*v_sinsum
v_complex = np.mean(v_complex.reshape((-1,spp)), axis=1)
i_samples = np.vstack((np.zeros(spp), data_i_periods))
i_samples = np.diff(i_samples, axis=0)
i_cossum = np.cumsum(i_samples * np.cos(2*np.pi/spp*k)) * np.sqrt(2)/spp
i_sinsum = np.cumsum(i_samples * np.sin(2*np.pi/spp*k)) * np.sqrt(2)/spp
i_complex = i_cossum + 1j*i_sinsum
i_complex = np.mean(i_complex.reshape((-1,spp)), axis=1)
s_complex = v_complex * i_complex.conjugate() # save for power calculations
ueffs = np.abs(v_complex)
ieffs = np.abs(i_complex)
half period calculations:
data_u_periods = data_u_periods.flatten()
data_i_periods = data_i_periods.flatten()
data_u_periods = data_u_periods.reshape((int(data_u_periods.shape[0]/(int(spp/2))),int(spp/2)))
data_i_periods = data_i_periods.reshape((int(data_i_periods.shape[0]/(int(spp/2))),int(spp/2)))
spp = spp/2
k = np.arange(spp) #
#print(spp)
#print (k)
#print (data_u_periods.shape)
v_samples = np.vstack((np.zeros(spp), data_u_periods))
#print ("v_samples", v_samples)
v_samples = np.diff(v_samples, axis=0)
#print ("v_samples :", v_samples)
#input("press enter")
v_cossum = np.cumsum(v_samples * np.cos(2*np.pi/spp*k)) * np.sqrt(2)/spp
v_sinsum = np.cumsum(v_samples * np.sin(2*np.pi/spp*k)) * np.sqrt(2)/spp
v_complex = v_cossum + 1j*v_sinsum
v_complex = np.mean(v_complex.reshape((-1,spp)), axis=1)
i_samples = np.vstack((np.zeros(spp), data_i_periods))
i_samples = np.diff(i_samples, axis=0)
i_cossum = np.cumsum(i_samples * np.cos(2*np.pi/spp*k)) * np.sqrt(2)/spp
i_sinsum = np.cumsum(i_samples * np.sin(2*np.pi/spp*k)) * np.sqrt(2)/spp
i_complex = i_cossum + 1j*i_sinsum
i_complex = np.mean(i_complex.reshape((-1,spp)), axis=1)
#s_complex = v_complex * i_complex.conjugate() # save for power calculations
print ("hp", 2*np.pi/spp*k)
ueffs = np.abs(v_complex)
ieffs = np.abs(i_complex)