Skip to content

crashmetrics.correlation

correlation

Test-versus-CAE correlation: ISO/TS 18571, CC rating and error measures.

Rate how well a computed signal (usually CAE) matches a reference signal (usually a physical test) with one number between 0 and 1, and its sub-scores.

Functions:

  • iso18571: ISO/TS 18571:2024 objective rating (corridor, phase, magnitude, slope) and its grade (excellent, good, fair, poor).
  • cc_rating: Corridor and cross-correlation (CC) rating: a corridor score plus phase, size and shape from the cross-correlation.
  • error_measures: RMSE, normalised RMSE, peak and peak-time errors, correlation coefficient, Sprague & Geers and Russell errors.
  • compare: All three at once; flatten turns the result into columns for a feature table.
  • resample_pair: Put two signals on one uniform time grid over their common interval.

Conventions:

  • reference is the signal you trust (the test), comparison the one being rated (CAE). The ratings are not symmetric: corridors are sized from the reference.
  • Signals may have different time bases; they are linearly resampled to dt (default 0.1 ms, the 10 kHz that ISO/TS 18571 assumes) over the common interval, or over t_start to t_end.
  • Filter both signals the same way (same CFC) before rating them.
  • A positive time shift means the comparison signal is late.

ISO18571Parameters dataclass

ISO18571Parameters(
    a0: float = 0.05,
    b0: float = 0.5,
    k_z: float = 2.0,
    max_shift: float = 0.2,
    k_p: float = 1.0,
    max_magnitude_error: float = 0.5,
    k_m: float = 1.0,
    max_slope_error: float = 2.0,
    k_s: float = 1.0,
    dtw_window: float = 0.1,
    w_z: float = 0.4,
    w_p: float = 0.2,
    w_m: float = 0.2,
    w_s: float = 0.2,
)

Parameters of ISO/TS 18571; the defaults are the standard's values. Change them only for studies of the metric itself.

a0 class-attribute instance-attribute

a0: float = 0.05

Inner corridor half width, fraction of the reference's absolute maximum.

b0 class-attribute instance-attribute

b0: float = 0.5

Outer corridor half width, fraction of the absolute maximum.

k_z class-attribute instance-attribute

k_z: float = 2.0

Corridor exponent.

max_shift class-attribute instance-attribute

max_shift: float = 0.2

Maximum allowable time shift, fraction of the interval (eps_P*).

k_p class-attribute instance-attribute

k_p: float = 1.0

Phase exponent.

max_magnitude_error class-attribute instance-attribute

max_magnitude_error: float = 0.5

Maximum allowable magnitude error (eps_M*).

k_m class-attribute instance-attribute

k_m: float = 1.0

Magnitude exponent.

max_slope_error class-attribute instance-attribute

max_slope_error: float = 2.0

Maximum allowable slope error (eps_S*).

k_s class-attribute instance-attribute

k_s: float = 1.0

Slope exponent.

dtw_window class-attribute instance-attribute

dtw_window: float = 0.1

Dynamic time warping window, fraction of the signal length (ISO/TS 18571:2024).

w_z class-attribute instance-attribute

w_z: float = 0.4

Weight of the corridor score.

w_p class-attribute instance-attribute

w_p: float = 0.2

Weight of the phase score.

w_m class-attribute instance-attribute

w_m: float = 0.2

Weight of the magnitude score.

w_s class-attribute instance-attribute

w_s: float = 0.2

Weight of the slope score.

ISO18571Result dataclass

ISO18571Result(
    rating: float,
    grade: str,
    corridor: float,
    phase: float,
    magnitude: float,
    slope: float,
    time_shift_ms: float,
    correlation: float,
    magnitude_error: float,
    slope_error: float,
    t_start: float,
    t_end: float,
    n_points: int,
)

ISO/TS 18571 rating of a comparison signal against a reference.

rating instance-attribute

rating: float

Overall rating R, 0 to 1.

grade instance-attribute

grade: str

"excellent" (R > 0.94), "good" (> 0.80), "fair" (> 0.58) or "poor".

corridor instance-attribute

corridor: float

Corridor score Z.

phase instance-attribute

phase: float

Phase score E_P.

magnitude instance-attribute

magnitude: float

Magnitude score E_M.

slope instance-attribute

slope: float

Slope score E_S.

time_shift_ms instance-attribute

time_shift_ms: float

Time shift with the highest correlation, ms (positive: the comparison is late).

correlation instance-attribute

correlation: float

Pearson correlation at that shift.

magnitude_error instance-attribute

magnitude_error: float

Magnitude error after the shift and time warping.

slope_error instance-attribute

slope_error: float

Slope error after the shift.

t_start instance-attribute

t_start: float

Start of the interval of evaluation, s.

t_end instance-attribute

t_end: float

End of the interval of evaluation, s.

n_points instance-attribute

n_points: int

Number of samples in the interval.

CCParameters dataclass

CCParameters(
    a0: float = 0.05,
    b0: float = 0.5,
    k_z: float = 2.0,
    int_min: float = 0.8,
    d_min: float = 0.01,
    d_max: float = 0.12,
    k_v: float = 1.0,
    k_g: float = 1.0,
    k_p: float = 1.0,
    w_phase: float = 1 / 3,
    w_size: float = 1 / 3,
    w_shape: float = 1 / 3,
    w_corridor: float = 0.5,
    w_cross: float = 0.5,
    norm: float | None = None,
)

Parameters of the corridor and cross-correlation rating.

The defaults are the values commonly cited for the published method (Gehre, Gades and Wernicke, ESV 2009). If your project compares results with another implementation, check its settings and set these to match. Names in parentheses are the parameter names commonly used for this method.

a0 class-attribute instance-attribute

a0: float = 0.05

Inner corridor half width, fraction of the norm (A_0).

b0 class-attribute instance-attribute

b0: float = 0.5

Outer corridor half width (B_0).

k_z class-attribute instance-attribute

k_z: float = 2.0

Corridor exponent (K).

int_min class-attribute instance-attribute

int_min: float = 0.8

Minimum overlap of the shifted signals, fraction of the interval (INT_MIN); the largest shift is 1 - int_min.

d_min class-attribute instance-attribute

d_min: float = 0.01

Time shift with full phase points, fraction of the interval (D_MIN).

d_max class-attribute instance-attribute

d_max: float = 0.12

Time shift with zero phase points (D_MAX).

k_v class-attribute instance-attribute

k_v: float = 1.0

Phase exponent (K_V).

k_g class-attribute instance-attribute

k_g: float = 1.0

Size exponent (K_G).

k_p class-attribute instance-attribute

k_p: float = 1.0

Shape (progression) exponent (K_P).

w_phase class-attribute instance-attribute

w_phase: float = 1 / 3

Weight of the phase rating in the cross-correlation rating (G_V).

w_size class-attribute instance-attribute

w_size: float = 1 / 3

Weight of the size rating (G_G).

w_shape class-attribute instance-attribute

w_shape: float = 1 / 3

Weight of the shape rating (G_P).

w_corridor class-attribute instance-attribute

w_corridor: float = 0.5

Weight of the corridor rating in the total (G_1).

w_cross class-attribute instance-attribute

w_cross: float = 0.5

Weight of the cross-correlation rating in the total (G_2).

norm class-attribute instance-attribute

norm: float | None = None

Corridor norm; default the reference's absolute maximum. Set it for small signals (for example a minimum displacement) so tiny absolute differences are not penalised.

CCResult dataclass

CCResult(
    rating: float,
    corridor: float,
    cross_correlation: float,
    phase: float,
    size: float,
    shape: float,
    time_shift_ms: float,
    correlation: float,
    t_start: float,
    t_end: float,
)

Corridor and cross-correlation rating of a comparison signal against a reference.

rating instance-attribute

rating: float

Total rating, 0 to 1.

corridor instance-attribute

corridor: float

Corridor rating.

cross_correlation instance-attribute

cross_correlation: float

Cross-correlation rating (weighted phase, size and shape).

phase instance-attribute

phase: float

Phase (time shift) rating.

size instance-attribute

size: float

Size rating: ratio of the smaller to the larger signal energy.

shape instance-attribute

shape: float

Shape (progression) rating: the cross-correlation at the best shift.

time_shift_ms instance-attribute

time_shift_ms: float

Time shift with the highest cross-correlation, ms (positive: the comparison is late).

correlation instance-attribute

correlation: float

Normalised cross-correlation at that shift.

t_start instance-attribute

t_start: float

Start of the interval of evaluation, s.

t_end instance-attribute

t_end: float

End of the interval of evaluation, s.

ErrorMeasures dataclass

ErrorMeasures(
    rmse: float,
    nrmse: float,
    mae: float,
    max_error: float,
    peak_reference: float,
    peak_comparison: float,
    peak_error: float,
    peak_time_error_ms: float,
    correlation: float,
    r_squared: float,
    sprague_geers_magnitude: float,
    sprague_geers_phase: float,
    sprague_geers_comprehensive: float,
    russell_magnitude: float,
    russell_phase: float,
    russell_comprehensive: float,
)

Classic error measures between a reference and a comparison.

rmse instance-attribute

rmse: float

Root mean square error, unit of the signals.

nrmse instance-attribute

nrmse: float

RMSE divided by the reference's absolute maximum.

mae instance-attribute

mae: float

Mean absolute error.

max_error instance-attribute

max_error: float

Largest absolute difference.

peak_reference instance-attribute

peak_reference: float

Reference value at its largest magnitude (signed).

peak_comparison instance-attribute

peak_comparison: float

Comparison value at its largest magnitude (signed).

peak_error instance-attribute

peak_error: float

(|peak comparison| - |peak reference|) / |peak reference|: +0.10 means the comparison peaks 10 % higher.

peak_time_error_ms instance-attribute

peak_time_error_ms: float

Time of the comparison's peak minus the reference's, ms.

correlation instance-attribute

correlation: float

Pearson correlation coefficient (no shift).

r_squared instance-attribute

r_squared: float

Coefficient of determination of the comparison as a prediction of the reference, 1 - SS_res / SS_tot (can be negative).

sprague_geers_magnitude instance-attribute

sprague_geers_magnitude: float

Sprague & Geers magnitude error M (0 for equal energy).

sprague_geers_phase instance-attribute

sprague_geers_phase: float

Sprague & Geers phase error P, 0 to 1.

sprague_geers_comprehensive instance-attribute

sprague_geers_comprehensive: float

Sprague & Geers comprehensive error C = sqrt(M^2 + P^2).

russell_magnitude instance-attribute

russell_magnitude: float

Russell magnitude error RM.

russell_phase instance-attribute

russell_phase: float

Russell phase error RP (the same as Sprague & Geers P).

russell_comprehensive instance-attribute

russell_comprehensive: float

Russell comprehensive error RC = sqrt(pi/4 (RM^2 + RP^2)).

Comparison dataclass

Comparison(
    iso: ISO18571Result,
    cc: CCResult,
    errors: ErrorMeasures,
    channel: str = "",
)

iso18571, cc_rating and error_measures of one signal pair.

channel class-attribute instance-attribute

channel: str = field(default='')

Optional channel name.

summary

summary() -> str

One line per method, for reports and logs.

resample_pair

resample_pair(
    time: ArrayLike,
    reference: ArrayLike,
    comparison: ArrayLike,
    comparison_time: ArrayLike | None = None,
    t_start: float | None = None,
    t_end: float | None = None,
    dt: float = 0.0001,
) -> tuple[Array, Array, Array]

Return both signals on one uniform time grid.

Parameters:

Name Type Description Default
time ArrayLike

Time of the reference signal, s.

required
reference ArrayLike

The two signals.

required
comparison ArrayLike

The two signals.

required
comparison_time ArrayLike | None

Time of the comparison signal, s, if it differs from time.

None
t_start float | None

Interval of evaluation, s. Default: the interval both signals cover.

None
t_end float | None

Interval of evaluation, s. Default: the interval both signals cover.

None
dt float

Time step of the common grid, s (default 0.1 ms = 10 kHz).

0.0001

Returns:

Type Description
(t, reference, comparison)

The grid from t_start in steps of dt up to t_end, and both signals linearly interpolated onto it.

iso18571_grade

iso18571_grade(rating: float) -> str

Return the ISO/TS 18571 grade of an overall rating: excellent (R > 0.94), good (0.80 < R <= 0.94), fair (0.58 < R <= 0.80) or poor (R <= 0.58).

iso18571

iso18571(
    time: ArrayLike,
    reference: ArrayLike,
    comparison: ArrayLike,
    comparison_time: ArrayLike | None = None,
    t_start: float | None = None,
    t_end: float | None = None,
    dt: float = 0.0001,
    parameters: ISO18571Parameters | None = None,
) -> ISO18571Result

Return the ISO/TS 18571 objective rating of two signals.

Parameters:

Name Type Description Default
time ArrayLike

Time of the reference signal, s.

required
reference ArrayLike

Reference signal (usually the test), any unit.

required
comparison ArrayLike

Signal to rate (usually CAE), same unit.

required
comparison_time ArrayLike | None

Time of the comparison signal if it differs from time.

None
t_start float | None

Interval of evaluation, s. Default: the interval both signals cover. Choose it to contain the event and little else: long quiet tails raise the corridor score.

None
t_end float | None

Interval of evaluation, s. Default: the interval both signals cover. Choose it to contain the event and little else: long quiet tails raise the corridor score.

None
dt float

Time step the signals are resampled to (default 0.1 ms, the 10 kHz the standard assumes).

0.0001
parameters ISO18571Parameters | None

ISO18571Parameters; the default is the standard's values.

None

Returns:

Type Description
ISO18571Result
Notes

The procedure follows ISO/TS 18571:2024:

  1. Corridor Z: inner and outer corridors of half width a0 and b0 times the reference's absolute maximum; each sample scores 1 inside the inner corridor, 0 outside the outer one and ((outer - d) / (outer - inner))^k_z between; Z is the average.
  2. Phase E_P: the comparison is shifted sample by sample, up to max_shift of the interval, and the shift with the highest Pearson correlation is kept (the smallest one on a tie). E_P falls linearly from 1 at no shift to 0 at max_shift.
  3. Magnitude E_M: the shifted signals are aligned with dynamic time warping (squared-difference cost, window 10 % of the length); the error is sum|C - T| / sum|T| and E_M falls linearly from 1 at no error to 0 at 0.5.
  4. Slope E_S: central-difference derivatives of the shifted signals, smoothed with a nine-point moving average; the error is sum|C' - T'| / sum|T'| and E_S falls linearly to 0 at 2.0.
  5. Rating R = 0.4 Z + 0.2 E_P + 0.2 E_M + 0.2 E_S.

The 2014 edition did not specify the warping window and computed the slope differently; ratings can differ slightly from 2014-based tools.

cc_rating

cc_rating(
    time: ArrayLike,
    reference: ArrayLike,
    comparison: ArrayLike,
    comparison_time: ArrayLike | None = None,
    t_start: float | None = None,
    t_end: float | None = None,
    dt: float = 0.0001,
    parameters: CCParameters | None = None,
) -> CCResult

Return the corridor and cross-correlation (CC) rating of two signals.

Parameters:

Name Type Description Default
time ArrayLike

As for iso18571.

required
reference ArrayLike

As for iso18571.

required
comparison ArrayLike

As for iso18571.

required
comparison_time ArrayLike

As for iso18571.

required
t_start ArrayLike

As for iso18571.

required
t_end ArrayLike

As for iso18571.

required
dt ArrayLike

As for iso18571.

required
parameters CCParameters | None

CCParameters.

None

Returns:

Type Description
CCResult
Notes
  1. Corridor: the same corridor method as ISO/TS 18571, sized from norm (default the reference's absolute maximum).
  2. Cross-correlation: the comparison is shifted by up to 1 - int_min of the interval; the shift with the highest normalised cross-correlation K = sum(T C) / sqrt(sum T^2 sum C^2) over the overlap is kept.

  3. Phase: 1 for a shift up to d_min of the interval, 0 from d_max, ((d_max - d) / (d_max - d_min))^k_v between.

  4. Size: (smaller / larger)^k_g of the two signal energies sum x^2 over the shifted overlap.
  5. Shape: max(K, 0)^k_p.
  6. Cross-correlation rating: their weighted sum.
  7. Total: w_corridor * corridor + w_cross * cross.

An automatic interval of evaluation and standard-deviation corridors (offered by some tools) are not implemented: give t_start and t_end.

error_measures

error_measures(
    time: ArrayLike,
    reference: ArrayLike,
    comparison: ArrayLike,
    comparison_time: ArrayLike | None = None,
    t_start: float | None = None,
    t_end: float | None = None,
    dt: float = 0.0001,
) -> ErrorMeasures

Return classic error measures between two signals.

Arguments as for iso18571. The Sprague & Geers (2004) and Russell (1997) errors are computed from the integrals of m^2, c^2 and m c over the interval (m: reference, c: comparison); 0 is a perfect match.

compare

compare(
    time: ArrayLike,
    reference: ArrayLike,
    comparison: ArrayLike,
    comparison_time: ArrayLike | None = None,
    t_start: float | None = None,
    t_end: float | None = None,
    dt: float = 0.0001,
    channel: str = "",
    iso_parameters: ISO18571Parameters | None = None,
    cc_parameters: CCParameters | None = None,
) -> Comparison

Return the ISO/TS 18571 rating, the CC rating and the error measures of one signal pair, over the same interval.

flatten(compare(...), prefix="head_") gives columns such as head_iso.rating and head_errors.peak_error for a feature table.