MATLAB Answers

0

I want to calculate the derivative of a channel. Can you suggest the best way to do so.

Asked by mac mcalpine on 19 Feb 2018
Latest activity Answered by Christopher Stapels on 21 Feb 2018
I am logging voltage on a solar powered IOT device. I would like to calculate the delta V to get an indication of charge rate.
The data is typically sent every 30 minutes, however not always. What would be the best way to calculate this and display in a line chart to view?

  0 Comments

Sign in to comment.

Tags

1 Answer

Answer by Christopher Stapels on 21 Feb 2018

One way would be to use an instance of the React App to test if field 2 has a value in it, perhaps "if field2 < 0". Then have the react call a MATLAB analysis. The analysis reads many values of field 2 and finds the last two non NaN entries, then calculates the slope. Finally, write the data to another channel, or another field in that channel. The field plot for the write channel will show you a visualization of the derivative data. Here is an example analysis you could use, you may have to play with the value of readPoints for your channel. Don't forget to edit the channel numbers and the API keys.
readChannelID = 1111;
writeChannelID = 2222;
fieldID1 = 1;
readPoints=50;
readAPIKey = 'XXXXXXXXXXXXXXXX';
writeAPIKey = 'xxxxxxxxxxxxxxxx';
%% Read Data %%
[data, times] = thingSpeakRead(readChannelID, 'Fields', fieldID1,'NumPoints',readPoints, 'ReadKey', readAPIKey);
i=0;
lastPoint=0;
%Get the last non empty entry in the data while ((lastPoint==0) (i>=readPoints))
if isnan(data(readPoints-i))
i=i+1;
else
lastPoint=data(readPoints-i);
lastTime=times(readPoints-i);
end
end
%Get the second to last non empty entry in the data
i=i+1;
firstPoint=0;
while ((firstPoint==0)|| (i>=readPoints))
if isnan(data(readPoints-i))
i=i+1;
else
firstPoint=data(readPoints-i);
firstTime=times(readPoints-i);
end
end
deriv=(lastPoint-firstPoint)/seconds(lastTime-firstTime);
thingSpeakWrite(writeChannelID,deriv,'writeKey',writeAPIKey);

  0 Comments

Sign in to comment.