---
title: "Rail Predictive Maintenance"
description: "The DSP cores (railfeatures, railposition) are host-unit-tested on nativesim/native/64; the full app runs end-to-end on nativesim with a canned NMEA track + synthetic vibration. No model ships (deterministic fallback). HiL on a real bogie with a customer-trained model is bench-gated."
source: https://docs.alplab.ai/sdk/examples/rail-predictive-maintenance
---

# `rail-predictive-maintenance`

:::warning[`[UNTESTED]` — v0.6 paper-correct]
The DSP cores (`rail_features`, `rail_position`) are host-unit-tested on `native_sim/native/64`; the full app runs end-to-end on native_sim with a canned NMEA track + synthetic vibration. No model ships (deterministic fallback). HiL on a real bogie with a customer-trained model is bench-gated.
:::

Train-mounted **rail-condition survey**: read axlebox/carbody vibration from the on-board ICM-42670, extract DSP features, classify the rail defect, and **geotag** each verdict to a track position (GNSS lat/lon + along-track chainage). One CSV record per 25 m segment, ready for the customer's GIS / MQTT gateway.

Source: [`examples/ai/rail-predictive-maintenance/`](https://github.com/alplabai/alp-sdk/tree/main/examples/ai/rail-predictive-maintenance).

This monitors the **rail (infrastructure)**, complementing [`ai-anomaly-detection-vibration`](https://docs.alplab.ai/sdk/examples/ai-anomaly-detection-vibration), which monitors a stationary asset (motor/pump bearing). Wheel-side defects (wheel flats) are out of scope. The speed-normalised wavelength `λ = v / f` makes corrugation detection speed-invariant.

## Pipeline

```
ICM-42670 (I2C) --window--> rail_features (RMS, crest, kurtosis, 8 FFT
  bands, dom-freq, rail wavelength = speed/freq) --feature vector-->
  <alp/inference.h> classifier (deterministic fallback if no model)
NEO-M9N GNSS (UART NMEA) --> rail_position (haversine chainage + segments)
  --> CSV record per segment
```

The spectral and statistical maths live in [`<alp/dsp.h>`](https://docs.alplab.ai/sdk/api/dsp), not in hand-rolled app code. `rail_features.c` opens a one-stage FFT chain and reduces windows with the library:

```c
alp_dsp_stage_t stages[] = {
    { .kind  = ALP_DSP_STAGE_FFT,
      .u.fft = { .n_points      = RAIL_WINDOW_N,
                 .output_format = ALP_DSP_FFT_OUTPUT_MAGNITUDE } },
};
alp_dsp_chain_t *chain = alp_dsp_chain_open(stages, 1u);
alp_dsp_chain_apply_bins(chain, samp_q15, RAIL_WINDOW_N, mag, RAIL_WINDOW_N, &got);
alp_dsp_chain_close(chain);
```

`alp_dsp_stats_f32()` supplies the RMS / peak reductions. The backend runs CMSIS-DSP `arm_rfft_fast_f32` (Helium-vectorised) on the M55 and portable C under `native_sim` — the app never names an `arm_*` symbol.

| Class | Signature |
|-------|-----------|
| `HEALTHY` | baseline |
| `CORRUGATION` | periodic rail roughness (narrowband, stable wavelength) |
| `JOINT_WELD` | impulsive transient (high crest + kurtosis) |
| `ROUGH_RCF` | broadband roughness / rolling-contact fatigue |

## `board.yaml`

```yaml
libraries:
  - name: tflite-micro
    cores: [m55_hp]
  - name: cmsis-dsp
    cores: [m55_hp]

som:
  sku: E1M-AEN801

preset: e1m-evk
supported_boards:
  - e1m-evk
  - e1m-x-evk

pins:
  - { e1m: E1M_I2C0, macro: EVK_I2C_BUS_SENSORS, doc: "ICM-42670 accelerometer bus" }
  - { e1m: E1M_UART1, macro: EVK_UART_PORT_ARDUINO, doc: "NEO-M9N GNSS NMEA (Arduino-header UART)" }

cores:
  a32_cluster:
    os: "off"
  m55_hp:
    app: ./src
    inference:
      default_arena_kib: 64
    peripherals:
      - i2c                   # ICM-42670 link.
      - uart                  # NEO-M9N GNSS NMEA link.

chips:
  - icm42670                  # 6-axis IMU; accel only.
  - ublox_neo_m9n             # Multi-constellation GNSS.

diagnostics:
  log_level: info
```

A `som.sku` flip to `E1M-V2M101` does not reach the DEEPX DX-M1: the DX-M1 is an A55 / Linux-only backend, and `E1M-V2M101` has only `a55_cluster` and `m33_sm` (no `m55_hp`). An M33 build gets the TFLM CPU kernels; a DX-M1 path needs an A55 / Yocto app.

## Expected output

```
# RAIL,chainage_m,lat,lon,speed_mps,class,severity,dom_freq_hz,rail_wavelength_m,fix
RAIL,100.0,59.334591,18.062400,6.2,CORRUGATION,0.81,120.0,0.0517,1
```

## See also

- [`<alp/inference.h>`](https://docs.alplab.ai/sdk/api/inference) · [`<alp/dsp.h>`](https://docs.alplab.ai/sdk/api/dsp) · [`<alp/chips.h>`](https://docs.alplab.ai/sdk/chips)
- [`ai-anomaly-detection-vibration`](https://docs.alplab.ai/sdk/examples/ai-anomaly-detection-vibration) — stationary-asset counterpart
- [Examples overview](https://docs.alplab.ai/sdk/examples/overview)
