Projective measurement of energy on an ensemble of qubits with unknown frequencies