C function for matching numeric vectors and calculating error / difference. This was used to detect difference between FFT results
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
1.4 KiB

9 years ago
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "src/vec_match.h"
9 years ago
#define DATA_LEN 11
9 years ago
static float reference[DATA_LEN] = {
0, 10, 20, 30, 40, 50, 40, 30, 20, 10, 0
};
static float data[DATA_LEN] = {
0, 10, 20, 30, 40, 50, 50, 40, 30, 30, 10
9 years ago
};
9 years ago
static float data_cprs[16] = {
0, 15.7, 0, 0, 0.1, 0.2, 0.1, 10, 24.242, 0, 0, 0.1, 0.2, 0.4, 0.5, 0
};
static float data_cprs2[16];
static float data_cprs3[16];
9 years ago
int main(void)
9 years ago
{
9 years ago
for (int i = 0; i < 16; i++) {
printf("%.1f, ", data_cprs[i]);
}
printf("\n");
int len = vec_pack(data_cprs2, 16, data_cprs, 16, 2);
printf("compressed len = %d\n", len);
for (int i = 0; i < len; i++) {
printf("%.1f, ", data_cprs2[i]);
}
printf("\n");
len = vec_unpack(data_cprs3, 16, data_cprs2, len);
printf("unpacked len = %d\n", len);
for (int i = 0; i < len; i++) {
printf("%.1f, ", data_cprs3[i]);
}
printf("\n");
9 years ago
return 0;
vec_match_cfg_t cfg = {
.length = DATA_LEN,
.drift_x = 1,
.offset_y = 5,
.abs_threshold = 0.1
};
// example
9 years ago
printf("REF: ");
for (int i = 0; i < DATA_LEN; i++) {
printf("%.0f, ", reference[i]);
}
printf("\n");
9 years ago
printf("MEAS: ");
for (int i = 0; i < DATA_LEN; i++) {
printf("%.0f, ", data[i]);
}
printf("\n");
// error metric fields
9 years ago
float env_e, abs_e;
9 years ago
bool ok = vec_match(data, reference, &cfg, &env_e, &abs_e);
9 years ago
printf("%s", ok ? "MATCH OK" : "MATCH FAILED");
printf("\n");
printf("Error rate: ENV %.2f, ABS %.2f\n", env_e, abs_e);
}