A phacoemulsification system including a phacoemulsification probe having a probe body, a horn disposed at least partially in the probe body, a needle coupled with the horn and configured to be inserted into an eye, and a piezoelectric actuator disposed in the probe body and configured to vibrate the horn and the needle in a first direction with a stroke length with respect to the probe body; a signal generator configured to generate a drive signal to drive a vibration of the piezoelectric actuator; a stroke measurement apparatus configured to provide indications of the stroke length of the needle over time; and a controller configured to dynamically adjust a frequency of the drive signal so as to maximize the stroke length and maintain mechanical resonance of the needle responsively to the provided indications of the stroke length.