implementing first part of Fourier Decomposition