The peak in the final sketch is the largest absolute calibrated voltage sample. fabs makes the convention explicit: both positive and negative excursions can supply the magnitude. The program divides that peak by RMS only when RMS voltage is above 10 V, otherwise returning zero. I can connect the familiar 1.41 example to an actual implementation now, while keeping the distinction between the largest sampled value and the signal's continuous peak.
I'm starting with the two pieces of the ratio. The peak describes the largest size of the signal in the interval being considered. RMS describes something different about the whole set of values. It includes what happens away from the peak as well. Putting them together gives a way to describe how large the peak is compared with that overall value. The ratio itself has no unit because the units cancel.
For an ideal sine wave, the relationship is neat. If its peak is A, the RMS value is A divided by the square root of two. Dividing the peak by that RMS value leaves the square root of two, about 1.414. This is a mathematical property of the ideal waveform.
I want another shape beside the sine wave so the number has some meaning. Imagine an ideal signal alternating equally between +1 and −1. Squaring either value gives 1, so the RMS value is 1. The magnitude of its peak is also 1. The crest factor is therefore 1. The difference from the sine wave isn't a calculation error. The two waveforms spend their time at different values.
Here's a second toy example using eight equally weighted samples: 0, 0, +2, −2, 0, 0, 0, 0. Their squares add to 8. Dividing by eight gives 1, so the RMS is 1, while the absolute peak is 2. The resulting ratio is 2. These are sample lists, not captured signals. They help me see that two sets can have the same RMS and different peaks.
That’s the part I like about a small numerical example. I can look at every value. The larger peak is there for only a small part of the list, so its relationship with the overall RMS changes. Suddenly crest factor feels less like an extra number on a display and more like a question about the shape of the signal. What is happening briefly that a single overall value might not show?
The peak and RMS come from the same stored collection and centred, calibrated voltage values. That answers two important interpretation questions without needing to guess from a variable name. It does not make sampling disappear: the highest point of the physical waveform could still fall between readings. The 10 V guard is also part of the result's meaning. A reported zero crest factor below that guard is an output choice, not a statement that the waveform has no peak.
Now I have to come back to the samples in the actual program. The real signal exists between readings as well as at the moments the ADC observes it. If the samples miss the highest point, the largest sampled value can be smaller than the true peak. Calling a variable peak doesn't make it a continuous observation of every moment. I need to understand how the sampling affects that estimate.
In this file, the RMS sum and absolute peak are taken from the same stored voltage collection after centring and calibration. I can therefore identify their common interval and scale. The remaining distinction is between the samples and the continuous physical signal: agreeing about the collection does not guarantee that its largest observation reached the true waveform peak.
The sign convention is explicit in fabs(v_actual). A negative excursion with a larger magnitude can replace the previous peak just as a positive one can. That’s a useful detail to explain beside the ratio, especially when considering a signal whose positive and negative excursions differ. The code is comparing magnitudes rather than choosing only one side of the waveform.
The familiar sine-wave result gives me a starting expectation for a suitable ideal case. It doesn't give me permission to treat other shapes as mistakes because their ratios differ. That would reverse the point of the measurement. I need to know what change in the waveform could produce a different answer before using the number to describe that change.
I'm keeping the two little examples beside the sine-wave relationship. Each one makes the operation visible: identify the peak, find RMS from the same values, divide. Then the practical questions become easier to ask. Which values did the software actually see, and what part of the signal could it have missed? That's more useful than only checking whether the final digits resemble 1.41.
The familiar ideal-sine ratio gives me a comparison to understand. The useful explanation follows both ingredients of the ratio and the actual rule that decides when it appears.