-
Notifications
You must be signed in to change notification settings - Fork 2
/
smooth.praat
36 lines (27 loc) · 1.17 KB
/
smooth.praat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
## smooth.praat: computes weighted symmetrical moving average
## James Kirby <[email protected]>
## 4 Jan 2017
## This basically constructs a Praat Formula... that works for moving window
## averages of arbitrary length, to avoid having to manually average and
## weight e.g. 1*( (i-10)+(i+10) ) + 2*( (i-9) + (i+9) ) + ... etc.
procedure smooth: .wS
## wS = window size = number of points on either side of point of interest to be taken into account
## slightly confusing but so too is allowing the user to specify the size of the window itself;
## what does an even (=asymmetric) window size mean?
# multipler of current value: wS+1
.nMult = .wS+1
# denominator: sum of weights
.denom = .wS+1
for i from 1 to .wS
.denom = .denom + 2*i
endfor
# construct formula
.formula$ = "(" + string$(.nMult) + " * self [col]"
j = .wS
while j > 0
.formula$ = .formula$ + " + " + string$(j) + " * (self [col - " + string$(.nMult-j) + "] + self [col + " + string$(.nMult-j) + "])"
j = j - 1
endwhile
.formula$ = .formula$ + " ) / " + string$(.denom)
# to access in main script body: use smooth.formula$
endproc