Automatic fitting procedure for the fundamental diagram