Пример #1
0
 def find_kiwi_regions(self, condition, segments, rate, min_no_ind_calls):
     candidates = []
     result = contiguous_regions(condition)
     for start, end in result:
         length = end - start
         if length >= min_no_ind_calls:
             region_start = segments[start][0]
             region_end = segments[start + length - 1][1]
             if self._density_above_threshold(region_start, region_end, length, rate):
                 candidates.append(Candidate(region_start, region_end))
             else:
                 for i in np.arange(length - min_no_ind_calls):
                     region_start = i
                     region_end = i + min_no_ind_calls
                     if self._density_above_threshold(region_start, region_end, min_no_ind_calls, rate):
                         candidates.append(Candidate(region_start, region_end))
     return candidates
Пример #2
0
 def find_kiwi_regions(self, condition, segments, rate, min_no_ind_calls):
     candidates = []
     result = contiguous_regions(condition)
     for start, end in result:
         length = end - start
         if length >= min_no_ind_calls:
             region_start = segments[start][0]
             region_end = segments[start + length - 1][1]
             if self._density_above_threshold(region_start, region_end,
                                              length, rate):
                 candidates.append(Candidate(region_start, region_end))
             else:
                 for i in np.arange(length - min_no_ind_calls):
                     region_start = i
                     region_end = i + min_no_ind_calls
                     if self._density_above_threshold(
                             region_start, region_end, min_no_ind_calls,
                             rate):
                         candidates.append(
                             Candidate(region_start, region_end))
     return candidates
Пример #3
0
def remove_clicks(signal, rate, window_size, margin):
    """
    Clicks are bursts of energy. The fucntion will calculate signal energy over given window
    size and eliminate regions of abnormaly high energy content.

    Parameters
    --------------
    signal : 1d-array
        Single-channel audio sample.
    rate : int
        Sample rate in Hz.
    window_size : int
        The number of data points used in each block for the energy calculation.
    margin : float
        How much (in seconds) the sample should be cut on both sides.
    Returns
    --------------
    signal : 1d-array
        Cleared signal.
    """
    margin = margin * rate
    overlap = window_size / 2.0
    mask = np.ones(len(signal), dtype=bool)

    if np.abs(signal.max()) > 2**14:
        energy = calculate_energy(signal, window_size, overlap)
        energy = sig.medfilt(energy, 15)

        p = np.percentile(energy, 90)
        condition = energy > 2*p

        cont = contiguous_regions(condition)
        for start, stop in cont:
            start_idx = start * window_size - margin
            stop_idx = stop * window_size + margin
            mask[start_idx:stop_idx] = False

    return signal[mask]
Пример #4
0
def remove_clicks(signal, rate, window_size, margin):
    """
    Clicks are bursts of energy. The fucntion will calculate signal energy over given window
    size and eliminate regions of abnormaly high energy content.

    Parameters
    --------------
    signal : 1d-array
        Single-channel audio sample.
    rate : int
        Sample rate in Hz.
    window_size : int
        The number of data points used in each block for the energy calculation.
    margin : float
        How much (in seconds) the sample should be cut on both sides.
    Returns
    --------------
    signal : 1d-array
        Cleared signal.
    """
    margin = margin * rate
    overlap = window_size / 2.0
    mask = np.ones(len(signal), dtype=bool)

    if np.abs(np.nanmax(signal)) > 2**14:
        energy = calculate_energy(signal, window_size, overlap)
        energy = sig.medfilt(energy, 15)

        p = np.percentile(energy, 90)
        condition = energy > 2*p

        cont = contiguous_regions(condition)
        for start, stop in cont:
            start_idx = int(start * window_size - margin)
            stop_idx = int(stop * window_size + margin)
            mask[start_idx:stop_idx] = False

    return signal[mask]