How to "Calibrate" data acquired in the live data acquisition example project.

7 次查看(过去 30 天)
I want the Liveaxes to display the modified sample data but am having problems understanding what math is required to change the recorded data to "calibrate it". I am using the function from the live data aqusition model from the Matlab examples pages and simulating a NI-6001 that is shifting between 10 to -10 V starting from 0. he example works up to when I try to modify the "Calibrateddate" variable.
The variable slopes is in the workspace and has the value 75.460709993827150. There is also an intercept variable I want to include but am unsure of how to add it also, I was wondering about using a loop to change the value of "Calibrateddata" but wasnt sure how to execute the idea.
Thanks.
function scansAvailable_Callback(app, src, ~)
%scansAvailable_Callback Executes on DAQ object ScansAvailable event
% This callback function gets executed periodically as more data is acquired.
% For a smooth live plot update, it stores the latest N seconds
% (specified time window) of acquired data and relative timestamps in FIFO
% buffers. A live plot is updated with the data in the FIFO buffer.
% If data logging option is selected in the UI, it also writes data to a
% binary file.
if ~isvalid(app)
return
end
[data,timestamps,triggertime] = read(src, src.ScansAvailableFcnCount, 'OutputFormat','Matrix');
%[data,timestamps,triggertime] = readwrite(src, src.ScansAvailableFcnCount, 'OutputFormat','Matrix');
Calibrateddata(:,1) = data(:,1);
slope = [slopes,1];
Calibrateddata(:,1) = mtimes(Calibrateddata,slope)
if app.LogRequested
% If Log data to file switch is on
latestdata = [timestamps, Calibrateddata]' ;
fwrite(app.TempFile, latestdata, 'double');
if timestamps(1)==0
app.TriggerTime = triggertime;
end
end
% Store continuous acquisition data in FIFO data buffers
buffersize = round(app.DAQ.Rate * app.TimewindowEditField.Value) + 1;
app.TimestampsFIFOBuffer = storeDataInFIFO(app, app.TimestampsFIFOBuffer, buffersize, timestamps);
app.DataFIFOBuffer = storeDataInFIFO(app, app.DataFIFOBuffer, buffersize, Calibrateddata(:,1));
% Update plot data
set(app.LivePlotLine, 'XData', app.TimestampsFIFOBuffer, 'YData', app.DataFIFOBuffer);
if numel(app.TimestampsFIFOBuffer) > 1
xlim(app.LiveAxes, [app.TimestampsFIFOBuffer(1), app.TimestampsFIFOBuffer(end)])
end
end
function Calibrateddata = storeDataInFIFO(~, Calibrateddata, buffersize, datablock)
%storeDataInFIFO Store continuous acquisition data in a FIFO data buffer
% Storing data in a finite-size FIFO buffer is used to plot the latest "N" seconds of acquired data for
% a smooth live plot update and without continuously increasing memory use.
% The most recently acquired data (datablock) is added to the buffer and if the amount of data in the
% buffer exceeds the specified buffer size (buffersize) the oldest data is discarded to cap the size of
% the data in the buffer to buffersize.
% input data is the existing data buffer (column vector Nx1).
% buffersize is the desired buffer size (maximum number of rows in data buffer) and can be changed.
% datablock is a new data block to be added to the buffer (column vector Kx1).
% output data is the updated data buffer (column vector Mx1).
% If the data size is greater than the buffer size, keep only the
% the latest "buffer size" worth of data
% This can occur if the buffer size is changed to a lower value during acquisition
if size(Calibrateddata,1) > buffersize
Calibrateddata = Calibrateddata(end-buffersize+1:end,:);
end
if size(datablock,1) < buffersize
% Data block size (number of rows) is smaller than the buffer size
if size(Calibrateddata,1) == buffersize
% Current data size is already equal to buffer size.
% Discard older data and append new data block,
% and keep data size equal to buffer size.
shiftPosition = size(datablock,1);
Calibrateddata = circshift(Calibrateddata,-shiftPosition);
Calibrateddata(end-shiftPosition+1:end,:) = datablock;
elseif (size(Calibrateddata,1) < buffersize) && (size(Calibrateddata,1)+size(datablock,1) > buffersize)
% Current data size is less than buffer size and appending the new
% data block results in a size greater than the buffer size.
Calibrateddata = [Calibrateddata; datablock];
shiftPosition = size(Calibrateddata,1) - buffersize;
Calibrateddata = circshift(Calibrateddata,-shiftPosition);
Calibrateddata(buffersize+1:end, :) = [];
else
% Current data size is less than buffer size and appending the new
% data block results in a size smaller than or equal to the buffer size.
% (if (size(data,1) < buffersize) && (size(data,1)+size(datablock,1) <= buffersize))
Calibrateddata = [Calibrateddata; datablock];
end
else
% Data block size (number of rows) is larger than or equal to buffer size
Calibrateddata = datablock(end-buffersize+1:end,:);
end
end
  4 个评论
Connor
Connor 2024-1-17
I think that I would have to change the value of "data" within the "scansAvailable" function but directly after it is read but am unsure if that is correct.
Connor
Connor 2024-1-18
I found out that I wasnt properlly calling the Variable from the other files Workspace into App Designer

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simultaneous and Synchronized Operations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by