从模量

时间:2018-08-02 11:46:09

标签: python sin mod

我有一个经过mod函数的正弦函数,剩下的只是模数。知道初始数据是连续的,我试图通过定义de_modulus函数来重建它。但是,如果减少数据点的数量,则此方法不起作用:

def de_modulus(x_arr: list, y_arr: list, modulus: float):
    ly = len(y_arr)
    y_new = np.zeros(len(y_arr))
    y_new[:]=y_arr[:]
    d_phase = modulus
    ratio = 1.5
    i = 1
    while i+1 < len(x_arr):
        der_i  = (y_new[i+1] - y_new[i]) / (x_arr[i+1] - x_arr[i])
        der_im = (y_new[i] - y_new[i-1]) / (x_arr[i] - x_arr[i-1])
        if (der_i * der_im < 0) and (abs(der_i) > ratio * abs(der_im) or abs(der_i) < abs(der_im)/ratio):
            sgn = -np.sign(der_i)
            y_new[i+1:]=y_new[i+1:]+d_phase*sgn
        i+=1
    return y_new

modul = 360
x_r = np.arange(0,360, 15)          # defining an x range
''' if the step in x_r is increased the reconstruction doesnt work!'''
y_or = 400*np.sin(np.radians(x_r))   # the original data series
y_r = np.mod(y_or, modul)           # the y range with a modulus

y_new = de_modulus(x_r, y_r, modul) # the y data with reverse modulus function

plt.plot(x_r, y_or,  ':y', label = 'Original data');
plt.plot(x_r, y_r,   'D' , label = 'Mod 35');
plt.plot(x_r, y_new, '.' , label = 'Mod reversed');
plt.legend(); 

对于找到模块或解决该问题的算法的任何帮助,我们深表感谢。

以下是正常(step = {15)和非正常(step = 25)情况的两个示例: Functioning with step = 15

non-functioning with step = 25

0 个答案:

没有答案