General-purpose pulse-processing algorithm