how to plot real time data, seperate different channel readings into different graphs and remove noise from a graph/ reading.
6 views (last 30 days)
Show older comments
The blow code does a live plot of 6 different channels. After acquisition, it draws a final plot of drag, side, yawn etc all on same graph....the graph also shows too much noise. I have tried the subplot for separating the final plots into different graphs but it returns errors.
i want the code to do a live plot of the drag, side, lift, yawn, roll and pitch on different graphs and the final plot should also show the drag, yawn etc on different graphs. i want to be able to log the final data(drag, lift etc against time) in a table format on an excel sheet after acquisition. I also want the graphs to eliminate noise.
can anyone help modify this code to do what is stated above or tell me what to do ? thank you in advance
% Create DAQ Session
s = daq.createSession ('ni');
s.IsContinuous = true;
s.Rate = 2000;
% Add channels
ch1 = s.addAnalogInputChannel('Dev1', 'ai0', 'Bridge');
ch2 = s.addAnalogInputChannel('Dev1', 'ai1', 'Bridge');
ch3 = s.addAnalogInputChannel('Dev1', 'ai2', 'Bridge');
ch4 = s.addAnalogInputChannel('Dev2', 'ai0', 'Bridge');
ch5 = s.addAnalogInputChannel('Dev2', 'ai1', 'Bridge');
ch6 = s.addAnalogInputChannel('Dev2', 'ai2', 'Bridge');
% Set channel properties
ch1.BridgeMode = 'Full';
ch1.ExcitationVoltage = 10;
ch1.NominalBridgeResistance = 350;
ch2.BridgeMode = 'Full';
ch2.ExcitationVoltage = 10;
ch2.NominalBridgeResistance = 350;
ch3.BridgeMode = 'Full';
ch3.ExcitationVoltage = 10;
ch3.NominalBridgeResistance = 350;
ch4.BridgeMode = 'Full';
ch4.ExcitationVoltage = 10;
ch4.NominalBridgeResistance = 350;
ch5.BridgeMode = 'Full';
ch5.ExcitationVoltage = 10;
ch5.NominalBridgeResistance = 350;
ch6.BridgeMode = 'Full';
ch6.ExcitationVoltage = 10;
ch6.NominalBridgeResistance = 350;
% specify legnths l, f, c1, c2 and n as seen on the force balance, refer
% to the diagram for better understanding
l = 30;
f = 20;
c1 = 25;
c2 = 30;
n = 30;
% specify the force coefficient per strain gotten during load cell
% caliberation
q = 200;
% Initialize Session 'UserData' property. During background acquisition,
% the 'recordData' callback function will keep appending data and
% timestamsps to the 'UserData' property.
s.UserData.Data = [];
s.UserData.TimeStamps = [];
% Add listener to 'DataAvailable' callback
lh1 = addlistener(s, 'DataAvailable', @recordData);
%% Start background acquisition
h = input('Enter the time of acquisition in seconds ');
disp('Acquiring data...');
startBackground(s)
% Increase or decrease the pause duration to fit desired acquisition time
pause(h)
stop(s)
%% Data extraction
% Extract data associated to each channel from the 'UserData' property.
chan1 = q * s.UserData.Data(:,1);
chan2 = q * s.UserData.Data(:,2);
chan3 = q * s.UserData.Data(:,3);
chan4 = q * s.UserData.Data(:,4);
chan5 = q * s.UserData.Data(:,5);
chan6 = q * s.UserData.Data(:,6);
drag = chan4 + chan5;
side = chan6;
lift = chan1 + chan2 + chan3;
rolling = (c2 * chan6) + (l * chan1) - (l * chan2);
pitching = (- c1 * chan4) - (c1 * chan5) + (f * chan1) + (f * chan2) - (2 * f * chan3);
yawning = (- n * chan4) + (n * chan5);
DAQ_1 = timetable(seconds(s.UserData.TimeStamps),drag,side,lift,rolling,pitching,yawning);
% Plot the entire acquired data
disp('Acquisition complete.');
figure
plot(DAQ_1.Time, DAQ_1.Variables)
xlabel('Time (s)')
ylabel('Force (N)')
legend(DAQ_1.Properties.VariableNames)
grid
% Clean up
delete(lh1)
clear s ch1 ch2 ch3 ch4 ch5 ch6 lh1
% Callback function
function recordData(src, eventData)
% RECORDDATA(SRC, EVENTDATA) records the acquired data, timestamps and
% trigger time. You can also use this function for plotting the
% acquired data live.
% SRC - Source object i.e. Session object
% EVENTDATA - Event data object i.e. 'DataAvailable' event data object
% Record the data and timestamps to the UserData property of the session.
src.UserData.Data = [src.UserData.Data; eventData.Data];
src.UserData.TimeStamps = [src.UserData.TimeStamps; eventData.TimeStamps];
% Live plotting
plot(eventData.TimeStamps, eventData.Data)
xlabel('Time (s)')
ylabel('Force (N)')
legend('ch1','ch2','ch3','ch4','ch5','ch6')
end
0 Comments
Answers (0)
See Also
Categories
Find more on National Instruments Frame Grabbers in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!