We demonstrate numerically the complete co-phasing of a 39-meter primary segmented mirror consisting of 798 hexagonal segments in R/V- and H/I/J-bands. The segments are initially misaligned with a Gaussian random distribution of piston/tip/tilt causing inter-segment phase steps of 5.5 waves RMS. We take into account the obscuration by the six spider vanes of the ELT, each 530mm wide. We simulate the signal from a modulated pyramid wavefront sensor (PWFS) when imaging the pupil of the telescope in monochromatic light, using discrete 2D Fourier transforms. The PWFS can measure segment tip/tilt inside the hexagons and the inter-segment steps in the middle of each of the 2262 edges. The pyramid phase step response function is not strongly seeing-dependent and resembles a single peak which is easier to resolve and process than that of e.g. the phase contrast WFS which has an oscillating shape. By contrast to the Shack-Hartmann WFS, the segment edge registration does not strongly rely on accurate optical alignment and can be done digitally during postprocessing. We model four separate narrow-band exposures of starlight for 30--50 seconds each whose results are compared to determine a set of most likely step solutions for each edge. We then employ maximum likelihood techniques to further filter the solutions and finally the Generalized Least Squares method, optimally exploiting the redundancies of the segment geometry. The residual RMS wavefront error of the phased mirror is below 1/30th of a wave.