Abstract-Codeword matching and signal aggregation (CMSA) is a recently proposed low-complexity noncoherent receiver for block-code-modulated ultrawideband impulse radio (UWB-IR) systems. As the frame/symbol duration is shortened to boost data rate, interframe interference (IFI) or intersymbol interference (ISI) occurs and degrades the detection performance of CMSA. In this paper, an effective IFI/ISI premitigation scheme is proposed for CMSA through a code optimization approach. By employing a tailored interference model that highlights the codeword properties, the system performance in the presence of moderate IFI/ISI is evaluated, and the average collected channel gain is introduced as the metric for code optimization. With the primary focus on binary modulation, the following two IFI/ISI-robust code properties are generalized: 1) shifted orthogonality and 2) shifted repetition. Based on these properties, the optimal code is constructed. It is observed that, when the optimal code occurs, the leaked signal energy or the interference can partially be used to enhance the detection performance of CMSA in the presence of IFI/ISI. Unlike most of the existing IFI/ISI mitigation schemes for noncoherent UWB-IR, which mainly focus on signal processing after the nonlinear detector, the optimized code is exploited to aggregate the leaked signal energy, along with the linear predetection operation already involved in the CMSA receiver. Both analysis and simulation show that a distinct performance improvement is achieved.Index Terms-Block code (BC) modulation, interframe interference (IFI), intersymbol interference (ISI), noncoherent, premitigation, ultrawideband impulse radio (UWB-IR).