標(biāo)題: lpc語(yǔ)音識(shí)別源碼 [打印本頁(yè)]

作者: titan7149    時(shí)間: 2017-4-29 14:43
標(biāo)題: lpc語(yǔ)音識(shí)別源碼
lpc語(yǔ)音識(shí)別源碼,這是我根據(jù)趙力那本“語(yǔ)音信號(hào)處理”后面的源代碼寫的LPC美爾倒譜特征的C源代碼,基本上沒做什么修改,需要的朋友就可以不用自己再錄入了。
程序調(diào)試通過,可以直接用。
由于這段代碼是我一個(gè)程序的一部分,我轉(zhuǎn)過來可能會(huì)少一些定義什么的,所以并不是非常完整。

  1. //Calculate LPC coefficients coefficients based on autocorrelation
  2. void corref(int ip,float cor[],float alf[])

  3. {
  4. int i,j;
  5. float refi,alfsave,resid;
  6. alf[1]=(-cor[1]);
  7. alf[0]=1;
  8. resid=1-cor[1]*cor[1];
  9. for(i=2;i<=ip;i++)
  10. {
  11. refi=cor[i];
  12. for(j=1;j<i;j++)
  13. refi+=alf[j]*cor[i-j];
  14. refi/=resid;
  15. alf[i]=(-refi);
  16. for(j=1;2*j<=i;j++)
  17. {
  18. alfsave=alf[j];
  19. alf[j]=alfsave-refi*alf[i-j];
  20. if(2*j!=i)
  21. alf[i-j]-=refi*alfsave;
  22. }
  23. }
  24. }

  25. //Calculate LPC cepstrum based on alf
  26. void alfcep(int ip,float alf[],float cep[],int n)

  27. {
  28. int m,i;
  29. float ss;
  30. m=0;
  31. goto start;
  32. next:
  33. m+=1;
  34. ss=0;
  35. i=0;
  36. goto step3;
  37. step2:
  38. ss-=alf[i]*cep[m-i];
  39. step3:
  40. i+=1;
  41. if(i>ip) goto step4;
  42. if(i<m) goto step2;
  43. ss-=alf[m]*m;
  44. step4:
  45. cep[m]=ss;
  46. start:
  47. if(m<n) goto next;
  48. for(m=2;m<=n;m++)
  49. cep[m]/=m;
  50. }

  51. //Calculate mel-warped LPC cepstrum
  52. void cepmel(float cep[],float mel[])
  53. {
  54. int k,n;
  55. float u0[ORDER+2],u1[ORDER+2];
  56. float alpha=ALPHA;
  57. //Calculation mel[0]*
  58. u0[ORDER+1]=0;
  59. for(n=ORDER;n>=0;--n)
  60. u0[n]=cep[n]+alpha*u0[n+1];
  61. //mel[0]=u0[0];
  62. //Calculation mel[1]*
  63. u1[ORDER+1]=0;
  64. for(n=ORDER;n>=0;--n)
  65. u1[n]=((1-alpha*alpha)*u0[n+1]+alpha*u1[n+1]);
  66. mel[1]=u1[0];
  67. //Calculation mel[2],mel[3],......,mel[ORDER] *
  68. for(k=2;k<=ORDER;++k)
  69. {
  70. for(n=0;n<=ORDER+1;++n)
  71. u0[n]=u1[n];
  72. for(n=ORDER;n>=0;--n)
  73. u1[n]=u0[n+1]+alpha*(u1[n+1]-u0[n]);
  74. mel[k]=u1[0];
  75. }
  76. }

  77. main()
  78. {
  79. int rad[][]; //端點(diǎn)檢測(cè)后的語(yǔ)音數(shù)據(jù)
  80. float cor[ORDER+1]; //autocorrelation coefficients ORDER=14
  81. float alf[ORDER+1]; //LPC
  82. float cep[ORDER+1]; //LPC cepstrum
  83. float mel[ORDER+1];
  84. float mel_data[length][ORDER];
  85. //mel-warped LPC cepstrum,length為端點(diǎn)檢測(cè)后的每個(gè)語(yǔ)音數(shù)據(jù)的幀長(zhǎng)
  86. int mel_v=0;

  87. //Auto-Correlation Calculation
  88. correl(rad[count],cor,W_SIZE,ORDER);
  89. //LPC Analysis Program
  90. corref(ORDER,cor,alf);
  91. //LPC Cepstrum Coefficient Calculation
  92. alfcep(ORDER,alf,cep,ORDER);
  93. alf[0]=cep[0]=cor[0]; //cor[0] is power
  94. //MEL Cepstrum Coefficient Calculation
  95. cepmel(cep,mel);
  96. //printf("\n Frame %d :",count);

  97. for(i=0;i<ORDER;i++)
  98. {
  99. mel_data[mel_v][i]=mel[i+1];
  100. //printf("\nFrame %d: Mel[%d][%d]= %g",count,mel_v,i,mel_data[mel_v][i]);
  101. }
  102. }
復(fù)制代碼

下載:
00063058lpc.rar (1.54 KB, 下載次數(shù): 13)







歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1