duty_cycle
Builtin index · Signal processing
result = duty_cycle(x, [level=], [hysteresis=0])
Input: x, level, hysteresis · Output: result
What it is
x: a length-N real vector, Signal, or Digital value (from to_digital, in which case its stored threshold is the default level, still overridable); keywords as for find_edges.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = duty_cycle(x, [level=], [hysteresis=0]) | x vector or Signalx: a length-N real vector, Signal, or Digital value (from to_digital, in which case its stored threshold is the default level, still overridable).level vector or Signal, optionalx: a length-N real vector, Signal, or Digital value (from to_digital, in which case its stored threshold is the default level, still overridable).hysteresis optional (default 0)not documented yet | result number | Returns a single number: mean high time over mean period, as a fraction in [0, 1], not a percentage — multiply by 100 for the figure a scope's front panel shows. The fraction is the composable form: duty_cycle(x) * pulse_period(x) is the high time. |
Examples
No documentation example calls this form yet. The Signal processing chapter is where one belongs.
How it works
duty_cycle(x, [level=], [hysteresis=]) -- mean high time over mean period. Returns a FRACTION in [0, 1], NOT a percentage, even though a scope's front panel says "50%". The reason is that this number's job is to be multiplied: duty_cycle(x) * pulse_period(x) is the high time, and that identity is silently wrong by 100x if this returns 50. overshoot/ undershoot below DO return percent, for the opposite reason -- those are read, not composed, and "0.05 overshoot" reads as 0.05%. Both are stated in the book table; the asymmetry is deliberate, not an oversight.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.