<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def emg_find_activation(envelope, sampling_rate=1000, threshold=0, n_above=0.25, n_below=1):
 """Detects onset in data based on amplitude threshold. Parameters envelope : array Linear envelope of EMG signal. sampling_rate : int Sampling rate (samples/second). threshold : float minimum amplitude of `x` to detect. n_above : float minimum continuous time (in s) greater than or equal to `threshold` to detect (but see the parameter `n_below`). n_below : float minimum time (in s) below `threshold` that will be ignored in the detection of `x` >= `threshold`. Returns ------- activation : array With 1 when muscle activated and 0 when not. Notes ----- You might have to tune the parameters according to the signal-to-noise characteristic of the data. See this IPython Notebook [1]_. References .. [1] http://nbviewer.ipython.org/github/demotu/BMC/blob/master/notebooks/DetectOnset.ipynb """

    n_above = n_above*sampling_rate
    n_below = n_below*sampling_rate


    envelope = np.atleast_1d(envelope).astype('float64')
    # deal with NaN's (by definition, NaN's are not greater than threshold)
    envelope[np.isnan(envelope)] = -np.inf
    # indices of data greater than or equal to threshold
    inds = np.nonzero(envelope >= threshold)[0]
    if inds.size:
        # initial and final indexes of continuous data
        inds = np.vstack((inds[np.diff(np.hstack((-np.inf, inds))) > n_below+1], \
                          inds[np.diff(np.hstack((inds, np.inf))) > n_below+1])).T
        # indexes of continuous data longer than or equal to n_above
        inds = inds[inds[:, 1]-inds[:, 0] >= n_above-1, :]
    if not inds.size:
        inds = np.array([])  # standardize inds shape

    inds = np.array(inds)

    activation = np.array([0]*len(envelope))
    for i in inds:
        activation[i[0]:i[1]] = 1
    return (activation)