예제 #1
0
def get_list_of_intervals(signals_af):
    """Getting RR signals and returning list of intervals"""

    # Wavelet filtration
    numbers_of_signals = len(signals_af[0, :])
    numbers_of_samples = len(signals_af[:, 0])

    for i in range(numbers_of_signals):
        if numbers_of_samples % 2 == 1:
            signals_af = signals_af[:numbers_of_samples - 1, :]
        signals_af[:, i] = wavelet_analysis.filter_signal(signals_af[:, i],
                                                          wavelet="db6",
                                                          highcut=False)

    # Finding R-waves
    analyzerQRS = bothChannelsQRSDetector.BothChannelsQRSDetector()
    combined_rr = analyzerQRS.compare(signals_af,
                                      record_file=file_path,
                                      plotting=False,
                                      qrs_reading=False)

    # Creating list of isoelectrics lines
    rr_ia = RRIntervalsAnalyser.RRIntervalsAnalyser(analyzerQRS)
    list_of_intervals_chann0, rr_distances_chann0 = rr_ia.get_intervals(
        combined_rr, channel_no=0, time_margin=0.1)
    list_of_intervals_chann1, rr_distances_chann1 = rr_ia.get_intervals(
        combined_rr, channel_no=1, time_margin=0.1)

    return (list_of_intervals_chann0, list_of_intervals_chann1)
예제 #2
0
    record_atrial_fibrillation.set_frequency(250)
    record_normal.set_frequency(1000)
    start = 1094000  # 1417000
    interval = 20  #164

    # SIGNALS
    signals_af = record_atrial_fibrillation.get_signals(start, interval)

    # RESAMPLING
    # signals_norm = signal.resample(signals_norm, num=len(signals_norm[:,0])/4)

    # QRS Analysis and RR Analysis
    analyzerQRS = bothChannelsQRSDetector.BothChannelsQRSDetector()
    combined_rr = analyzerQRS.compare(signals_af, record_file=path_af)

    rr_ia = RRIntervalsAnalyser.RRIntervalsAnalyser(analyzerQRS)
    list_of_intervals_chann0, rr_distances_chann0 = rr_ia.get_intervals(
        combined_rr, channel_no=0, time_margin=0.1)
    list_of_intervals_chann1, rr_distances_chann1 = rr_ia.get_intervals(
        combined_rr, channel_no=1, time_margin=0.1)

    list_of_isoelectrics_chann0 = rr_ia.get_list_of_intervals_isoelectric_line(
        list_of_intervals_chann0, interval_samples=100)
    list_of_isoelectrics_chann1 = rr_ia.get_list_of_intervals_isoelectric_line(
        list_of_intervals_chann1, interval_samples=100)

    pca = dimensionAnalyzer.PCADimensionAnalyser()
    ica = dimensionAnalyzer.ICADimensionAnalyzer()

    for index, interval_chann0 in enumerate(list_of_intervals_chann0):
        if subdir_patientname == "learning-set":
            filepath = path.join("downloads", "af_term", subdir_patientname,
                                 record_no)
            record = wfdb.rdsamp(filepath)
            n = calculate_number_of_samples(time_of_record, fs=128)
            signals, fields = wfdb.srdsamp(filepath,
                                           sampfrom=record.siglen - n - 1,
                                           sampto=record.siglen - 1,
                                           channels=None,
                                           pbdir=None)

            # GETTING RR INTERVALS
            rr_detector = bothChannelsQRSDetector.BothChannelsQRSDetector()
            combined_rr = rr_detector.compare(signals=signals[:, 0:2],
                                              sampling_ratio=128)
            rr_ia = RRIntervalsAnalyser.RRIntervalsAnalyser(
                sampling_ratio=128, signals=signals[:, 0:2])

            a = rr_ia.get_intervals(combined_rr, channel_no=0, time_margin=0.1)
            list_of_intervals_chann0, rr_distances_chann0 = rr_ia.get_intervals(
                combined_rr, channel_no=0, time_margin=0.1)
            list_of_intervals_chann1, rr_distances_chann1 = rr_ia.get_intervals(
                combined_rr, channel_no=1, time_margin=0.1)
            # SAVE TO DICT WITH PATIENT INFO
            patient_name = record_no
            data_for_patient = {
                "channel0": list_of_intervals_chann0,
                "channel1": list_of_intervals_chann1
            }
            aftdb_dataset[patient_name] = data_for_patient

            if record_no == 'n03':