Instability of continuously acquired signals
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 592
- Forks
- 199
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 10
Description
import os
import time
import h5py
import nidaqmx
import numpy as np
from nidaqmx.constants import AcquisitionType, Edge
def main():
tmp_list = []
data = np.zeros(400)
with nidaqmx.Task() as task:
def callback(task_handle, every_n_samples_event_type, number_of_samples, callback_data):
# reader.read_many_sample(data, number_of_samples_per_channel=number_of_samples,timeout=0)
# print(data[0])
arr = task.read(number_of_samples_per_channel=number_of_samples)
tmp_list.extend(arr)
return 0
task.ai_channels.add_ai_voltage_chan("Dev1/ai0")
task.timing.cfg_samp_clk_timing(2e6, "", Edge.RISING, sample_mode=AcquisitionType.CONTINUOUS)
task.triggers.start_trigger.cfg_dig_edge_start_trig("/Dev1/PFI0", Edge.RISING)
task.register_every_n_samples_acquired_into_buffer_event(400, callback)
task.start()
input("Running task. Press Enter to stop.\n")
task.stop()
path = "D:/HGY_DATA/test_daq/xj1.h5"
os.remove(path)
with h5py.File(path, 'a') as file:
dataset = file.create_dataset(
'Imaging data_' + time.strftime("%Y_%m_%d_%H_%M_%S", time.localtime())
, shape=(0, 400)
, maxshape=(None, 400)
, dtype=np.float32
, chunks=(1, 400))
# 初始化创建字符串属性
dataset.attrs['Display Time'] = 0
# 追加写入新数据
current_len = len(dataset)
result_data = np.array(tmp_list).reshape((-1, 400))
dataset.resize(current_len + result_data.shape[0], axis=0)
dataset[current_len:] = result_data
print("over")
if __name__ == "__main__":
main()
Acquisition Card:NI PCIe-6361
Same environment, I use the Python API to continuously capture a standard sine wave from a signal generator. As a result, the captured data is not one cycle per line (the first amplitude value of each line is decreasing gradually), but it is normal if the data is captured using LabVIew. This question has been bothering me for days!!!
### Tasks
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Begin at the inline callback passed to register_every_n_samples_acquired_into_buffer_event and compare task.read(...) with the configured continuous timing and 400-sample event size. Reproduce with the NI PCIe-6361 and sine-wave setup; done means explaining or correcting the Python-side instability so captured rows match the expected signal, with behavior verified against LabVIEW.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- data, embedded-iot
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100