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