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

조회 수: 1 (최근 30일)
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?

답변 (1개)

Christopher Stapels
Christopher Stapels 2018년 2월 21일
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);

커뮤니티

더 많은 답변 보기:  ThingSpeak 커뮤니티

카테고리

Help CenterFile Exchange에서 Visualize Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by