Skip to main content

pulse_transitions

This library implements a python version of the Pulse and Transition Metrics function category in Matlab.

Example Use Case

Second Order System

For the full example see examples/second_order_system.py.

import numpy as np
from scipy.signal import lsim
from scipy.signal import lti

from pulse_transitions import detect_edges
from pulse_transitions import detect_signal_levels
from pulse_transitions import get_edge_metrics


# Example: synthetic underdamped step response
def generate_step_response(t, damping=0.2, freq=10):
    # Second-order system parameters
    wn = freq          # Natural frequency (rad/s)
    zeta = damping        # Damping ratio

    # Transfer function: H(s) = wn^2 / (s^2 + 2*zeta*wn*s + wn^2)
    num = [wn**2]
    den = [1, 2*zeta*wn, wn**2]

    # Create the system
    system = lti(num, den)

    u = [0]*len(t[t<0]) + [1]*len(t[t>=0])
    t_shift = t-min(t)
    t_out, y_out, _ = lsim(system, U=u, T=t_shift)

    return t, y_out

# Generate data
t = np.linspace(-0.25, 1, 1000)
t_out, y = generate_step_response(t, freq=25/(max(t)))

threshold_fractions=(0.1, 0.9)

# Estimate levels (e.g. using histogram or endpoints)
levels = detect_signal_levels(x=t, y=y, method="histogram")
low, high = levels

# Detect edges
edge = detect_edges(t, y, levels=levels, fractional_thresholds=threshold_fractions)[0]

# Compute overshoot / undershoot
metrics = get_edge_metrics(x=t, y=y, fractional_thresholds=threshold_fractions, levels=levels)

Measuring one edge of a signal that has several

A trace that steps through several levels (a TDR trace has a new level after every discontinuity) has no single pair of levels. measure_edge takes the edge nearest a place you give, rising or falling, and measures it between the flat parts either side of it (or levels you pass):

from pulse_transitions import EdgeNotFound, measure_edge

try:
    measured = measure_edge(t, y, around=2.5, max_distance=0.2, fractional_thresholds=(0.2, 0.8))
except EdgeNotFound as error:  # also an IndexError and a ValueError
    print(error)
else:
    bottom, top = measured.levels
    print(measured.edge.start, measured.edge.end, measured.duration)

Edge.start and Edge.end are the first and the last threshold crossing in time order, so a falling edge crosses its high threshold at start.

Errors

Unknown keyword arguments raise TypeError rather than being ignored (thresholds= is fractional_thresholds=). Functions that look for an edge return [] or None when there is none; measure_edge raises EdgeNotFound.

Installation

pypi

pip install pulse_transitions

GitHub Release

pip install https://github.com/snhobbs/pulse_transitions/archive/refs/tags/<TAGNAME>.zip

From Source

git clone https://github.com/snhobbs/pulse_transitions/
pip install .

Matpulse Functions

Function Description Implemented?
midcross Mid-reference level crossing for bilevel waveform ☑️
statelevels State-level estimation for bilevel waveform with histogram method ☑️
falltime Fall time of negative-going bilevel waveform transitions ☑️
overshoot Overshoot metrics of bilevel waveform transitions ☑️
risetime Rise time of positive-going bilevel waveform transitions ☑️
settlingtime Settling time for bilevel waveform ☑️
slewrate Slew rate of bilevel waveform ☑️
undershoot Undershoot metrics of bilevel waveform transitions ☑️
dutycycle Duty cycle of pulse waveform ❌
pulseperiod Period of bilevel pulse ❌
pulsesep Separation between bilevel waveform pulses ❌
pulsewidth Bilevel waveform pulse width ❌

Background & Resources

HP Journal

There's an excellent description of the algorithms used by HP here.

Control Library

Metadata

Release files for pulse-transitions 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pulse-transitions 0.2.0
File Size Uploaded
pulse_transitions-0.2.0.tar.gz 459.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pulse-transitions 0.2.0
File Interpreter ABI Platform
pulse_transitions-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 496.0 kB

Release files / pulse_transitions-0.2.0.tar.gz

Download URL pulse_transitions-0.2.0.tar.gz
Size 459.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ffa3bdde1d1b264950076972d4bb4e1c6fabb7c2292c4d06295d9f784906e577
BLAKE2b-256 checksum
How to use checksums
129b4a5624af9372d0895ecb7d6699b8283345722c9ca7988f5120cb1a00f60f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

Release files / pulse_transitions-0.2.0-py3-none-any.whl

Download URL pulse_transitions-0.2.0-py3-none-any.whl
Size 36.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a32d84a17e4f2b85fdc68d3ceffcae790ea1ca9703d7bd6c4e964a738b145228
BLAKE2b-256 checksum
How to use checksums
bebd321319b4783a438b744eaf37b9675cb3c7db1d2ed50a298a5669168276c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page