Gas station without pumps

2022 April 16

ECG: 2-electrode vs. 3-electrode

Filed under: Circuits course — gasstationwithoutpumps @ 12:23
Tags: , , , ,

In Lower PVC frequency, I said “I did not do direct comparisons of the 2-electrode and 3-electrode configurations—I’ll have to try that sometime soon.” So I did that earlier this week, recording resting ECGs first with a 3-electrode configuration (with the bias electrode on my sternum, halfway between the LA and RA electrodes) and then with a 2-electrode configuration (with the bias wire clipped to the RA electrode).  The 60 Hz noise was slightly higher with the 2-electrode configuration, but after filtering and signal averaging the two recordings were almost identical:


The waveforms after signal averaging were remarkably similar. The PVC burden was also similar (20.1% for the 3-electrode recording and 20.5% for the 2-electrode recording).


The pulse rate from looking at time between spikes worked well for the resting recordings, but the autocorrelation method failed completely, so I did not plot it. The rapid fluctuation in heart rate within a narrow range is real, not an artifact of the algorithm—the heart beats are not perfectly periodic, and the PVCs may be making them even less periodic. The 2-electrode recording probably started a little after 400 seconds—PteroDAQ only time stamps when the file was saved, not what the t=0s time was. I should probably fix PteroDAQ to change that, recording both.


I tried recording a session on the exercise bike also. The PVCs are mainly during resting at the beginning of the session and at the end of a recovery at the end of the session—the PVC burden was only 1.4%.


For the exercise recording, the noise really disrupted the spike-based pulse detection, but did not interfere as much with the autocorrelation-based pulse detection. My peak pulse rate was about 151.5 bpm, by the autocorrelation measure. I’m not sure whether the sudden changes in pulse rate at 100s (when I started pedaling) and around 556s (about 130s into the recovery time) are real or not—the noise in the recording makes it a little difficult to determine the “correct” pulse rate.

The noise during exercise was not 60Hz noise and seemed to vary with whether I was inhaling or exhaling, so I think that it was probably caused by EMG signals from the pectoral muscles or perhaps the diaphragm. The spike detector was clearly missing a lot of the spikes, but making it more sensitive would probably result in false triggering on the EMG noise. I’m wondering whether putting the electrodes on my back, over the scapulae, would reduce the EMG noise, but placing those electrodes and clipping to them would be difficult without an assistant.

The autocorrelation-based pulse detection seems more reliable when exercising, as my pulse is more periodic and has few PVCs, and the autocorrelation method is less susceptible to aperiodic noise.  The spike-based pulse detection seems more reliable when resting, when the pulse is not as periodic and PVCs disrupt the pattern.

I’m also wondering whether a more strenuous exercise session would raise my pulse rate, or whether I’m getting close to my maximum heart rate.  The standard formula for maximum heart rate by age suggests that this may be close to my maximum, but the exercise does not seem all that strenuous, and a couple of years ago I could routinely push to 170 bpm (though perhaps on a device that was an unreliable reporter—it was built into a treadmill at the gym).  So sometime in the next few weeks I’ll try using a higher power output and seeing where my heartbeat tops out.  I’ll probably need to increase the cadence, rather than the resistance, as I’ve been using about 70rpm and 28Nm to get about 205W.  Raising that to 80rpm or even 90rpm is probably easier than increasing the torque.

2022 April 8

Press release for my book

Filed under: Circuits course — gasstationwithoutpumps @ 22:29
Tags: , , ,

World Scientific Publishing has released a press release for my book at  That press release is lightly edited from one I wrote for them.

The press release does not point to the lower-cost PDF version at, but I can’t really expect World Scientific to advertise the cheaper option, even though they did allow me to continue selling it.  They have not given me permission to use their cover design


Blue cover

for my PDF sales, so I will continue to use my own design:


I’m not that fond of their all-caps typesetting anyway, and the generic “tech” background has nothing to do with the contents of the book—but if they think that generic tech backgrounds sell better, I’m willing to believe them, as they have much more experience selling books than I do.

The text for the two versions of the book should be identical, but they are resetting it (with smaller headings and some other formatting changes), so the pagination will be different.

2022 March 29

Better heartbeat detection

Filed under: Circuits course — gasstationwithoutpumps @ 14:37
Tags: , , , , ,

In Lower PVC frequency, I promised “I’ll report on the algorithms when I get something a little better than I have now.”

I’ve played with three algorithms this week:

  • Doing spike detection, then measuring the time for 2n periods by looking at the time between the spikes n before andafter the current spike.  This gives a fine resolution both in time and frequency, and provides smoothing because adjacent measurements overlap by 2(n-1) periods. It is, however, very susceptible to errors due to miscalling the spikes.  Missed spikes result in too low a frequency, and extraneous spikes result in too high a frequency. I could increase n to reduce the effect of miscounts, but at some loss of time resolution when pulse rate changed.
  • Taking FFT of a block of samples (say 4096, which is about 17 seconds at 240 Hz) and looking for a high energy frequency.  Temporal resolution is poor (even with 50% overlapping blocks we get one measurement every 8.5s) and frequency resolution also poor (bins are about 3.5 bpm wide). I tried improving the frequency resolution by looking at the phase change for the peak between adjacent windows, but that didn’t solve the main problem, which was that choosing the right peak in the spectrum was often difficult.  The simple algorithms I tried for choosing the peak often failed. I eventually gave up on this technique.
  • Taking the autocorrelation of a block of samples (using rfft and irfft) and looking for a peak. The time for that peak is the period, which can be inverted to get the frequency.  This method provides the same coarse time resolution as the FFT method (same size blocks), but has much better frequency resolution, as even the fastest reasonable pulse rate (240bpm or 4Hz) has 60 samples at a sampling rate of 240Hz. I tried accentuating peaks “of the right width” in the autocorrelation by doing some filtering of the autocorrelation, and I tried looking for harmonic errors (where 150bpm might result in a larger peak in the autocorrelation at 75bpm, 50bpm, or 37.5bpm). Even with all the tweaks I could think of, I still had a number of way-off estimates, though median filtering removed most of the anomalies.  Of course, median-of-5 filter makes the time resolution even worse, as median could have come from any of 5 windows (with 50% overlap, that means a time range of 12288 samples or 51.2 seconds!).

I did most of my algorithm testing on one data set (the exercise set from 23 March 2022), and the algorithm is almost certainly overtrained on that data.


Here are both algorithms applied to the two data sets from 23 March. On the exercise set, the autocorrelation method did an excellent job (except right at the end of the run), but the 12-period measure clearly shows missing and extra peaks. On the resting set, the 12-period measurements were very good, but the autocorrelation ones failed at one point, even with median-of-five filtering. The autocorrelation measurements were also consistently somewhat low.


To try to figure out why the autocorrelation estimates of the pulse rate were low, I tried superimposing the filtered ECG signal on the plot. The PVCs are visible as large downward spikes. Having one or more PVCs in the window seems to make the autocorrelation estimates somewhat too low. I still have no explanation for why the autocorrelation measure fails so badly around 50 seconds.

Although the autocorrelation measure makes a nice smooth plot on the exercise data set, I sacrificed a lot of temporal resolution to get that. I think that I would do better to make a more robust spike detector to improve the period-based measurements.

2022 March 24

Lower PVC frequency

Filed under: Circuits course — gasstationwithoutpumps @ 09:58
Tags: , , ,

In PVC: Premature Ventricular Contraction, PVC and pulse, PVC again, and No PVC while exercising I posted some ECG recordings of my heart to show the premature ventricular complexes. Yesterday I tried recording the ECGs again, this time using only 2 electrodes using Lead I (LA–RA) and connecting the bias wire to right-arm electrode.  When I’ve tried that in the past it has not worked well, but with the new amplifier I got reasonably good recording, with only a bit more noise than I usually get with a 3-electrode configuration.  I did not do direct comparisons of the 2-electrode and 3-electrode configurations—I’ll have to try that sometime soon.

The interesting result is that my PVCs seem to be much less frequent now.  In a fairly long (454-second) recording, I had 355 normal spikes and 13 PVCs—a PVC burden of only 3.5%, with a pulse rate of 48.5 bpm.


The resting pulses looked pretty much like other recordings I made (averaged over all the pulses.

I also made a recording while on the bicycle ergometer: 100s just sitting, 400s pedaling moderately hard, and 500s recovering.  There were very few PVCs in that recording also (only 13 detected, for a PVC burden of 0.9%).  The averaging of waveforms across the entire recording did not produce a very useful result, as the heart rate varied from around 45bpm to around 154bpm.  I probably should modify the software to produce averages over just a dozen or so beats, to get the noise reduction without the confounding effect of variation in rate.

My attempt to produce a bpm vs time graph was not very successful—the signal was noisy enough that the spike detection algorithm was occasionally missing a spike or picking up an extra one, so that the method I was using of just inverting the time for n periods resulted in a very noisy graph at the higher heart rates.  I spent most of yesterday looking at two other ways of determining the period—one using the peak in an FFT and phase changes at that peak between overlapping windows and one using peaks in autocorrelation.  None of the three techniques worked well enough to produce a smooth graph, so I’ll probably work on them some more to try to come up with a more robust pulse finder.

I’ll report on the algorithms when I get something a little better than I have now.

2022 February 18

No PVC while exercising

Filed under: Circuits course — gasstationwithoutpumps @ 14:44
Tags: , , ,

In PVC: Premature Ventricular Contraction, PVC and pulse, and PVC again I posted some ECG recordings of my heart to show the premature ventricular complexes.

This week, I built a new ECG amplifier with a lower gain (especially on the first stage), with the voltage reference in the middle of the voltage range, and with a somewhat higher corner frequency for the high-pass filter, so that I would not clip the signals, even if there were fairly substantial movement artifacts.   I’m not going to provide that design here, as the design is still a lab in my textbook (and I have caught students copying not-so-great designs from earlier blog posts, without understanding what they were copying).

I also used longer wires to connect to the electrodes, so that I could sit upright on my bicycle ergometer without pulling the amplifier off the book rest on the handlebars. Because I was just recording Lead I (left arm minus right arm), I put the body-bias electrode on my sternum, halfway between the other electrodes, rather than as a left-leg electrode, so that I could keep the wires bundled together better.  This seemed to work fine for recording Lead I.

I recorded the ECG signal both resting (sitting at a table) and exercising, but I did not use the optical pulse monitor. The exercise session started out with me sitting still on the ergometer, then pedaling at about 70rpm with a resistance of about 30 N•m (about 220W).

I modified the software to report the instantaneous beats per minute (based on 6 periods):


The resting heart rate shows some fluctuation, which seems to be at lest partially due to PVCs disrupting the normal rhythm, but the normal sinus beats are a bit irregular also. The exercise shows a smooth increase from about 60bpm to 148bpm, then a gradual recovery as I stopped pedaling. The two big upward spikes and the big downward spike are places where they simple spike detector I was using either caught an extra spike or missed a spike. I looked at the bandpass-filtered signal in those places, and I did not see an easy way to improve the spike detector.


The resting recording was similar to my previous ones, showing an average heart rate of 49.5bpm, with 156 normal spikes and 53 PVCs, for a PVC burden of 25.9%. 

The exercise recording showed very few PVCs (only 4)—and those at the beginning and end of the recording, when I was not exercising.   My average heart rate was 113.5bpm, with 601 normal spikes and 4 PVCs, for a PVC burden of 0.6%.  It looks to me like normal sinus beats prevent the PVCs, and I only get PVCs when my sinus rhythm drops way down—as if my heart was trying to compensate for inadequate pacemaking at the sinoatrial node.


The averages for the normal ECG recordings are fairly similar, thought the T-wave seems to be smaller and earlier in the exercise recording. The exercise PVC average is only averaging 4 spikes, and so is very noisy. It is not clear to me whether the slightly earlier T-wave is meaningful here—though it does seem to correspond with the earlier time when exercising for the normal T-wave.

Also this week I contacted  Dr. Gregory M. Marcus at UCSF, who wrote Evaluation and Management of Premature Ventricular Complexes by , Circulation. 2020;141:1404–1418 I asked whether there were any more recent articles about risk for people in my circumstances (normal left-ventricular ejection fraction (LVEF), no symptoms, >10% burden) and whether there was any information about people who developed PVCs after having sinus bradycardia.  He told me that he knew of no newer material and no known connection between extant sinus bradycardia and PVC burden.  He just repeated the suggestion to get an echocardiogram annually and not be otherwise treated until something changes. 

Now that I know that my PVCs decrease when I exercise, I went looking for papers that might make sense of that.  I found  “Significant reduction in the density of premature ventricular complex with ß-blocker medication in fast rate-dependent premature ventricular complex” by Park, Y.M., Kim, C.Y., Seo, J. et al.  Int J Arrhythm 21, 20 (2020)., in which they categorized PVC patients into 3 groups: those whose rate of PVCs went up with heart rate (fast rate-dependent PVC), those whose PVCs went down with heart rate (slow rate-dependent PVC), and those whose PVCs seemed independent of heart rate.  I believe that I fall into the second group, though I’ve not worn a 24-hour Holter monitor to determine this the way they did.  The take-away from the article is that it probably would not do any good for me to take beta-blockers (which I wasn’t planning to do anyway).

Aside: I found it rather amusing that the article in the International Journal of Arrhythmia used the wrong character for β-blockers, referring to them as ß-blockers (using the German Esszett character instead of the Greek lower-case beta). I don’t fault the authors (who were all Korean), but the reviewers and copy-editors of the journal, who should have caught the error.

Next Page »

%d bloggers like this: