我需要你的帮助。我想找到sphinx3中生成的两个mfc文件的每个值之间的欧几里德距离。我的问题是我必须传递两个wav文件,例如a.wav和b.wav,其中b.wav是a.wav的子部分。我用文本格式生成了.mfc,就像这样
11.143 1.3739 -0.18189 -0.46588 0.081962 -0.053194 -0.039629 -0.19989 -0.28369 -0.41381 -0.38511 -0.25862 -0.017158
11.013 1.2289 -0.28845 -0.51773 -0.049813 -0.0025347 -0.10207 -0.23056 -0.33524 -0.27521 -0.37585 -0.36463 -0.06067
10.999 1.2356 -0.1489 -0.39382 -0.029506 0.054779 0.12997 -0.11465 -0.27684 -0.40508 -0.4854 -0.31248 -0.19142
10.977 1.235 -0.18344 -0.61799 -0.12633 -0.049641 0.039414 -0.16939 -0.1884 -0.34448 -0.27235 -0.20559 -0.23409
10.987 1.2966 -0.12835 -0.4269 -0.14144 -0.14519 -0.06445 -0.19406 -0.19799 -0.29742 -0.41959 -0.17827 -0.029767
11.035 1.4875 -0.23199 -0.51662 -0.045337 -0.024595 -0.079227 -0.20181 -0.25853 -0.43788 -0.47611 -0.33845 -0.082532
现在我想计算a.mfc和b.mfc的每个值之间的欧氏距离。这在Matlab中是可能的,但它花费了太多时间。我希望这可以用C语言完成。任何帮助将不胜感激。
谢谢。
答案 0 :(得分:2)
你的问题并不是特别好。 AFAIK mfc文件包含具有13个元素的向量。一些未经测试的代码将是:
#include <stdio.h>
#include <math.h>
#define VECSIZE 13
void readvec(char* s, float* v) {
// read one vector from s into v
char* h;
h = strtok(s, " ");
int i = 0;
while (h != NULL && i < VECSIZE) {
v[i++] = atof(h);
h = strtok(NULL, " ");
}
while (i < VECSIZE)
v[i++] = .0;
}
bool compareFiles() {
FILE* a = fopen("a.wav", "r");
FILE* b = fopen("b.wav", "r");
FILE* res = fopen("res.wav", "w"); // results file
if (a == NULL || b == NULL || res == NULL)
return false;
char* sa[1024];
char* sb[1024];
float va[VECSIZE];
float vb[VECSIZE];
while (!feof(a) && !feof(b)) {
fgets(sa, 1024, a);
readvec(sa, va);
fgets(sb, 1024, b);
readvec(sb, vb);
float diff =.0;
for (int i = 0; i < VECSIZE; i++)
diff += pow(va[i] - vb[i], 2);
diff = sqrt(diff);
fprintf(res, "%f\n", diff);
}
fclose(a);
fclose(b);
fclose(res);
return true;
}