A System Identification Approach for Failure Diagnosis and Detection