我正在对电压和电流有效值进行som计算,并且以更高的精度获得了一种新的方法。 它适用于所设计的全周期值,但它不适用于半周期值。
spp = 200,输入是一个具有Nx200值的数组(逐周期)。
因此,当我使用完整版本时,我可以获得230 V电压,但只能从半周期版本获得约100 V
全周期计算:
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)
答案 0 :(得分:0)
这是一个简单的疏忽,而不是在同一点上取两个时期之间的差异,我采取了同一时期的第一个和第二个之间的差异。而下半场对下一个赛季的上半场......
所以现在它可以正常工作!
固定代码:
“”” 获取期间RMS值的函数
Args
-----
data_u_periods : all voltage periods
data_i_periods : all current periods
spp : samples per period
Returns
---------
arrays with half period rms values
"""
k = np.arange(spp)
v_samples = np.vstack((np.zeros(spp), data_u_periods))
v_samples = np.diff(v_samples, axis = 0)
v_prepp_cos = v_samples * np.cos(2*np.pi/spp*k)
v_prepp_sin = v_samples * np.sin(2*np.pi/spp*k)
v_prepp_cos = v_prepp_cos.flatten()
v_prepp_cos = v_prepp_cos.reshape((int(v_prepp_cos.shape[0]/(int(spp/2))), int(spp/2)))
v_prepp_sin = v_prepp_sin.flatten()
v_prepp_sin = v_prepp_sin.reshape((int(v_prepp_sin.shape[0]/(int(spp/2))), int(spp/2)))
#print ("v_samples hp", v_samples)
i_samples = np.vstack((np.zeros(spp), data_i_periods))
i_samples = np.diff(i_samples, axis = 0)
i_prepp_cos = i_samples * np.cos(2*np.pi/spp*k)
i_prepp_sin = i_samples * np.sin(2*np.pi/spp*k)
i_prepp_cos = i_prepp_cos.flatten()
i_prepp_cos = i_prepp_cos.reshape((int(i_prepp_cos.shape[0]/(int(spp/2))), int(spp/2)))
i_prepp_sin = i_prepp_sin.flatten()
i_prepp_sin = i_prepp_sin.reshape((int(i_prepp_sin.shape[0]/(int(spp/2))), int(spp/2)))
spp = spp/2
v_cossum = np.cumsum(v_prepp_cos) * np.sqrt(2)/(2*spp)
v_sinsum = np.cumsum(v_prepp_sin) * np.sqrt(2)/(2*spp)
v_complex = v_cossum + 1j*v_sinsum
v_complex = np.mean(v_complex.reshape((-1, spp)), axis = 1)
i_cossum = np.cumsum(i_prepp_cos) * np.sqrt(2)/(2*spp)
i_sinsum = np.cumsum(i_prepp_sin) * np.sqrt(2)/(2*spp)
i_complex = i_cossum + 1j*i_sinsum
i_complex = np.mean(i_complex.reshape((-1, spp)), axis = 1)
ueffs = np.abs(v_complex)
ieffs = np.abs(i_complex)
#print ("ueff hp", ueffs)
return ueffs, ieffs