In this paper, we address the problem of joint optimal threshold-based relaying and maximum likelihood (ML) detection in network-coded cooperative systems. The purpose of using threshold-based relaying is to circumvent the impact of error propagation, which could lead to degrading the system diversity. For simplicity, we consider a simple network comprising two source nodes and one relay node. The relay operates in the decode-and-forward (DF) mode and employs binary network coding. The communication between the two source nodes is bidirectional, resulting in a two-way relay channel. We assume binary phase shift keying (BPSK) signaling. For a given log-likelihood ratio (LLR)-based threshold used at the relay, we derive the ML detector at the...