Calculate detection threshold in a separate function