Abstract-This study aimed at developing an adaptive algorithm to detect in real time temporal gait events, based on data acquired from inertial and magnetic measurement units.Trials on 9 healthy subjects were performed to select the best body locations for the sensors out of 8 different possibilities, trying to optimize system portability, data intervariability and real-time algorithm simplicity. Subjects walked over the GaitRite mat at different self-selected speeds: normal, fast, and slow. Results showed a significantly low variability (p<0.05) of the shank angular velocity in the sagittal plane, reducing the number of sensors required for the real-time algorithm to two (the ones placed on the shanks).The detection of the Initial Contact (IC) and the End Contact (EC) was based on the shank angular velocity and flexion/extension angle. The gait events were identified as local minima on the sagittal-plane angular velocity. Features extracted from the signals of the previous steps were used to improve the events localization. These features were selfcalibrated at the beginning of the trial and updated every step.The algorithm was validated against the GaitRite system and was compared to two other real-time algorithms available in the literature to assess its reliability and performance. F1-scores of 0.9987 for IC and 0.9996 for EC were obtained. Our algorithm detected the gait events with a mean (SD) delay of 68.6 (15.1) ms for IC and 7.8 (23.6) ms for EC, with respect to the GaitRite, for the self-selected normal speed. These values were significantly lower than those obtained by other published algorithms.Results indicated that the system is suitable for real-time gait monitoring, assessment and ambulatory rehabilitation, based on biofeedback or neuroprostheses.