The determination of the spectral distribution of an x-ray beam from attenuation measurements in a narrow beam has aroused great interest since it was first proposed by Silberstein in 1932. Since then, it has become clear that this is an ill-conditioned problem. Then, due to the intrinsic difficulties of the problem, care has been taken to improve the mathematical and numerical inversion techniques. Alternative ways to circumvent the explicit inversion by using the attenuation curve itself to calculate directly generalized moments of the solution have also been found. In this work, the explicit reconstruction of the spectral distribution is carried out by an expectation-maximization method that satisfies the a priori condition of positiveness of the solution and allows us to impose the boundness of its support easily, conditions which are known to be fulfilled by physically acceptable solutions. The simulations made and the experimental validation of the proposed method allow us to prove its scope and limitations.