test_FilterBank.praat 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # test_Filterbank.praat
  2. # djmw 20110907
  3. eps = 1.6e-16
  4. printline test_FilterBank
  5. starttime = 0
  6. endtime = 1
  7. fs = 44100
  8. s = Create Sound from formula... sineWithNoise 1 starttime endtime fs 1/2 * sin(2*pi*377*x) + randomGauss(0,0.1)
  9. call test_FormantFilter s
  10. call test_BarkFilter s
  11. call test_MelFilter s
  12. select s
  13. Remove
  14. printline test_FilterBank OK
  15. procedure test_FormantFilter .s
  16. printline 'tab$' test FormantFilter
  17. bf_first = 100
  18. fdistance = 50
  19. timestep = 0.005
  20. select .s
  21. .ff = To FormantFilter... 0.015 timestep bf_first fdistance 0 1.1 75 600
  22. call queries .ff
  23. call modifies .ff
  24. call commons .ff
  25. select .ff
  26. Remove
  27. endproc
  28. procedure test_BarkFilter .s
  29. printline 'tab$' test BarkFilter
  30. select .s
  31. bf_first = 1
  32. fdistance = 1
  33. .bf = To BarkFilter... 0.015 timestep 1 1 0
  34. call queries .bf
  35. call modifies .bf
  36. call commons .bf
  37. select .bf
  38. Remove
  39. endproc
  40. procedure test_MelFilter .s
  41. printline 'tab$' test MelFilter
  42. select .s
  43. bf_first = 100
  44. fdistance = 100
  45. .mf = To MelFilter... 0.015 timestep bf_first fdistance 0
  46. call queries .mf
  47. call modifies .mf
  48. call commons .mf
  49. select .mf
  50. .mfcc = To MFCC... 12
  51. Remove
  52. select .mf
  53. Remove
  54. endproc
  55. procedure commons .bf
  56. select .bf
  57. .in = To Intensity
  58. Remove
  59. select .bf
  60. .mat = To Matrix
  61. Remove
  62. endproc
  63. procedure queries .fb
  64. select .fb
  65. .starttime = Get start time
  66. .endtime = Get end time
  67. .dur = Get total duration
  68. assert abs( .dur -(.endtime-.starttime)) <= eps
  69. assert .starttime = starttime
  70. assert .endtime = endtime
  71. .timestep = Get time step
  72. assert .timestep = timestep; '.timestep' 'timestep'
  73. .bf_first = Get lowest frequency
  74. assert .bf_first >= 0; '.bf_first' 'bf_first'
  75. .bf_last = Get highest frequency
  76. assert .bf_last <= fs/2
  77. .nf = Get number of frequencies
  78. assert .nf >= 1
  79. .fdistance = Get frequency distance
  80. assert .fdistance=fdistance; '.fdistance' 'fdistance'
  81. .f_from_row[1] = Get frequency from row... 1
  82. for .i from 2 to .nf
  83. .f_from_row[.i] = Get frequency from row... .i
  84. .fi = .f_from_row[.i]
  85. .fim1 = .f_from_row[.i-1]
  86. assert .f_from_row[.i] >.f_from_row[.i-1]; '.fi' >.'fim1'
  87. endfor
  88. for .i to .nf
  89. .time = randomUniform (.starttime, endtime)
  90. .vali = Get value in cell... .time .i
  91. endfor
  92. endproc
  93. procedure modifies .fb
  94. select .fb
  95. Equalize intensities... 80
  96. endproc