An efficient quantum filter for multiphoton states