Skip to content

Commit

Permalink
bugfix cumulative_mean in yin
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Lostanlen committed Aug 23, 2019
1 parent 489fd73 commit 278bb70
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions librosa/core/pitch.py
Expand Up @@ -439,19 +439,10 @@ def yin(y, sr=22050, frame_length=2048, hop_length=None, fmin=40, fmax=None,
yin_frames = energy_0 + energy_frames - 2*acf_frames

# Cumulative mean normalized difference function.
# NB: Equation 8 in de Cheveigné and Kawahara JASA 2002 seems to imply that
# the denominator is: cumsum(difference_fames)/tau_range, not
# cumsum(difference_frames/tau_range) as we implement it.
# However, going back to line 48 of the MATLAB code by AdC, we find the line:
# dd= d(2:end) ./ (cumsum(d(2:end)) ./ (1:(p.maxprd)));
# in which the parentheses indicate that the division by tau must happen
# before the cumulative summation, not after.
# Therefore, in this implementation, we purposefully diverge from Equation 8
# and follow the MATLAB reference implementation instead.
if cumulative:
yin_numerator = yin_frames[(min_period-1):(max_period+1), :]
tau_range = np.arange(1, frame_length)[:, np.newaxis]
cumulative_mean = np.cumsum(yin_frames[1:, :]/tau_range, axis=0)
cumulative_mean = np.cumsum(yin_frames[1:, :], axis=0) / tau_range
epsilon = np.finfo(y.dtype).eps
yin_denominator = epsilon + cumulative_mean[(min_period-2):max_period, :]
yin_frames = yin_numerator / yin_denominator
Expand Down

0 comments on commit 278bb70

Please sign in to comment.