How to change analog output according to acquired analog input data from a NI DAQ
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello everyone, i'm a freshman of matlab. I just wrote a Script to accquire data from my DAQ device and to generate analog signal by the DAQ device. Here is my Script.
>>>>>>>>>>>>>>>>>>>>>>>>>>>> MY SCRIPT<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
clear all;
dq = daq("ni");
dq.Rate = 1000;
addinput(dq, "SimDev1", "ai0", "Voltage");
addoutput(dq, "Dev1", "ao0", "Voltage");
i=1;
while(1)
data(i,1) = read(dq, "OutputFormat", "Matrix");
if i >= 5000
return
end
output (data(i) >=2.0) = 5;
output (data(i) < 2.0) = -5;
%if data(i) >= 2.0
% output = linspace(1,1,1000)';
%else
% output = linspace(5,5,1000)';
%end
subplot(2,1,1)
plot(data);
ylabel("Voltage (V)");
title("Acquired Data");
xlim([0 5000]);
%ylim([-10 10])
subplot(2,1,2)
%newcolors = [0.8500 0.3250 0.0980];
%colororder(newcolors)
plot(i, output,'Marker','.','MarkerEdgeColor','r' );
%hold on
ylabel("Voltage (V)")
title("Output Data");
xlim([0 5000]);
ylim([-10 10]);
pause(0);
i=i+1;
end
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Finish<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Actually I want it to plot acquired data in Real Time and it seems work out fine.
Then I want it to generate analog signal according to data acquired.
For exp : When input > 2V , output = 5V. When input < 2V ,output = -5V. Sth like this.
But to make the output happen, i have to use "readwrite". Here is my trouble.
It seems that readwrite can only put at the behind of "output". But if there's no "read", Data wont be read and " output (data(i) >=2.0) = 5; " won't work.
I tried to use "read" then use "write" also failed.
Anybody can help me? Appreciate a lot.
2 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Analog Data Acquisition finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!