-----
    Brief
    -----
    Returns the evolution time series of EMG median frequency along the acquisition, based on a sliding window
    mechanism.

    -----------
    Description
    -----------
    The median frequency of activation events in EMG signal is particularly important in fatigue evaluation methods.

    This function calculates the median frequency of each activation period and allows to plot those values in order to
    see the temporal evolution of this particular feature.

    ----------
    Parameters
    ----------
    data : list
        EMG signal.

    sample_rate : int
        Sampling frequency.

    time_units : boolean
        If True this function will return the x axis samples in seconds.

    raw_to_mv : boolean
        If True then it is assumed that the input samples are in a raw format and the output
        results will be in mV. When True "device" and "resolution" inputs became mandatory.

    device : str
        Plux device label:
        - "bioplux"
        - "bioplux_exp"
        - "biosignalsplux"
        - "rachimeter"
        - "channeller"
        - "swifter"
        - "ddme_openbanplux"

    resolution : int
        Resolution selected during acquisition.

    show_plot : boolean
        If True, then a figure with the median frequency evolution will be shown.

    Returns
    -------
    out : pandas.DataFrame
        DataFrame with the time and the sequence of median frequency evolution.

def fatigue_eval_med_freq(data, sample_rate, time_units=True, raw_to_mv=True,
                          device="biosignalsplux", resolution=16, show_plot=False):
    """
    -----
    Brief
    -----
    Returns the evolution time series of EMG median frequency along the acquisition, based on a sliding window
    mechanism.

    -----------
    Description
    -----------
    The median frequency of activation events in EMG signal is particularly important in fatigue evaluation methods.

    This function calculates the median frequency of each activation period and allows to plot those values in order to
    see the temporal evolution of this particular feature.

    ----------
    Parameters
    ----------
    data : list
        EMG signal.

    sample_rate : int
        Sampling frequency.

    time_units : boolean
        If True this function will return the x axis samples in seconds.

    raw_to_mv : boolean
        If True then it is assumed that the input samples are in a raw format and the output
        results will be in mV. When True "device" and "resolution" inputs became mandatory.

    device : str
        Plux device label:
        - "bioplux"
        - "bioplux_exp"
        - "biosignalsplux"
        - "rachimeter"
        - "channeller"
        - "swifter"
        - "ddme_openbanplux"

    resolution : int
        Resolution selected during acquisition.

    show_plot : boolean
        If True, then a figure with the median frequency evolution will be shown.

    Returns
    -------
    out : pandas.DataFrame
        DataFrame with the time and the sequence of median frequency evolution.
    """

    # Conversion of data samples to mV if requested by raw_to_mv input.
    if raw_to_mv is True:
        data = raw_to_phy("EMG", device, data, resolution, option="mV")

    # Definition of the time axis.
    if time_units is True:
        time = numpy.linspace(0, len(data) / sample_rate, len(data))
    else:
        time = numpy.linspace(0, len(data) - 1, len(data))

    # Detection of muscular activation periods.
    burst_begin, burst_end = detect_emg_activations(data, sample_rate, smooth_level=20,
                                                    threshold_level=10, time_units=False,
                                                    volts=True, resolution=resolution,
                                                    device=device, plot_result=False)[:2]

    # Iteration along bursts.
    median_freq_data = []
    median_freq_time = []
    for burst in range(0, len(burst_begin)):
        processing_window = data[burst_begin[burst]:burst_end[burst]]
        central_point = (burst_begin[burst] + burst_end[burst]) / 2
        median_freq_time.append(central_point / sample_rate)

        # Generation of the processing window power spectrum.
        freqs, power = scisignal.welch(processing_window, fs=sample_rate, window='hanning',
                                       noverlap=0, nfft=int(256.))

        # Determination of median power frequency.
        area_freq = integr.cumtrapz(power, freqs, initial=0)
        total_power = area_freq[-1]
        median_freq_data.append(freqs[numpy.where(area_freq >= total_power / 2)[0][0]])

    # Graphical Representation step.
    if show_plot is True:
        list_figures_1 = plot([list(time), list(median_freq_time)],
                              [list(data), list(median_freq_data)],
                              title=["EMG Acquisition highlighting bursts",
                                     "Median Frequency Evolution"], gridPlot=True,
                              gridLines=2, gridColumns=1, openSignalsStyle=True,
                              x_axis_label="Time (s)",
                              yAxisLabel=["Raw Data", "Median Frequency (Hz)"],
                              x_range=[0, 125], show_plot=False)

        # Highlighting processing window.
        for burst in range(0, len(burst_begin)):
            color = opensignals_color_pallet()
            box_annotation = BoxAnnotation(left=burst_begin[burst] / sample_rate,
                                           right=burst_end[burst] / sample_rate, fill_color=color,
                                           fill_alpha=0.1)
            box_annotation_copy = BoxAnnotation(left=burst_begin[burst] / sample_rate,
                                                right=burst_end[burst] / sample_rate,
                                                fill_color=color, fill_alpha=0.1)
            list_figures_1[0].add_layout(box_annotation)
            list_figures_1[1].add_layout(box_annotation_copy)

        gridplot_1 = gridplot([[list_figures_1[0]], [list_figures_1[1]]],
                              **opensignals_kwargs("gridplot"))
        show(gridplot_1)

    # pandas.DataFrame(a, columns=a.keys())
    # pandas.DataFrame([a], columns=a.keys())
    return pandas.DataFrame({"Time (s)": median_freq_time,
                             "Median Frequency (Hz)": median_freq_data},
                            columns=["Time (s)", "Median Frequency (Hz)"])