Skip to content

New example voltage_acq_int_clk_plot_wfm.py does not behave as expected. #936

Description

@Emanuel-Lpz

Bug Report

This shipping example works great for slow sample rates; however, at high sample rates (for instance, 1MS/s), it takes up to 30 secs to display the graph. The bottleneck seems to be the timestamp generation: get_timestamps creates a timestamp object for every single sample, converting each timestamp to timedelta and calculating offsets is expensive.

Repro or Code Sample

Test with the original voltage_acq_int_clk_plot_wfm.py example, at sample rates.

Expected Behavior

Bottlebeck performance with this new example.

Current Behavior

Up to 30 seconds before data is properly displayed at high sample rates.

Possible Solution

I made some changes to the code, mainly on line 13, integrating NumPy. The behavior is much better, but probably you have a better solution:

import matplotlib.pyplot as plot
import numpy as np
import nidaqmx
from nidaqmx.constants import AcquisitionType, READ_ALL_AVAILABLE

with nidaqmx.Task() as task:
    task.ai_channels.add_ai_voltage_chan(physical_channel= "USB-6453/ai0")
    sampling_rate = 100000
    task.timing.cfg_samp_clk_timing(rate=sampling_rate, sample_mode=AcquisitionType.FINITE, samps_per_chan=100000)
    task.start()
    waveform = task.read_waveform(READ_ALL_AVAILABLE)

    time_offsets = np.arange(waveform.sample_count) / sampling_rate
    plot.plot(time_offsets, waveform.scaled_data)
    plot.xlabel("Seconds")
    plot.ylabel(waveform.units)
    plot.title(waveform.channel_name)
    plot.grid(True)
    plot.show()   

Context

This is not critical, but it would benefit the example code collection.

Your Environment

  • Operating system and version: Windows 11
  • NI-DAQmx version: 25Q3
  • nidaqmx-python version: 1.4.7
  • Python 3.11

AB#3775416

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions