A method for determining a process variable of a product in a tank based on a time delay of electromagnetic waves. The method further comprises forming a measurement signal comprising a sequence of values, each value representing a time correlation between a pulse of a reference signal and a reflected signal, sampling and digitizing this measurement signal to form a digital signal, identifying a time window of the digital signal including the surface echo peak, determining a relative time period between a reference time corresponding to the predefined reference and a beginning of the time window, time-to-frequency transforming the digital signal in the time window to obtain a phase spectrum, determining a relative phase shift of the spectrum and using the relative phase shift to calculate a corresponding time shift, and determining the time delay by adding the relative time period and the time shift.The invention is based on the realization that major improvement of measurement performance, compared to amplitude detection only, can be achieved by discrimination of the phase difference between the reflected signal and a reference. The detection is further independent of the pulse waveform and modulation, significantly reducing the requirements on pulse modulation.