import binascii import pandas as pd import matplotlib.pyplot as plt counter = 0 counter_prev = 0 millisecs = 0 with open("FILE_1.ECG", "rb") as f: with open("HBL_cleaned.txt", "w") as outfile: outfile.write(f"timestamp,ECG,etag,ptag\n") while True: chunk = f.read(3) if not chunk: break counter+= 1 ptag = int(binascii.hexlify(chunk), 16) & 0x03 etag = (int(binascii.hexlify(chunk), 16) & 0x38)>>3 sample = (int(binascii.hexlify(chunk), 16) & 0xFFFFC0)>>6 if(etag == 0b110): print(f"{counter} \tFIFO Empty") continue if(etag == 0b010): counter_prev = counter print(f"{counter} \tFIFO End") if (counter_prev - counter > 32): print("ABNORMALItY") continue outfile.write(f'{millisecs},{str(sample)},{format(etag, "03b")},{format(ptag, "03b")}\n') millisecs+=1 outfile.close() df = pd.read_csv('HBL_cleaned.txt') df['ECG'].plot() plt.show()