Skip to content

Instantly share code, notes, and snippets.

@ximeg
Created January 16, 2026 19:59
Show Gist options
  • Select an option

  • Save ximeg/d6a2d156281ca2724530ae5b4ded0ac0 to your computer and use it in GitHub Desktop.

Select an option

Save ximeg/d6a2d156281ca2724530ae5b4ded0ac0 to your computer and use it in GitHub Desktop.
waveform thresholding and histogram building to characterize jitter
import pandas as pd
data_file = '../data1000/10us_ALEX_jitter.parquet'
df = pd.read_parquet(data_file)
df
thr = 2.5
df1 = df.query('rep <= 1000').query('channel == "Camera" and (140 <= time <= 160)').sort_values(['rep', 'channel', 'line', 'time'])
df1 = df1.reset_index()
prev_v = df1.groupby(['rep', 'channel', 'line'])['voltage'].shift(1)
mask = (prev_v < thr) & (df1['voltage'] >= thr)
cross = df1.loc[mask, ['rep', 'channel', 'line', 'time']] \
          .rename(columns={'time': 't_cross'})
cross
p = (
    ggplot(cross.assign(t_cross = lambda df: df.t_cross), aes(x='t_cross'))
    + geom_histogram(bins=20)
    + labs(x='Crossing time', y='Count')
    + theme_classic()
    + coord_cartesian(xlim = (72, 76))
    + theme(figure_size=(6, 1.5), axis_line_x = element_blank(), panel_grid_major_x= element_line(color = "darkgrey", linetype = "solid", size = 0.5))
    + xlab("time, µs")
)
p5, p95 = cross['t_cross'].quantile([0.05, 0.95])
width_90 = p95 - p5
width_90
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment