Matlab NI USB 6009 Analog signal question

5 views (last 30 days)
Hi,
I have a test stand that sends out analog command signal ( voltage) every 0.5 seconds to a device and gets a response signal back from proximity sensor (voltage). I am using NI USB 6009 to get data from these two signals
I am trying to write a script to compare timing delay between command signal and repsonse signal in real time.
I am able to get signals and live plot of them. This is my scrip so far:
s = daq.createSession('ni');
ch2 = s.addAnalogInputChannel('Dev2', 'ai2', 'Voltage');
ch3 = s.addAnalogInputChannel('Dev2', 'ai3', 'Voltage');
ch2.TerminalConfig = 'Differential';
ch3.TerminalConfig = 'SingleEnded';
ch2.Range = [-10,10];
ch3.Range = [-10,10];
s.IsContinuous = true;
lh = s.addlistener('DataAvailable',@data);
hold ('on');
startBackground(s);
function data(src,event)
event.TimeStamps;
DemandVoltage = mean(event.Data(:,1));
ResponseVoltage = mean(event.Data(:,2));
plot(event.TimeStamps,event.Data)
if DemandVoltage> 3.5 %if Demand Voltage goes above -8.38 V give me time stamp
t1= event.TimeStamps
end
if ResponseVoltage>3 %%if Response Voltage goes above 0.035 V give me time stamp
t2= event.TimeStamps
end
end
I have tried to set up threshold voltage levels for 2 channels with " if statements" to get TimeStamps fro command and response, but I get exactly same timestaps fro two channels even though there is a time deference between them. I can see it on the plot (about 26 ms delay). I am attaching the plot. The idea is to have less than 60 ms delay between command and response signal. If it is greater than 60 ms, it means that something wrong with test sample.
How can I get theshhold timing?
Thank you.
Demand vs Respons Plot.jpg

Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!