Check your ECG with the Armmite H7


Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 11832
Posted: 06:01pm 09 Jan 2019      



To do this you need some of these




One of these




and a set of these




All very cheap and then just add some very simple code.

The code is set up for 50Hz mains voltage. The amplifier is extremely sensitive and picks up 50Hz noise from the environment. The code averages 80 samples every 20mSec in order minimise this and as shown in the picture this works pretty well. For 60Hz operation you will need to adjust the mains frequency, samples per second and number of samples in order to filter the noise and get the right number of samples across the screen. I'm using a 5" SSD1963 in 16-bit mode but any display could work by adjusting the display parameters.

The code as written uses the huge memory on the H7 and the background ADC sampling but could be re-written for other Micromites. Note, the code also needed a change to the H7 firmware to overcome a limit on the maximum array size of 32767. This change will be included in the next H7 release.

Option explicit
Option default none
Option VCC 3.308
const r_trigger=2.3 'level to trigger trace and count BPM
const MAINSFREQ = 50
Const SAMPLESPERSEC = 4000
const MAXPULSE=500
Const AveragingFREQ = SAMPLESPERSEC/MAINSFREQ '20mSec to filter mains noise
CONST RTIME=60/MAXPULSE*AveragingFREQ 'minimum number of samples before we expect a new QRS complex
Const NSAMPLES = 48000
Dim integer i, j, k, BPMstate, BPMcount
Dim float a(NSAMPLES-1), displ(NSAMPLES / AveragingFREQ-1)
dim integer RPOS(100)
CLS

'
' convert the signals
'
ADC open SAMPLESPERSEC, 49,,, adc_done
ADC TRIGGER 1, r_trigger
do
ADC start a()
j=0
Do
Loop While j=0
k=0
BPMstate=RTIME 'don't look for an new QRS complex for RTIME samples
BPMcount=0
for i=0 to NSAMPLES / AveragingFREQ-1
displ(i)=0
for j=0 to AveragingFREQ-1
displ(i)=displ(i)+a(k)
k=k+1
next j
displ(i)=displ(i)/AveragingFREQ
' now evaluate BPM
' we know we were triggered by a QRS complex
if BPMstate > 0 then BPMstate = BPMstate - 1
if BPMstate = 0 and displ(i)>r_trigger then
RPOS(BPMcount)=i
BPMcount=BPMcount+1
RPOS(BPMcount)=i
BPMstate=RTIME
endif
next i

Box 99,0,603,MM.VRes,1,rgb(white),rgb(black)
For i=2 To 599
Line i+100, 250 - displ((i-2)\2)*75, i+102, 250 - displ(i\2)*75,, RGB(magenta)
cdisp(i\2-1)=displ(i\2-1)
Next i
line 100,250-r_trigger*75,699,250-r_trigger*75,,rgb(blue)
For i=600 To 1199
Line i-500, 470 - displ((i-2)\2)*75, i-498, 470 - displ(i\2)*75,, RGB(magenta)
Next i
line 100,470-r_trigger*75,699,470-r_trigger*75,,rgb(blue)
if BPMcount then text mm.hres\2,450,str$(60/(RPOS(BPMcount)/MAINSFREQ)*BPMcount,3,0)+" BPM",C,4
loop
'
End

Sub adc_done
j=1
End Sub

Edited by matherp 2019-01-11