Example Heart Rate Monitor

For the purpose of this example, I'll generate a signal that simulates the data generated from a heart-rate monitor connected to a patient. Please do not use this in any sort of production system; it's merely for educational purposes (and not meant to truly represent heart signals!).

The patient walks around, and as a result, two signals are picked up: 1) the heart signal and 2) a signal associated with the patient's movement, or what is typically referred to as a movement artifact. Listing 8-8 shows these signals in my simulation.

Listing 8-8. Heart Rate Simulation

# heart signal simulation N = 256 # number of samples per second T=2 # number of seconds hr = 1.67 # 100 beats per minutes Fl=0.5 # movement frequency t = arange(T*N)/float(N)

# add heart signals y2 = zeros(size(yl))

# combine movement with beats y = yl+y2

# create a high-pass filter

# plot the graphs figure()

title('Heart signal with movement artifact (simulation)') plot(t, y, lw=2) xlabel('t [seconds]') ylabel('Amplitude []')

subplot(2, 1, 2) title('Filtered signal') plot(t, yn, lw=2) xlabel('t [seconds]') ylabel('Amplitude []')

I've defined several parameters that control the script. The value N is equal to the number of samples per second (some are used to name this value Fs, which stands for frequency of sampling). The value T is the total number of seconds, in this case 2 whole seconds. The value hr is the patient's heart rate, 100 beats per minute: 100 / 60 = 1.67 Hz. Lastly, I defined the movement artifact frequency at 0.5 Hz. I then construct a time vector, t, and a movement artifact vector, vl, and add "beats" with triangular waveforms using the signal.triang() function.

Now that I have a heart signal with a movement artifact, I turn to filter out the movement artifact. I design a second-order Butterworth HPF to do so via the call to signal.butter() and use the filter parameters to filter the signal using signal.lfilter(). Figure 8-15 shows the resulting plot.

Heart signal with movement artifact (simulation)

Heart signal with movement artifact (simulation)

t [seconds]

Figure 8-15. Filtering a signal t [seconds]

Figure 8-15. Filtering a signal

Was this article helpful?

0 0

Post a comment