UPC · Mechatronics Engineering · Lima, Peru

Stolen water leaves an echo.

A controlled water hammer, 17 features and four machine-learning models turn 30 seconds of pressure into an explainable verdict: bypass or normal. Two programs make it possible — from the laboratory bench to the point on the street.

0 % synthetic accuracy 0 % in the field (n = 36) echo measured at 8.4 ± 0.4 ms 0 features · 4 models
IFM PN7092 · 1 kHz · 14-bit REC #0042 · BYPASS @ 3 m · 3 bar
The problem · non-revenue water

The fraud audits can't see.

A clandestine bypass is an illegal branch installed downstream of the legal connection: the customer keeps registering consumption, the branch is buried or embedded, and its hydraulic signature is masked by regular demand. Andean utilities consistently report that conventional location technologies perform poorly against this kind of theft.

The question behind this project: can a pressure wave, read by a single sensor, give away a T-junction nobody can see?
0
billion m³ of non-revenue water are lost worldwide every year.
39–50USD bn
in estimated annual financial losses for water utilities.
>0%
of non-revenue water in many Latin American utilities comes from unauthorized consumption — with illegal connections as the leading contributor.
The physics · tref = 2·Lb / a

Every T-junction answers back.
Even buried.

The principle fits in four steps — and in 8.86 milliseconds.

STEP 1 / TRIGGER

Sharp closure

A PLC-commanded solenoid valve closes in ≈ 15 ms — well below 2L/a — generating a controlled water hammer.

ΔP = ρ · a · ΔV
STEP 2 / PROPAGATION

The wave travels

The pressure front runs along the PVC SCH-40 pipe at the Korteweg–Joukowsky celerity.

a ≈ 677 m/s
STEP 3 / REFLECTION

The bypass betrays

The T-junction splits the hydraulic impedance into two parallel branches and reflects a negative rarefaction pulse.

r = (Zeq − Z)/(Zeq + Z) = −⅓
STEP 4 / CLASSIFICATION

ML decides

The echo arrives at t = 2Lb/a. 17 features (time, frequency, db4 wavelet) are extracted and an ensemble returns the verdict.

RF + SVM + XGB + LGBM
Didactic simulator 15 m line · a = 677 m/s
3.0 m
0 m 5 m 10 m 15 m valve + sensor legal user BYPASS
tref = 2·Lb/a = 8.86 ms r = −1/3 · a = 677 m/s ✓ measured in the lab: 8.4 ± 0.4 ms BYPASS · confidence 95.9 %

Illustrative model based on equations (1)–(6) of the study. Move the bypass: the echo shifts by exactly 2·Lb/a.

The platform · train in the lab → deploy in the field
Phase 1 · Laboratory

Big Brother

Bench with a 2 HP pump, Siemens S7-1200 PLC and solenoid valve. 1,200 labeled records at 5 distances.

→
Acquisition

CSV · 1 kHz

30 s window, 30,000 samples per record, 14-bit resolution.

→
Training

HydroAnalyzer

6-stage filtering, ×4–10 augmentation, 5-fold cross-validation, model ranking.

→
Export

.joblib → portable_v1

Model + scaler + features + metrics in one file. NumPy-only converter for the edge.

→
Phase 2 · Field

Little Brother

Arduino Q samples at 500 Hz, extracts the same 17 features and replies with a JSON verdict to the phone.

Phase 1 · Train — desktop application

HydroAnalyzer v4.2 · “Aurora”

Over 10,000 lines of Python that carry the raw signal all the way to the exported model, without leaving a single window. Four tabs share one model object: what you train in one, you analyze in another.

Download installer (.exe) Windows 64-bit · double-click to install
HydroAnalyzer v4.2 “Aurora” — UPC
Filtering · 6 stages
anti-spike ON
Hampel ON
IQR ON
duration OFF
manual OFF
Butterworth ON
Synthetic · 1,200 transients · 5-fold CV
Random Forest.971
SVM · RBF.962
XGBoost.969
LightGBM.966
Consensus.967
Grouped CSV · ×4–10 augmentation
d3_bypass_*.csv×240
d5_bypass_*.csv×240
d_normal_*.csv×480
75 / 25 train–test split
Feature importance · top 5 of 17
echo_Δt.21
neg_peak_amp.17
band_2–4kHz.13
db4_d3_E.11
rise_time.08
RF 0.971 SVM 0.962 Consensus 0.967 ▲ BYPASS @ 3 m ensemble_v42.joblib

Physical simulator

Generates transients with the analytic p(t) model, visualizes Signal/PSD, 2D spectrogram and 3D surface, wavelet scalograms — and predicts instantly.

6-stage filtering

Neighbor anti-spike, Hampel, IQR envelope, duration filter, manual suppression and zero-phase Butterworth. All off by default: the operator decides.

Synthetic + real

Class-balanced datasets, grouped CSV ingestion, ×4–10 augmentation (noise, jitter, scaling) and a 75/25 split with Suggest hyperparameter buttons.

4 models + ensembles

Random Forest, SVM-RBF, XGBoost and LightGBM under stratified 5-fold cross-validation. Multi-select: two loaded models become a voting ensemble.

Deep analysis

Confusion matrix, feature importance, Leave-One-Out analysis, per-fold metrics, outlier detection and removal, automatic model ranking.

Export and deploy

A single .joblib with model + scaler + feature list + metrics. The portable_v1 converter ships it as pure NumPy for the field device.

Phase 2 · Deploy — field device

Little Brother HydraDetect-AI

The lab, in a case. An Arduino Q of the Linux class runs the FastAPI backend, samples the line at 500 Hz and runs the same 17-feature extractor as the desktop: bit-exact compatibility between training and inference. The technician only needs a phone.

Try the live detector Download HydraDetect-AI Arduino App Lab project (.zip) · import & flash
HydraDetect-AI● Arduino Q connected
Analysis result
RF SVM XGB LGBM
Acquiring · 500 Hz · 30 s0 %
—
READY
Voting Ensemble · 4 models
RF—
SVM—
XGB—
LGBM—
POST /api/predict · 200 OK · 1.8 s · 30 s window @ 500 Hz

Linux at the edge

The Arduino Q runs a full Python stack on board: NumPy, SciPy, scikit-learn and PyWavelets. On-site inference, no cloud and no laptop.

500 Hz · 30 s

The same pressure sensor as the lab, read through the on-board analog interface. The full window is stored and processed locally.

Bit-exact

The extract_features routine is identical to the desktop's. Zero drift between what the model learned and what it sees in the field.

Voting consensus

RF + SVM + XGB + LGBM with soft voting. If the models disagree, the result is “inconclusive” and a retest is suggested — fraud demands certainty.

WebUI from the phone

On selecting a .joblib, /api/inspect_model instantly shows which models it contains. Big percentage, collapsible per-model detail, JSON verdict.

Field hardware

Relay, portable solenoid valve, buck converters and a battery with BMS in a sealed enclosure. It taps the line through a T and fires its own water hammer.

Validation · synthetic + laboratory + field

The numbers, unvarnished.

Results from the campaign reported in the study: 1,200 synthetic transients (75/25 split), reflection patterns measured on the Big Brother bench, and a 36-acquisition field pilot.

Table II · synthetic validation (test set)
ModelAccuracyPrecisionRecallF1
Random Forest0.9710.9650.9780.971
SVM (RBF)0.9620.9570.9680.962
Consensus0.9670.9730.9710.965
89 % in the field

The lab-trained model keeps 89 % accuracy when transferred to the Little Brother (36 acquisitions, 500 Hz, higher noise floor).

LAB → FIELD TRANSFER
8.4 ± 0.4 ≈ 8.86 ms

Measured echo vs. Joukowsky-impedance theory for a bypass at 3 m. Relative amplitude 0.31 ± 0.04 against the predicted r = −1/3. The physics, confirmed.

n = 20 ACQUISITIONS · BIG BROTHER
explainable > opaque

A 1-D CNN baseline reached 91.5 % — but demanded ~10× more data and non-interpretable decisions. In fraud cases, explainability wins: the RF + SVM consensus is the operational classifier.

VS DEEP LEARNING
Downloads

Take them with you.

Two files, one methodology. Train with one, detect with the other.

Phase 1 · Desktop

HydroAnalyzer

v4.2 “Aurora” · PyQt5 · ~10,000 lines

Simulation, 6-stage filtering, synthetic and real training, 4 models with cross-validation, full analysis and .joblib export. Distributed as a Windows installer (.exe).

instalador.exe
Windows 10/11 · 64-bitinstalador.exedouble-click to install
Phase 2 · Field

HydraDetect-AI

Little Brother · FastAPI · 4-model ensemble

Arduino App Lab project: assets, Python sketch, app.yaml and readme. Import it into the Arduino App Lab and flash it to the Arduino Q.

HydraDetectAI-LittleBrother-win64.zip
Arduino App Labimport project & flashworks with HydroAnalyzer models

Trouble downloading? Reach out — links are published with each release.