Skip to content

Commit ce1febb

Browse files
committed
Rewritten the delta calculation in a more vectorial form
1 parent e1e029a commit ce1febb

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

python_speech_features/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,12 @@ def delta(feat, N):
179179
:param N: For each frame, calculate delta features based on preceding and following N frames
180180
:returns: A numpy array of size (NUMFRAMES by number of features) containing delta features. Each row holds 1 delta feature vector.
181181
"""
182+
if N < 1:
183+
raise ValueError('N must be an integer >= 1')
182184
NUMFRAMES = len(feat)
183185
denominator = 2 * sum([i**2 for i in range(1, N+1)])
184186
delta_feat = numpy.empty_like(feat)
185187
padded = numpy.pad(feat, ((N, N), (0, 0)), mode='edge') # padded version of feat
186188
for t in range(NUMFRAMES):
187-
delta_feat[t] = numpy.sum([n * padded[N+t + n] for n in range(-N, N+1)], axis=0) / denominator
189+
delta_feat[t] = numpy.dot(numpy.arange(-N, N+1), padded[t : t+2*N+1]) / denominator # [t : t+2*N+1] == [(N+t)-N : (N+t)+N+1]
188190
return delta_feat

0 commit comments

Comments
 (0)