跳转至

代码

检测实现 — 逐模态对比 + 阈值判定

void tiny_damage_detect(const tiny_sysid_result_t *cur, tiny_damage_detect_t *out)
{
    memset(out, 0, sizeof(*out));
    if (!g_has_baseline || !cur || cur->n_modes < 1) return;

    int nm = (cur->n_modes < g_baseline.n_modes)
             ? cur->n_modes : g_baseline.n_modes;

    float fd_max = 0, ml_max = 0, dd_max = 0;

    for (int m = 0; m < nm; m++) {
        // 频率偏移百分比
        float fb = g_baseline.frequencies[m];
        float fd = 100.0f * fabsf(cur->frequencies[m] - fb) / fb;
        if (fd > fd_max) fd_max = fd;

        // MAC 损失
        float ml = 1.0f - tiny_sysid_mac(cur->shapes[m],
                      g_baseline.shapes[m], cur->n_ch);
        if (ml > ml_max) ml_max = ml;

        // 阻尼变化百分比
        float db = g_baseline.damping[m];
        float dd = 100.0f * fabsf(cur->damping[m] - db) / db;
        if (dd > dd_max) dd_max = dd;
    }

    // 阈值判定
    bool f = (fd_max > 5.0f);
    bool m = (ml_max > 0.15f);
    bool d = (dd_max > 100.0f);
    out->flags = (f ? 1 : 0) | (m ? 2 : 0) | (d ? 4 : 0);

    // 综合损伤指数
    float di = (fd_max/15.0f + ml_max/0.30f + dd_max/300.0f) / 3.0f;
    out->index = (di > 1.0f) ? 1.0f : di;

    // 最终判定:指数 > 0.5 或 >= 2 指标超标
    out->damaged = (out->flags >= 2) || (out->index > 0.5f);
}

关键逻辑

  • 对每个模态独立计算三个指标,取最大变化量
  • 损伤指数用归一化加权平均,分母是各指标的严重阈值
  • flags 位掩码便于快速判断哪些指标超标