Harmonic Filter Function In Python