Spectrum sensing is a key function of cognitive radio systems. Sensing performance is determined by three main factors including the wireless channel between the primary system and the cognitive radio nodes, the detection threshold, and the sensing time. In this letter a closed-form expression for the average probability of detection for energy detection based spectrum sensing over two-wave with diffuse power fading channels is derived. This expression is then used to optimize the detection threshold for cognitive radio nodes, which operate in confined structures that exhibit worse than Rayleigh fading conditions. Such fading conditions can represent a behavioral model of cognitive machine-to-machine systems deployed in enclosed structures such as in-vehicular environments.