Learn · 02 of 02

Data & AI

How the model reads a recording, and how well it works.

How a heart recording becomes a decision: what a phonocardiogram looks like, what the model sees at every step, how it was trained and how well it works.

01 · Reading a phonocardiogram

The sound of a heart, drawn.

A phonocardiogram (PCG) is a recording of the sounds a heart makes. Every heartbeat has two main sounds: the first heart sound (The first of the two main heart sounds: a short burst that starts systole. S1 and S2 are the timing landmarks the model needs.) and the second heart sound (The second main heart sound. It ends systole and starts diastole.). The gap from S1 to S2 is The gap from the end of S1 to the start of S2, while the ventricles contract., and the gap from S2 to the next S1 is diastole. A heart murmur is an extra sound that fills part of the beat.

These are two real recordings from two children, each cut to a single beat and drawn on the same time scale. The model does not look at one beat like this: it reads a whole 5 s window, several heartbeats long, so it sees the pattern repeat and nobody has to find S1 and S2 for it first.

FIG. 1 · One heartbeat, with and without a murmur

0–800 ms from the start of S1

One heartbeat, with and without a murmurTwo real recordings of a single heartbeat on the same time scale, from 0 to 800 milliseconds after the start of S1. Top, recording 49568_MV, labelled no murmur: S1 120 ms, Systole 180 ms, S2 100 ms, Diastole 400 ms. Bottom, recording 9979_TV, labelled murmur: S1 153 ms, Systole 138 ms, S2 127 ms, Diastole 199 ms. The difference is in systole, between S1 and S2, drawn as a teal outline in the top beat and a hatched band in the bottom beat. In the top beat the sound there averages 0.03 of the beat's peak, a quiet gap. In the bottom beat it averages 0.30 of that beat's peak, and the dataset labels this child's murmur holosystolic (filling the whole systole).No murmurDataset label, not a model outputS1lub — mitral andtricuspid valvescloseSystoleventricles contract andpump blood outS2dub — aorticand pulmonaryvalves closeDiastoleventricles relax and refillQuiet gapthe gap between S1 and S2 stays quiet0100200300400500600700800ms+peak0−peakCirCor 49568_MV · mitral · no murmur0 ms = start of S1 · this beat lasts 800 msMurmurDataset label, not a model outputS1SystoleS2DiastoleMurmurfills the whole systole (holosystolic, as labelled in the dataset)0100200300400500600700800ms+peak0−peakCirCor 9979_TV · tricuspid · murmur grade III/VI0 ms = start of S1 · this beat lasts 618 ms

Scroll sideways to see the whole drawing

Murmur, dataset labelSystole of a beat labelled no murmurS1 and S2, dataset segmentation

Two real recordings, one heartbeat each: 49568_MV.wav (mitral site, labelled no murmur) above 9979_TV.wav (tricuspid site, labelled murmur, grade III/VI). The labels are the dataset’s, not a model output. Time is in milliseconds from the start of S1, and each trace is scaled to its own largest value, so compare shapes, not loudness. The part boundaries are the expert-reviewed S1/S2 segmentation of the dataset and the hatch is its murmur label. The sound is filtered to 20–500 Hz, the band the final system keeps.

The beats are at 5.42–6.22 s of 49568_MV and 3.66–4.28 s of 9979_TV. 8 samples at the loudest S1 peak of 9979_TV touch full scale. In murmur recordings the dataset’s S1/S2 borders can be less sharp, so some of the murmur can fall inside the S1 and S2 brackets. CirCor DigiScope Phonocardiogram Dataset, PhysioNet 2022, ODC-By 1.0.

02 · What the AI sees

Follow one window through the model.

Pick a real recording and one of its 5 s windows. Every figure is computed by the same feature code the classifier uses, so you see what the model sees. A recording from the test split was never used for training.

Dataset label: Murmur — holosystolic, grade III/VI. Test split, held out: never used for training. Dataset label, not a model output.

Loading window

FIG. 2 · 9979_TV.wav · window —. Time in seconds from the start of the file; amplitude in file units (full scale ±1). The vertical scale fits this window.

Step 1 of 5

The raw window

The classifier never looks at a whole recording at once. It cuts the recording into 5 s windows and starts a new window every 2.5 s, so each window holds several heartbeats. This plot is the window you chose, as the file stores it.

Window
—
Samples
—

Recordings from the CirCor DigiScope Phonocardiogram Dataset v1.0.3 (PhysioNet, ODC-By 1.0); the full citation is in the next chapter.

03 · How it was trained

Learning from labelled recordings.

The model learns from recordings that have already been labelled. Training reads only the training half of the data: it never opens a test file.

438

training patient IDs

1,432

training recordings

11,278

training windows

0.32

decision threshold

The data

The CirCor DigiScope Phonocardiogram Dataset, version 1.0.3, from PhysioNet under the Open Data Commons Attribution License 1.0. It holds heart sounds from 942 paediatric patients, recorded at up to four chest locations (aortic, pulmonary, tricuspid and mitral) at 4 kHz. A recording is labelled "murmur present" if a murmur was audible at that location and "murmur absent" if the patient has no murmur. Recordings of patients labelled Unknown are left out, and so are recordings of a patient with a murmur at a location where it was not audible.

  • Oliveira J, Renna F, Costa P, et al. The CirCor DigiScope Phonocardiogram Dataset (version 1.0.3). PhysioNet; 2022. doi:10.13026/tshs-mw03
  • Oliveira JH, Renna F, Costa P, et al. The CirCor DigiScope Dataset: From Murmur Detection to Murmur Classification. IEEE Journal of Biomedical and Health Informatics. 2021. doi:10.1109/JBHI.2021.3137048
  • Pollard T, Moody BE, Lehman L, et al. PhysioNet as a global platform for biomedical research. Nature Health. 2026. doi:10.1038/s44360-026-00096-z

The recipe

  1. Split by child, 50/50 (seed 3641). Half of the children train the model and the other half are held out. No child has recordings on both sides.
  2. Make windows. Every training recording is cut into 5 s windows, a new one every 2.5 s, and each window becomes 26 numbers. A window gets the label of its recording.
  3. Compare candidates: 12 random forests (200 or 400 trees, three depth limits, two leaf sizes), scored with 5-fold cross-validation grouped by child.
  4. Pick the model: the forest with the best mean AUC in cross-validation, 400 trees in all.
  5. Fix the threshold on the out-of-fold training predictions with Youden's rule. It is set once and never changed for the offline baseline or the live result.
  6. Fit the winner on all training windows and save it.

FIG. 7 · The candidates

5-fold cross-validation, training half

Candidate models, scored on the training half by cross-validation grouped by child
ModelAUC, mean ± SD over foldsBalanced accuracy at 0.5Sensitivity at 0.5Specificity at 0.5
forest n=200 depth=none leaf=10.749 ± 0.0790.600.210.99
forest n=200 depth=none leaf=50.748 ± 0.0820.650.330.97
forest n=200 depth=8 leaf=10.733 ± 0.0910.680.570.79
forest n=200 depth=8 leaf=50.733 ± 0.0920.670.570.78
forest n=200 depth=16 leaf=10.752 ± 0.0790.630.290.98
forest n=200 depth=16 leaf=50.748 ± 0.0830.660.360.95
forest n=400 depth=none leaf=10.750 ± 0.0810.600.210.99
forest n=400 depth=none leaf=50.747 ± 0.0830.650.340.97
forest n=400 depth=8 leaf=10.733 ± 0.0900.680.570.80
forest n=400 depth=8 leaf=50.732 ± 0.0920.670.560.78
forest n=400 depth=16 leaf=1chosen0.754 ± 0.0790.640.300.97
forest n=400 depth=16 leaf=50.748 ± 0.0820.660.360.95
Why a random forest? It is cheap to run on a Raspberry Pi and its answer is easy to explain: every tree votes, and the share of trees voting murmur is the window's score; the confidence shown is the share agreeing with the chosen label. The choice is by cross-validated AUC alone; the table also shows sensitivity and specificity at a share of 0.5, which is not the threshold used. The choice, in the training's own words: forest n=400 depth=16 leaf=1 has the best mean AUC (0.754) of the 12 forests tried.
Window
5 s every 2.5 s
Band kept before any feature
20–500 Hz
MFCCs
13 coefficients, 26 mel bands
Frame and step
32 ms and 16 ms
Numbers per window
26
Forest
400 trees, depth 16, at least 1 window per leaf, 649,328 nodes
Windows by class
9,402 absent, 1,876 murmur
Decision threshold
0.32 (shown as 0.32)
Seeds
split 3641, cross-validation 0, forest 0
Trained
2026-11-18, model file 1ba195cf721f

04 · How well it works

The numbers: offline baseline and through the hardware.

The experiment compares two results for the same held-out files: the model's offline score, worked out in software during training, and the result when each file is played through the hardware and classified live. The model, features and threshold (0.32) are the same. The bench set has one recording from each of 160 held-out children, 80 with a murmur and 80 without. The test split has every recording of the held-out children: 1458 recordings from 436 patients.

Headline numbers

Offline baseline · software, from training

The model's score on the held-out files.

ROC AUC1 is perfect · 0.5 is chance
0.724160 recordings
SensitivityMurmurs flagged
0.7195% CI 0.61–0.80 · 57 of 80
SpecificityNo-murmur recordings cleared
0.6895% CI 0.57–0.77 · 54 of 80
AccuracyShare of recordings classified right
0.6995% CI 0.62–0.76 · 111 of 160
Confusion matrixTrue class against the model's answer
Confusion matrix, offline baseline, bench set
Predicted murmurPredicted absent
Murmur, 8057found23missed
Absent, 8026false alarm54cleared

Through the hardware · live

The same files, played and classified live.

Hardware pending

Not measured

Needs the speaker, coupler, silicone, microphone, front end and ADC.

Source · results/injected__bench.jsonBench set, n = 160Wilson 95% intervalsThreshold 0.32, fixed from training, never tuned for the live result

Every evaluation run

Every evaluation run, by run and set
Run and setAccuracySensitivitySpecificityROC AUCBalanced accuracyAlways-absent baseline
Offline baseline, bench set160 recordings, 80 murmur and 80 absent0.6995% CI 0.62–0.76 · 111 of 1600.7195% CI 0.61–0.80 · 57 of 800.6895% CI 0.57–0.77 · 54 of 800.7240.690.50
Offline baseline, test split1458 recordings, 252 murmur and 1206 absent0.7195% CI 0.68–0.73 · 1031 of 14580.7295% CI 0.66–0.77 · 181 of 2520.7095% CI 0.68–0.73 · 850 of 12060.7670.710.83
Simulated bandpass, bench set Simulated160 recordings, 80 murmur and 80 absent0.6495% CI 0.57–0.71 · 103 of 1600.7295% CI 0.62–0.81 · 58 of 800.5695% CI 0.45–0.67 · 45 of 800.7150.640.50
Through the hardware, bench setplayed and classified liveNot measured

Under each rate are its 95% A range that probably contains the true rate if we tested many more files like these. A wide range means few files. (a range that probably holds the true rate if we tested many more files like these) and the number of files behind it. The Wilson method assumes every file is independent.

Sensitivity by murmur grade

Sensitivity by murmur grade
GradeOffline baseline, bench setOffline baseline, test splitSimulated bandpass, bench set
Grade I/VI0.6195% CI 0.47–0.73 · 31 of 510.5895% CI 0.48–0.67 · 63 of 1090.6395% CI 0.49–0.75 · 32 of 51
Grades II/VI and III/VI0.8995% CI 0.73–0.96 · 25 of 280.8395% CI 0.76–0.88 · 117 of 1410.8995% CI 0.73–0.96 · 25 of 28
Other grades1.0095% CI 0.21–1.00 · 1 of 10.5095% CI 0.09–0.91 · 1 of 21.0095% CI 0.21–1.00 · 1 of 1

Murmurs are graded by loudness. Quiet grade I/VI murmurs are the hardest to detect. "Other grades" pools the few files with other grades, which are too few to say anything.

Confusion matrices

A confusion matrix counts every file by what it really is (rows) and what the model said (columns). The bench set's matrix is in the headline numbers above.

Offline baseline, test split

Confusion matrix, offline baseline, test split
Predicted murmurPredicted absent
Murmur, 252181found71missed
Absent, 1206356false alarm850cleared

Simulated bandpass, bench set Simulated

Confusion matrix, simulated bandpass, bench set
Predicted murmurPredicted absent
Murmur, 8058found22missed
Absent, 8035false alarm45cleared

Simulated bandpass against the offline baseline

Simulated

Each bench file was also scored in software after a model of a 20–500 Hz bandpass filter (simulated), with the same model and threshold as the offline baseline. The change is simulated minus the offline baseline. This models the filter only. It is not a measurement through hardware, and it is not the live result.

Change in each metric, simulated minus the offline baseline
MetricOffline baselineSimulatedChange95% interval of the change
Sensitivity0.710.72+0.01-0.03 to 0.06
Specificity0.680.56-0.11-0.19 to -0.05
Accuracy0.690.64-0.05-0.09 to -0.01
Balanced accuracy0.690.64-0.05-0.09 to -0.01
ROC AUC0.7240.715-0.009-0.033 to 0.015

The intervals are descriptive, from a paired bootstrap that resamples files together. The An exact test on the files whose decision changed, run once for the murmur files and once for the absent files. tests below are the inferential result: with fewer than about 10 files that changed their decision, an interval can exclude 0 while the exact test does not.

Files whose decision changed between the offline baseline and simulated bandpass, with exact McNemar tests
Files that areFilesChangedTo presentTo absentp, exact McNemarp, Holm-adjusted
Murmur files803211.0001.000
Absent files809900.0040.008

Honest caveats

  • Quiet murmurs are hard. In the offline baseline on the bench set, sensitivity is 0.61 for grade I/VI murmurs (31 of 51) against 0.89 for grades II/VI and III/VI (25 of 28). 85339_MV.wav is a recording the model misses: the share of trees voting murmur, averaged over its windows, is 0.19, below the threshold 0.32, so the answer is "Murmur absent". 9979_TV.wav is found only narrowly: its score is 0.323 against a threshold of 0.316, so a small change in the model could flip it.
  • Test-split intervals are optimistic. The test split has several recordings per child, but the interval maths treats every file as independent, so its intervals come out too narrow. The bench set has one recording per child and does not have this problem.
  • Accuracy alone flatters the test split. A model that always says "absent" already scores 0.83 there. The bench set is balanced, so its baseline is 0.50. Read sensitivity and balanced accuracy too.
  • Absolute accuracy may be a little optimistic. The design was refined while earlier experimental splits of the same labelled patients were in use, so it was not chosen blind to the final test half. This matters much less for the comparison between the offline baseline and the live result, which use the same files, the same model and the same threshold.
  • Live shows one window at a time. A live result is one 5 s window, so its error rates are the window-level ones, not the recording-level ones above. In the offline baseline on the bench set, window-level sensitivity is 0.67 and specificity is 0.62 over 1219 windows.
  • Simulated is not hardware. The simulated bandpass models a filter only, not the loudspeaker, the silicone layer, the microphone or the noise of real electronics. The live run through the hardware will measure those, and it is not measured yet.

Decision threshold 0.3156 in the model, shown as 0.32

05 · Where to look in the code

Where to look in the code.

pcg/features.py
The one feature path: windows, band-limit, RMS, MFCCs and their mean and standard deviation per window.
pcg/explain.py
Recomputes each stage of one window, for the step-through above.
pcg/labels.py
The label rule and the split by child.
pcg/train.py
Cross-validation, the model choice and the threshold.
pcg/model.py
The saved forest, each tree's vote, and the recording-level rule: the mean of the window vote shares.
pcg/evaluate.py
Scoring a run, offline or through the hardware, and comparing two runs.
hmi/export_web.py
Writes the data files this page is built from.
web/src/components/learn/
The components and the arithmetic behind this page, with tests.