A time–frequency contrastive learning model for anomaly detection in multivariate time series

Wěi Zhāng, Xin Li, Huijuan Li, Jian Ma, Kong Pengfei, Shuo Zhang, Ying LiuComplex 2025 · DOI

Abstract

Anomaly detection in multivariate time series is critical for applications such as industrial maintenance, early warning systems, and environmental monitoring. However, existing reconstruction-based models often exhibit poor generalization and high false-negative rates, limiting their effectiveness. To address these challenges, this paper proposes a time–frequency contrastive learning (TFCL) anomaly detection model that integrates a contrastive learning module with a gated feature fusion module. The contrastive learning module employs a time-weighted and temperature-controlled loss function to enhance feature representation from both time and frequency perspectives. Meanwhile, the feature fusion module utilizes a gating mechanism to dynamically adjust the integration of time and frequency features, generating robust joint representations. Additionally, a latent-feature-driven and component-weighted anomaly discrimination strategy is proposed, leveraging reconstruction residuals and feature importance to precisely identify anomalies. The model’s performance was evaluated on publicly available datasets (SWaT and WADI) and real-world air quality monitoring data (AQMD). Experimental results demonstrate that TFCL achieves an average F1 score of 92.47% on SWaT and WADI, outperforming state-of-the-art methods and demonstrating good generalization.

Introduction: The Challenge of Multivariate Anomaly Detection

Detecting anomalies in multivariate time series (MTS)—such as sensor data from power plants or water treatment facilities—is a complex task. Most current reconstruction-based models, like Autoencoders or Transformers, attempt to learn the "normal" pattern of data and flag deviations that they cannot reconstruct accurately as anomalies.

Example of a multivariate time series anomaly (shaded in pink) in the DPIT301 sensor.

However, these models face two major hurdles. First, they often suffer from "domain myopia," focusing predominantly on the time domain while ignoring frequency-domain spectral patterns that could reveal hidden irregularities. Second, they frequently exhibit high false-negative rates because their detection criteria—usually simple reconstruction error—are too simplistic to capture complex, multi-dimensional deviations.

The TFCL Methodology

The proposed Time–Frequency Contrastive Learning (TFCL) model addresses these limitations through three innovative pillars:

1. Dual-Domain Contrastive Learning

The model employs two separate encoders: a Transformer-based encoder for temporal dependencies and an FFT-based (Fast Fourier Transform) encoder for spectral features. A contrastive loss function forces the model to align these representations, ensuring that time and frequency views of the same moment are recognized as similar, while distinct moments remain differentiated.

2. Gated Feature Fusion

Rather than simply concatenating time and frequency features, TFCL uses a gated feature fusion module. This mechanism employs a learnable Sigmoid-based gate to dynamically decide the relative importance of each domain for a given data point, generating a more robust joint representation.

The Gated Feature Fusion module dynamically integrates time and frequency domain features using learnable weights.

3. Latent-Feature-Driven Scoring

Standard models calculate anomaly scores based solely on the raw reconstruction residual ($X - \hat{X}$). TFCL refines this by weighting the residual with the "importance" of features in the latent space ($Z$). This allows the model to focus on the most relevant sensor dimensions, preventing noise in less critical sensors from masking real issues or triggering false alarms.

Experimental Evaluation and Results

The model was evaluated on three major datasets: SWaT (Secure Water Treatment), WADI (Water Distribution), and AQMD (Air Quality Monitoring Data). TFCL outperformed several state-of-the-art models, including Adformer and U-Transformer.

  • High Accuracy: The model achieved an F1 score of 92.50% on SWaT and 92.44% on WADI.
  • Reduced False Negatives: On the WADI dataset, TFCL’s False Negative Rate (FNR) was approximately 9.6%, a significant improvement over competing models like AT-DCAEP, which exceeded 30%.
  • Real-World Reliability: In the AQMD case study, the model achieved a 0% False Negative Rate across eight types of sensor anomalies, demonstrating its practical utility for mission-critical environmental monitoring.

Conclusion

By integrating contrastive learning with a gated fusion mechanism and a latent-feature-weighted scoring strategy, TFCL significantly improves the sensitivity and generalization of anomaly detection in multivariate time series. While the model shows a slightly higher False Positive Rate in some scenarios, its ability to drastically reduce missed detections makes it a robust choice for industrial and environmental safety applications. Future research will explore the universality of the model across diverse industrial systems without extensive retraining.

Summary updated

Abstract

Anomaly detection in multivariate time series is critical for applications such as industrial maintenance, early warning systems, and environmental monitoring. However, existing reconstruction-based models often exhibit poor generalization and high false-negative rates, limiting their effectiveness. To address these challenges, this paper proposes a time–frequency contrastive learning (TFCL) anomaly detection model that integrates a contrastive learning module with a gated feature fusion module. The contrastive learning module employs a time-weighted and temperature-controlled loss function to enhance feature representation from both time and frequency perspectives. Meanwhile, the feature fusion module utilizes a gating mechanism to dynamically adjust the integration of time and frequency features, generating robust joint representations. Additionally, a latent-feature-driven and component-weighted anomaly discrimination strategy is proposed, leveraging reconstruction residuals and feature importance to precisely identify anomalies. The model’s performance was evaluated on publicly available datasets (SWaT and WADI) and real-world air quality monitoring data (AQMD). Experimental results demonstrate that TFCL achieves an average F1 score of 92.47% on SWaT and WADI, outperforming state-of-the-art methods and demonstrating good generalization. Moreover, the proposed TFCL achieves accurate anomaly detection in AQMD, which highlights its practical value in real-world scenarios.
BibTeX
@inproceedings{zhang2025timefrequency,
  author = {Wěi Zhāng and Xin Li and Huijuan Li and Jian Ma and Kong Pengfei and Shuo Zhang and Ying Liu},
  title = {{A time–frequency contrastive learning model for anomaly detection in multivariate time series}},
  booktitle = {Complex},
  year = {2025},
  doi = {10.1007/s40747-025-02119-w},
}
Figure