Skip to content

Commit

Permalink
Remove pre-emphasis glitch (#1159)
Browse files Browse the repository at this point in the history
* fixed #1032

* updated pre-emphasis documentation
  • Loading branch information
bmcfee committed Jun 12, 2020
1 parent c9ff670 commit 9604144
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions librosa/effects.py
Expand Up @@ -593,8 +593,17 @@ def preemphasis(y, coef=0.97, zi=None, return_zf=False):
At `coef=1`, the result is the first-order difference of the signal.
The default (0.97) matches the pre-emphasis filter used in the HTK
implementation of MFCCs [1]_.
.. [1] http://htk.eng.cam.ac.uk/
zi : number
Initial filter state
Initial filter state. When making successive calls to non-overlapping
frames, this can be set to the `zf` returned from the previous call.
(See example below.)
By default `zi` is initialized as `2*y[0] - y[1]`.
return_zf : boolean
If `True`, return the final filter state.
Expand Down Expand Up @@ -642,7 +651,10 @@ def preemphasis(y, coef=0.97, zi=None, return_zf=False):
a = np.asarray([1.0], dtype=y.dtype)

if zi is None:
zi = scipy.signal.lfilter_zi(b, a)
# Initialize the filter to implement linear extrapolation
zi = 2*y[..., 0] - y[..., 1]

zi = np.atleast_1d(zi)

y_out, z_f = scipy.signal.lfilter(b, a, y,
zi=np.asarray(zi, dtype=y.dtype))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_effects.py
Expand Up @@ -244,7 +244,7 @@ def test_split(y_split_idx, frame_length, hop_length, top_db):


@pytest.mark.parametrize("coef", [0.5, 0.99])
@pytest.mark.parametrize("zi", [None, [0]])
@pytest.mark.parametrize("zi", [None, 0, [0]])
@pytest.mark.parametrize("return_zf", [False, True])
@pytest.mark.parametrize("dtype", [np.float32, np.float64])
def test_preemphasis(coef, zi, return_zf, dtype):
Expand Down

0 comments on commit 9604144

Please sign in to comment.