An implantable medical device configured to provide for an intracardiac function, the implantable medical device comprising: a body; a sensor arrangement arranged on the body and configured to receive a cardiac sense signal; and a processing circuitry operatively connected to the sensor arrangement, wherein the processing circuitry is configured to process the cardiac sense signal received using the sensor arrangement to detect a signal deflection in the cardiac sense signal potentially indicative of an atrial event (As) caused by atrial activity; and to start a peak detection window based on a detection of said signal deflection for determining a peak amplitude associated with said atrial event (As), wherein the peak detection window comprises one or more sub-windows (P i, P i+1,...), the processing circuitry being configured to determine a candidate peak value in each sub-window (P i, P i+1,...) and to set the peak amplitude based on valid candidate peak values of one or more consecutive sub-windows (P i, P i+1,...), wherein the valid candidate peak values are candidate peak values in valid sub-windows, and wherein a sub-window is considered valid, if this sub-window is not discarded due to being close to a T or QRS wave and/or not discarded due to suspicion of contamination from near-field ventricular activity. a body; a sensor arrangement arranged on the body and configured to receive a cardiac sense signal; and a processing circuitry operatively connected to the sensor arrangement, wherein the processing circuitry is configured to process the cardiac sense signal received using the sensor arrangement to detect a signal deflection in the cardiac sense signal potentially indicative of an atrial event (As) caused by atrial activity; and to start a peak detection window based on a detection of said signal deflection for determining a peak amplitude associated with said atrial event (As), wherein the peak detection window comprises one or more sub-windows (P i, P i+1,...), the processing circuitry being configured to determine a candidate peak value in each sub-window (P i, P i+1,...) and to set the peak amplitude based on valid candidate peak values of one or more consecutive sub-windows (P i, P i+1,...), wherein the valid candidate peak values are candidate peak values in valid sub-windows, and wherein a sub-window is considered valid, if this sub-window is not discarded due to being close to a T or QRS wave and/or not discarded due to suspicion of contamination from near-field ventricular activity. to detect a signal deflection in the cardiac sense signal potentially indicative of an atrial event (As) caused by atrial activity; and to start a peak detection window based on a detection of said signal deflection for determining a peak amplitude associated with said atrial event (As), wherein the peak detection window comprises one or more sub-windows (P i, P i+1,...), the processing circuitry being configured to determine a candidate peak value in each sub-window (P i, P i+1,...) and to set the peak amplitude based on valid candidate peak values of one or more consecutive sub-windows (P i, P i+1,...), wherein the valid candidate peak values are candidate peak values in valid sub-windows, and wherein a sub-window is considered valid, if this sub-window is not discarded due to being close to a T or QRS wave and/or not discarded due to suspicion of contamination from near-field ventricular activity.