#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ ENGG1811 Lecture Week 4 Counting heart beats """ #%% Import file import matplotlib.pyplot as plt #%% Load data and convert to float # load the file which contains sampling instants # create a list of sampling time (data type: string) with open('time_data_partial.txt') as f: time_str_list = f.read().splitlines() # load the file which contains measured voltage # create a list of voltage values (data type: string) with open('voltage_data_partial.txt') as f: voltage_str_list = f.read().splitlines() # convert the elements in the list to float data type time_list = [float(t) for t in time_str_list] voltage_list = [float(v) for v in voltage_str_list] #%% Count the number tall peaks # Define a threshold threshold = 3 # Counting incoporating threshold is_peak_list = [] # Enter the code here print('The number of tall peaks is:',sum(is_peak_list)) fig3 = plt.figure() # create a new figure plt.plot(time_list,voltage_list) plt.xlabel('time [s]') # label for x-axis plt.ylabel('voltage [V]') # label for y-axis plt.title('Pulse oximeter data') # title of the graph plt.grid() # display the grid plt.show() # to display the graph