Calcul scientifique/Interpolation

Exemple d'interpolation (filtrage) de Savitsky et Golay du second et du quatrième ordre sur 11 points, en Python :

 def F2(a,b,c,d,e,f,g,h,i,j,k):
    """This function is the base for the Savitsky Golay 2nd order smoothing """ 
    coefs=[-0.084, 0.021, 0.103, 0.161, 0.196, 0.207, 0.196, 0.161,0.103, 0.021, -0.084]
    return (a*coefs[0] + b*coefs[1] + c*coefs[2] + d*coefs[3] + e*coefs[4] + f*coefs[5] + g*coefs[6] + h*coefs[7] + i*coefs[8] +j*coefs[9] + k*coefs[10]) 
 def lisse2(x):
    """Does the 2nd order savitsky Golay smoothing"""
    tx = ([ x[0] ] * 5)  + x + ([ x[-1] ] * 5)
    rx = []
    for i in range(5,len(tx)-5):
                rx.append(apply(F2,tuple(tx[i-5:i+6])))
    return rx

Voir aussi modifier