Пример #1
0
def compute_power_frequency_on_spectrum(signal, low_bound_freq, high_bound_freq=None):
    """Compute the total power frequency on a particular spectrum

    Args:
        signal: the input data (1d-array).
        lower_bound_freq: the lower bound frequency below which the signal must be completely attenuated.
        higher_bound_freq: the higher bound frequency above which the signal must be completely attenuated.
    Returns:
        total_power_frequency: a float that represents the total power frequency of the freq_spectrum.

    """
    if high_bound_freq is None:
        filtered_freq = high_pass_filter(signal, low_bound_freq, defaults.SAMPLING_FREQUENCY)
    else:
        filtered_freq = band_pass_filter(signal, low_bound_freq, high_bound_freq, defaults.SAMPLING_FREQUENCY)

    return compute_total_power_frequency_on_signal(filtered_freq)
Пример #2
0
def signals_to_epochs(signal_dictionary):
    """Filter the signal data using BP and Notch filters.
    Aggregate the signal data into epochs (30 seconds per epoch, 30 * sampling_frequency data per epoch)

    Args:
        signal_dictionary: dictionary of lists of EEG and EMG data
        log: option to log the progress of the function

    Returns:
        epochs: dictionary of data_file dictionaries, each containing dictionaries of lists of filtered EEG and EMG data
    """
    epochs = []

    for channel, signal in signal_dictionary.iteritems():
        # determine signal type and use the appropriate boundary frequencies for BP filter
        if channel in (EMG1, EMG2):
            low_bound_freq = EMG_LOW_BOUND_FREQUENCY
            high_bound_freq = EMG_HIGH_BOUND_FREQUENCY
        else:
            low_bound_freq = EEG_LOW_BOUND_FREQUENCY
            high_bound_freq = EEG_HIGH_BOUND_FREQUENCY

        # apply BP filter
        filtered_signal, _ = band_pass_filter(signal, low_bound_freq,
                                              high_bound_freq, SAMPLING_FREQUENCY)
        # apply Notch filter to remove AC interference
        filtered_signal = notch_filter(filtered_signal, NOTCH_FREQUENCY,
                                       NOTCH_FREQUENCY_BANDWIDTH, SAMPLING_FREQUENCY)

        # aggregate data into epochs
        start_idx = 0
        end_idx = SAMPLES_PER_EPOCH
        epoch_idx = 0

        while end_idx <= len(filtered_signal):
            if not epoch_idx < len(epochs):
                epochs.append({})

            epochs[epoch_idx][channel] = filtered_signal[start_idx:end_idx]
            epoch_idx += 1
            start_idx = end_idx
            end_idx += SAMPLES_PER_EPOCH
    return epochs