Produce PSD from a FFT output
Indeed, PHP is not a weapon of choice to do signal processing. But if you absolutely need to &quot;adapt&quot; the matlab formula, here is an one-liner to &quot;conjugate&quot; the data, based on commented lines from the code of your question (// $fft[0] is real portion of 1, etc.):
// PHP's $conjdata[·] stands for matlab's conj[Y] 
for ($i = 0, $cnt = count($data), $ri = 1; $i &lt; $cnt; $i++, $ri = -$ri) $conjdata[$i] = $data[$i]*$ri;

Also, the PSD formula is somewhat trickier than just Y*conj(Y)/N. See, for example, https://stackoverflow.com/questions/3949324/calculate-autocorrelation-using-fft-in-matlab, the second answer.