| 1 |
# |
| 2 |
# test/num/interpolation.praat |
| 3 |
# Paul Boersma 2020-09-24 |
| 4 |
# |
| 5 |
|
| 6 |
writeInfoLine: "Interpolation, especially cubic..." |
| 7 |
Erase all |
| 8 |
Times |
| 9 |
12 |
| 10 |
sound = Create Sound from formula: "fakerandom", 1, 0, 1, 10000, ~ cos (56426631 * x^2) |
| 11 |
midTime = 0.5 |
| 12 |
timeDepth = 0.00026 |
| 13 |
top = -0.4 |
| 14 |
@drawValues: "nearest" |
| 15 |
@drawValues: "linear" |
| 16 |
@drawValues: "cubic" |
| 17 |
@drawValues: "sinc70" |
| 18 |
@drawValues: "sinc700" |
| 19 |
Remove |
| 20 |
appendInfoLine: "OK" |
| 21 |
|
| 22 |
procedure drawValues: interpolation$ |
| 23 |
bottom = top + 2.4 |
| 24 |
Select outer viewport: 0, 6, top, bottom |
| 25 |
Draw: midTime - timeDepth, midTime + timeDepth, -1.1, 1.1, "no", "poles" |
| 26 |
Draw inner box |
| 27 |
Marks bottom every: 1.0, 0.0001, "yes", "yes", "yes" |
| 28 |
Marks left every: 1.0, 0.2, "yes", "yes", "yes" |
| 29 |
time = midTime - timeDepth |
| 30 |
while time <= midTime + timeDepth |
| 31 |
value = Get value at time: 1, time, interpolation$ |
| 32 |
Paint circle (mm): "black", time, value, 0.5 |
| 33 |
time += 1e-6 |
| 34 |
endwhile |
| 35 |
peakInterpolation$ = |
| 36 |
... if interpolation$ = "nearest" then "none" |
| 37 |
... else if interpolation$ = "linear" then "parabolic" |
| 38 |
... else interpolation$ fi fi |
| 39 |
maximum = Get maximum: midTime - timeDepth / 2, midTime + timeDepth / 2, peakInterpolation$ |
| 40 |
timeOfMaximum = Get time of maximum: midTime - timeDepth / 2, midTime + timeDepth / 2, peakInterpolation$ |
| 41 |
Paint circle (mm): "red", timeOfMaximum, maximum, 2.0 |
| 42 |
if peakInterpolation$ = interpolation$ |
| 43 |
interpolatedValue = Get value at time: 1, timeOfMaximum, interpolation$ |
| 44 |
appendInfoLine: interpolation$, ": peak at ", timeOfMaximum, |
| 45 |
... " s; peak height ", maximum, "; interpolated value ", interpolatedValue |
| 46 |
assert interpolatedValue = maximum |
| 47 |
endif |
| 48 |
top += 1.8 |
| 49 |
endproc |