Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def calcBaseline(time_series):
- time_series = np.asarray(time_series, dtype=int)
- baseline_values = peakutils.baseline(time_series)
- with open('baseline_values.txt', 'w') as filehandle:
- filehandle.writelines("%s\n" % value for value in baseline_values)
- def subtractBaseline(file):
- time_series = []
- baseline_values = []
- new_time_series = []
- nts = np.array(new_time_series, dtype=float)
- #read baseline values
- with open('baseline_values.txt', 'r') as filehandle:
- for line in filehandle:
- baseline_values.append(line.split()[0])
- bv = np.array(baseline_values, dtype=float)
- #read time series
- with open('C:/Users/João/Desktop/ECG/data/'+file) as f:
- for line in f:
- time_series.append(line.split()[6])
- if len(time_series) == 100:
- ts = np.array(time_series, dtype=float)
- nts = ts - bv
- time_series = []
- if time_series:
- ts = np.array(time_series, dtype=float)
- nts = ts - bv
- return nts
- def plotWithoutBaseline(signal):
- x = np.arange(0, len(signal), 1)
- y = np.asarray(signal)
- fig, ax = plt.subplots()
- ax.plot(x, y)
- plt.show()
- def filterSignal():
- print("Choose file from list of files:")
- files = os.listdir('data')
- for i in range(0,len(files)-1):
- if files[i].endswith('.txt'):
- print(files[i])
- file = input("Write the desired file name:")
- #remove baseline from the signal
- with open('C:/Users/João/Desktop/ECG/data/'+file, 'r') as f:
- result = []
- for line in f:
- result.append(line.split()[6])
- if len(result) == 100:
- calcBaseline(result)
- result = []
- if result:
- calcBaseline(result)
- signal = subtractBaseline(file)
- plotWithoutBaseline(signal)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement