• 大小: 8KB
    文件类型: .c
    金币: 1
    下载: 0 次
    发布日期: 2021-05-10
  • 语言: 其他
  • 标签: DTW  C  源码  

资源简介

DTW算法的C源码,希望对研究语音识别算法的各位有帮助。

资源截图

代码片段和文件信息

#include    
#include    
#include    
  
#define VERY_BIG  (1e30)   
  
/* dtw.c */  
/* VERSION 2.0 Andrew Slater 20/8/1999 */  
/* Latest changes 3/2006 by John Coleman */  
  
/* DEscriptION */  
/* Compute a distance matrix on 2 multi-parameter vectors from 2 utterances 
   and perform dynamic time warping on the distance matrix */  
  
/* INPUT: */  
/* Two ASCII parameter files of the format: 
 
   filex: 
 
   X1a   X1b ... X1n 
   X2a   X2b ... X2n 
   ... 
 
   filey: 
 
   Y1a   Y1b ... Y1n 
   Y2a   Y2b ... Y2n 
   ... 
 
where a b ... n are parameters (e.g. f0 tongue-tip x co-ordinate) 
      1 ... n is a time series 
      X and Y are 2 utterances 
 
Distance is calculated as: 
 
   Dist[x1][y1] = (X1a - Y1a)^2 + (X1b - Y1b)^2 + ... + (X1n - Y1n)^2 etc. 
 
*/  
  
/* OUTPUTS: */  
/* output file: best alignment of the 2 parameter files */  
/* glob: sum of global distances useful as a similarity measure */  
  
int main(argc argv)  
int argc;  
char *argv[];  
  
{  
  
double **globdist;  
double **Dist;  
  
double top mid bot cheapest total;  
unsigned short int **move;  
unsigned short int **warp;  
unsigned short int **temp;  
  
unsigned int I X Y n i j k;  
unsigned int xsize = atoi(argv[4]);  
unsigned int ysize = atoi(argv[5]);  
unsigned int params = atoi(argv[6]);  
  
unsigned int debug; /* debug flag */  
  
float **x **y; /*now 2 dimensional*/  
  
FILE *file1 *file2 *glob *debug_file *output_file;  
  
if (argc <7 || argc > 8)  
{fprintf(stderr“Usage: dtw infile1 infile2 outfile xsize ysize params [debug_file]\n“);  
 exit(1);  
}  
  
 if (argc == 8)  
   {  
     /* open debug file */  
  
     if ((debug_file = fopen(argv[7]“wb“)) == NULL)  
       {fprintf(stderr“Cannot open debug file\n“);  
       exit(1);  
       }  
  
     debug = 1;  
   }  
  
 /* open x-parameter file */  
  
if ((file1=fopen(argv[1]“rb“))==NULL)  
{fprintf(stderr“File %s cannot be opened\n“argv[1]);  
exit(1);  
}  
  
/* open y-parameter file */  
  
if ((file2=fopen(argv[2]“rb“))==NULL)  
{fprintf(stderr“File %s cannot be opened\n“argv[2]);  
exit(1);  
}  
  
if (debug==1) fprintf(debug_file“xsize %d ysize %d params %d\n“xsizeysizeparams);  
  
/* allocate memory for x and y matrices */  
  
if ((x = malloc(xsize * sizeof(float *))) == NULL)  
     fprintf(stderr“Memory allocation error (x)\n“);  
  
for (i=0; i < xsize; i++)  
     if ((x[i] = malloc(params * sizeof(float))) == NULL)  
     fprintf(stderr“Memory allocation error (x)\n“);  
  
if ((y = malloc(ysize * sizeof(float *))) == NULL)  
     fprintf(stderr“Memory allocation error (y)\n“);  
  
for (i=0; i < ysize; i++)  
     if ((y[i] = malloc(params * sizeof(float))) == NULL)  
     fprintf(stderr“Memory allocation error (y)\n“);  
  
     /* allocate memory for Dist */  
  
if ((Dist = mallo

评论

共有 条评论