This paper addresses the problem of spectrum sensing for cognitive radio, in the case of a primary signal characterized by a discontinuous channel occupation within the considered sensing window. Under such conditions, the performance of two different energy detectors is investigated. The first one (energy average detector) decides whether the channel is free or busy on the basis of the energy sample average; the second one (energy threshold detector) performs a soft estimation of the channel occupation probability by comparing the energy samples with a proper threshold. For both the detectors, an analytical model is derived and validated through simulation, and the optimal decision threshold is found as a function of the primary signal parameters.