Function to calculate ems