[英]Declare and define the function distance() to find the Euclidean distance between the two points (x[0], y[0]) and (x[1], y[1]) in c
[英]find euclidean distance between values in c
我需要你的幫助。 我想找到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語言完成。 任何幫助將不勝感激。
謝謝。
你的問題沒有特別好。 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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.