Efficient algorithm for matrix spectral factorization