Derivation of channel-data | MATLAB | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
Derivation of channel-data
No permission to create posts
December 21, 2017
6:37 am
Avatar
Max Marder
New Member
Members
Forum Posts: 3
Member Since:
December 21, 2017
sp_UserOfflineSmall Offline

Hello,

I want to create a plot with the derivation of existing channel-data.

I send about every 5 minutes the amount of used energy to thingspeak. This is more or less a constant increasing value.

Watching these values in a graph is boring.

I want to display the derivation of these values in a graph.

Example:

Sending each time a value of totally used Kilo-Watt-Hours (kWh):

100,00 ... 100,01 ... 100,02 ... 100,03 ... 100,10 (using the microwave) ... 100,11 ... 100,12 ... 100,12 (main fuse blows) ... 100,12 ...

This should display a const horizontal line with a single peak (microwave) and going back to zero at the end.

I tried this but i does not work:

[energyData, time] = thingSpeakRead(readChannelID, 'Fields', energyFieldID, 'NumPoints', 100, 'ReadKey', readAPIKey);

dydx = diff(energyData(:))./diff(time(:)); % Cannot divide a double array by a duration array.

 

And it should be some kind of logarithm. I want to see small changes (e.g. kitchen-light with 60W) as well as big changes (e.g. microwave with 1500W).

 

Is there a easy way to do so?

Thanks a lot!

December 21, 2017
1:29 pm
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 210
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

Try converting to seconds:

dydx = diff(data(:))./seconds(diff(time(:)));

December 21, 2017
3:37 pm
Avatar
Max Marder
New Member
Members
Forum Posts: 3
Member Since:
December 21, 2017
sp_UserOfflineSmall Offline

Hy,

thanks a lot for the really fast response!

I guess its pretty close to a working solution...:

My code is:

[data, time] = thingSpeakRead(readChannelID, 'Field', fieldID1, 'NumPoints', 250, 'ReadKey', readAPIKey);

dydx = diff(data(:))./seconds(diff(time(:)));

thingSpeakPlot(time, dydx);

And the result is:

Error using thingSpeakPlot (line 59)

X must be same length as Y.

Error in Create a 2-D line plot 2 (line 25)

thingSpeakPlot(time, dydx);

 

Can you help me one more time?

December 26, 2017
10:01 am
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 210
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

Since dxdy is a difference, there is one less point in that array, compared to the time stamps. After you do the calculation, remove the first point in the time array.

I changed one of your variable names in the code below.

[data, times] = thingSpeakRead(readChannelID, 'Field', fieldID1, 'NumPoints', 250, 'ReadKey', readAPIKey);

dydx = diff(data(:))./seconds(diff(times(:)));

times(1)=[];  %remove one data point for plotting.  MATLAB arrays stary at 1, not zero.

thingSpeakPlot(times, dydx);

January 2, 2018
1:59 pm
Avatar
Max Marder
New Member
Members
Forum Posts: 3
Member Since:
December 21, 2017
sp_UserOfflineSmall Offline

PERFECT

Thanks a lot, nice christms gift 🙂

 

My code looks at the end like this:

%
% Energy - 2 days deviation log
%

readChannelID = xxx; % public!
fieldID = yy;

% numOfPoints = 750;
% numOfHours = 2;
numOfDays = 2;

readAPIKey = '';

 

%% Read Data %%

% [data, time] = thingSpeakRead(readChannelID, 'Field', fieldID, 'NumPoints', numOfPoints, 'ReadKey', readAPIKey);
[data, time] = thingSpeakRead(readChannelID, 'Field', fieldID, 'NumDays',numOfDays);

dydx = 100 * (diff(data(:))./seconds(diff(time(:))));
numOfPoints = numel(time); % Number of array elements
disp(['numOfPoints is: ''', num2str(numOfPoints), '''']);

time2 = time(2:numOfPoints,1);

whos; % DEBUGGING

%% Visualize Data %%

thingSpeakPlot(time2, dydx, 'LineWidth',1, 'Color','red', 'YScale','log');

 

January 2, 2018
3:36 pm
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 210
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

Thanks for posting the solution, I like your syntax better - it is more generic. (and happy new year too!)

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
14 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 261

Vinod: 196

piajola: 85

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

Newest Members:

harriettlf60, ShaToow, Aleftinfenny, DiaBentee, hugo11dom@gmail.com, Pisaruk530

Administrators: Hans: 387, lee: 457