test_gammatonefilter.praat 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # test_gammatonefilter.praat
  2. # djmw 20170531
  3. for i to 5
  4. puls [i] = Create Sound from formula: "puls", 1, 0, i * 0.2, 44100, "col=1"
  5. endfor
  6. appendInfoLine: "test_gammatonefilter.praat"
  7. appendInfoLine: tab$, "Filter pulses of duration i * 0.2"
  8. header$ = "F"+tab$+"Q"+tab$+"Peak(dB)"+tab$+"dF"
  9. output$ = header$ +newline$
  10. q = 0.1
  11. f = 1000
  12. for ifreq to 20
  13. b = 100
  14. f = 500 + (ifreq - 1) * 100
  15. for i to 5
  16. selectObject: puls [i]
  17. s = Filter (gammatone): f, b
  18. spec = To Spectrum: "yes"
  19. be [i] = Get band energy: f - 0.5 * b, f + 0.5 * b
  20. removeObject: s, spec
  21. endfor
  22. for i from 2 to 5
  23. ;appendInfoLine: abs(be[i] -be [i-1]) / abs (be[i])
  24. assert abs(be[i] -be [i-1]) / abs (be[i]) < 1e-4
  25. endfor
  26. endfor
  27. for i to 5
  28. removeObject: puls [i]
  29. endfor
  30. appendInfoLine: tab$, "Compare incomplete gamma with Gamma[n,z]"
  31. # values in the csv file were calculated by the Mathematica function
  32. # N[Gamma[i, i + I i/j], 10]
  33. igt = Read Table from comma-separated file: "incompleteGamma.csv"
  34. numberOfLines = Get number of rows
  35. eps = 1e-7
  36. for irow to numberOfLines
  37. i = Get value: irow, "i"
  38. j = Get value: irow, "j"
  39. re = Get value: irow, "re"
  40. im = Get value: irow, "im"
  41. z$ = Get incomplete gamma: i, 0.0, i, i / j
  42. @complex (z$)
  43. pre = complex.re
  44. pim = complex.im
  45. ;appendInfoLine: irow, " ", re, " ", im, " ", pre, " ", pim
  46. assert abs((pre - re)/pre) < eps && abs ((pim - im)/pim) < eps; 'irow' 'pre' 're' 'pim' 'im' <'z$'>
  47. endfor
  48. removeObject: igt
  49. procedure complex: .z$
  50. .re = extractNumber (.z$, "")
  51. .im = extractNumber (.z$, "+")
  52. if .im = undefined
  53. ; im < 0
  54. .index = rindex (.z$, "-")
  55. .length = length (.z$)
  56. .last$ = mid$ (.z$, .index, .length - .index)
  57. .im = number (.last$)
  58. endif
  59. endproc
  60. appendInfoLine: "test_gammatonefilter.praat OK"