打印

计步算法部分分享

[复制链接]
698|2
手机看帖
扫描二维码
随时随地手机跟帖
沙发
foliages|  楼主 | 2024-2-2 16:25 | 只看该作者
C:\Users\su\Desktop

使用特权

评论回复
板凳
foliages|  楼主 | 2024-2-2 16:26 | 只看该作者
float get_distance_data(int16_t extra_steps, int16_t nstep)
{
    int16_t data_size = PROCESS_BUF_SIZE;
    int16_t peak_step_size = g_peak_save_index;
    float real_dis = 0;
    int32_t dis_ans = 0;
    int32_t steplen = 0;
    int32_t steplen_height = 0;
    int16_t from = 0;
    int16_t i = 0, j = 0;
    int32_t avg_steplen = 0;
    int32_t avg_steplen_count = 0;

    //模型的特征值
    int32_t diff_min_max, step_hz, sex;
    int32_t dt, amean_dt, amean_dt_dt, diffminmax_amean, x_y_z;
    int64_t duringtime;
    int32_t step_hz_count;
    struct CHARACT calcans;
    dis_ans = 0;
    for (i = 1; i < peak_step_size; i++) {
        if (0 == g_step_save[i])
            continue;
        from = i - 1;

        step_hz = g_step_freq_save[i];
        step_hz_count = 1;
        for (j = i - 1; j >= 0 && j >= i - nstep; j--) {
            from = j;
            if (0 == g_step_save[j]){
                break;
            } else{
                step_hz += g_step_freq_save[j];
                step_hz_count++;
            }
        }

        step_hz /= step_hz_count ;
        
        if(g_peak_save[from] > g_peak_save[i] || g_peak_save[from] < 0
            || g_peak_save[i] >= data_size) {
            continue;
        }

        calcans = calc_charact(g_data_compose, data_size , g_peak_save[from] , g_peak_save[i]);

        //height = ((g_hight_cm*ZOOMSIZE - PLAN_MEAN_HEIGHT)*ZOOMSIZE) / PLAN_SD_HEIGHT;
        diff_min_max =((calcans.diff_min_max - PLAN_MEAN_DIFF_MIN_MAX) * ZOOMSIZE) / PLAN_SD_DIFF_MIN_MAX;
        step_hz = ((step_hz - PLAN_MEAN_STEP_HZ) * ZOOMSIZE) / PLAN_SD_STEP_HZ;
        sex = g_isfemale;
        //amean = ((calcans.amean - PLAN_MEAN_AMEAN)*ZOOMSIZE)/PLAN_SD_AMEAN;
        //fat_factor = ((g_weight_kg*10000)/(g_hight_cm*g_hight_cm))*ZOOMSIZE;
        //fat_factor = ((fat_factor - PLAN_MEAN_FAT_FACTOR)*ZOOMSIZE)/PLAN_SD_FAT_FACTOR;
        
        duringtime = (g_data_timestamp[g_peak_save[i]] - g_data_timestamp[g_peak_save[from]]) / step_hz_count;
        dt = (int32_t)duringtime;
        amean_dt = (calcans.amean * dt) / 1000;
        amean_dt_dt = (amean_dt * dt) / 1000;
        //amean_diffminmax = (calcans.amean*ZOOMSIZE)/calcans.diff_min_max;
        diffminmax_amean = (calcans.diff_min_max * ZOOMSIZE) / calcans.amean;
        dt = (dt - PLAN_MEAN_DT) * ZOOMSIZE / PLAN_SD_DT;
        amean_dt = (amean_dt - PLAN_MEAN_AMEAN_DT) * ZOOMSIZE / PLAN_SD_AMEAN_DT;
        amean_dt_dt = (amean_dt_dt - PLAN_MEAN_AMEAN_DT_DT) * ZOOMSIZE/PLAN_SD_AMEAN_DT_DT;
        //amean_diffminmax = (amean_diffminmax - PLAN_MEAN_AMEAN_DIFFMINMAX) * ZOOMSIZE/PLAN_SD_AMEAN_DIFFMINMAX;
        diffminmax_amean = (diffminmax_amean - PLAN_MEAN_DIFFMINMAX_AMEAN) * ZOOMSIZE/PLAN_SD_DIFFMINMAX_AMEAN;
        //r_xyz = (calcans.r_xyz - PLAN_MEAN_R_XYZ) * ZOOMSIZE/PLAN_SD_R_XYZ;
        x_y_z = (calcans.x_y_z - PLAN_MEAN_X_Y_Z) * ZOOMSIZE / PLAN_SD_X_Y_Z;
        
        steplen_height = K_INTERCEPT
            //+ K_HEIGHT * height
            + K_DIFF_MIN_MAX * diff_min_max
            + K_STEP_HZ * step_hz
            //+ K_AMEAN * amean
            + K_SEX * sex
            //+ K_FAT_FACTOR * fat_factor
            + K_DT * dt
            + K_AMEAN_DT * amean_dt
            + K_AMEAN_DT_DT * amean_dt_dt
           // + K_AMEAN_DIFFMINMAX * amean_diffminmax
            + K_DIFFMINMAX_AMEAN * diffminmax_amean
           // + K_R_XYZ * r_xyz
            + K_X_Y_Z * x_y_z;
        steplen = (steplen_height * g_hight_cm) / 100;
        dis_ans += steplen * g_step_save[i];
        avg_steplen_count++;
        avg_steplen += steplen;

#ifdef TEST_TOOL
        acum_step_count++;
        acum_step_len_sum += (double)steplen / (double)(ZOOMSIZE * ZOOMSIZE);
        acum_step_len = (double)acum_step_len_sum / (double)acum_step_count;
#endif
    }
   
    if (avg_steplen_count > 0) {
        s_avg_steplen = avg_steplen / avg_steplen_count;
    }
    dis_ans += s_avg_steplen * extra_steps;
    real_dis =((float)dis_ans) / (ZOOMSIZE * ZOOMSIZE);
    return real_dis;
}

9274965bca689169d6.png (198.56 KB )

9274965bca689169d6.png

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

12

主题

87

帖子

2

粉丝