GPIO sync issues

Hi, I’ve discovered a strange issue with the GPIO sampling on the JS220 (up-to-date firm (1.3.0) and software (1.2.5)) and conducted the following experiment:
Measure a fast digital signal with both the analog voltage and the digital IN0 channels (parallel), which should yield a perfectly synchronous signal.
With lower sampling frequencies, however, I get an increasing delay of the analog signal (1ms @10kHz). At 1MHz, it’s not noticable (experiment with a signal generator outstanding).
This is the same for the UI as well as with the python driver package (timestamps evaluated).
Can you please advice where the delay might come from and how to correct it?

PS: the delay @1MHz is actually negative, i.e. the digital signal is lagging behind the analogue…

Hi @MLehmann - Thank you for the clear description and pictures!

Your Joulescope JS220 always samples at 2 MHz. It downsamples to 1 MHz on the instrument. When you set other sampling frequencies, the host performs downsampling by default. Downsampling consists of two phases:

  1. filter to prevent aliasing
  2. decimate by N

Filters often have group delay. You can review the downsampling code. The host software currently does not account for this group delay. Since the general purpose inputs are not filtered or downsampled, the analog signals get delayed somewhat proportional to the downsampling factor N.

The JS220 now implements sinc1 filtering on the instrument. The Downsampling section of the Joulescope JS220 User’s Guide has details. sinc1 filtering is the simple average of N samples, which introduces much less delay. You configure it like this:

Does this work better for your measurements?

Thanks a lot for the hint, it actually works much better this way, however, the flanges are less steep now with low sampling rates. I can see in the code that the delay is calculated but wonder, why there is still a visible delay at all and it’s not fully compensated. Would a delay compensation with the old algorithm not work the same way?
Also, how can I use the new downsampling method with the pyjoulescope driver in python?

Thanks, Martin

Hi @MLehmann -

Yes sinc1 filters are not as sharp in the frequency domain as the wideband filters. However, they have “no” delay (actually 1/2 sample in the downsampled domain) and preserve “average” on a sample-by-sample basis. Sinc1 filters are maximally flat (smooth on transitions) while wideband filters add “peaking” around sharp transitions.

The jsdrv_downsample structure does contain sample_delay that is properly computed. However, this value is not exposed outside the module and definitely not applied to data observed by applications. See downsample.h. So, we did part of the work to compensate for this delay.

You can request the sinc1 filter using the publish method and h/filter, like this:

import joulescope
import numpy as np

device = joulescope.scan_require_one()
device.parameter_set('sampling_frequency', 10_000)
device.open()
try:
    device.parameter_set('i_range', 'auto')
    device.parameter_set('v_range', '15V')
    device.publish('h/filter', 1)
    
    # replace with your code
    data = device.read(contiguous_duration=1.0)
    current = data[:,0]
    current_avg = np.mean(current[np.isfinite(current)])
    print(current_avg)
    
finally:
    device.close()