fix d2 function for heterodyne (WIP)