Measuring Time when Light Intensity is lowest | ThingSpeak Apps | 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
Measuring Time when Light Intensity is lowest
No permission to create posts
April 2, 2018
8:54 pm
Avatar
applepie80
New Member
Members
Forum Posts: 1
Member Since:
April 2, 2018
sp_UserOfflineSmall Offline

I'm having trouble trying to develop a function for comparing the data points I have collected from my light intensity sensor in order to see the period of  time when there is the lowest activity of light. I'm not familiar with programming so I appreciate all the help I can get.  Essentially, I have a light intensity sensor measuring the quality of light in a room which will be uploaded onto the ThingSpeaks server. So far I have been able to retrieve data points in a table format using under the Matlab Analysis App,

readings = thingSpeakRead(ChannelID, 'Fields', 1,'NumPoints', 60, 'OutputFormat', 'table')

However, I want to create a function that can see when the light quality value is low for a few occurrences, mark that time and then subtract it from the next time the light quality is at a higher value to figure out the longest time that the light level stays low. I am unsure about how to do this using the above function to retrieve the data thus far. My general idea is to find the first low value with the corresponding time, search through the rest of the data until a high value is present again with the corresponding time and then subtract both times under a table format. Ultimately, I want to use this data  as a proxy to see how much light impacts me when I sleep by using light quality as a factor.

Does anyone have an idea of how this can be implemented or is there an easier way for me to obtain the results I want?

April 3, 2018
9:24 am
Avatar
cstapels
Moderator
Members


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

Neat project.  I wonder what you are using to measure light level.  In phase II of the experiment you could measure the spectrum too.

I would set up a timeControl that runs a MATLAB analysis daily, then writes your new values to another channel.

There is presently a code template called "Replace missing values in data" that will show you some of these techniques.

Use thingSpeakRead() to get the data, you can use 'numDays', 1 or 'NumMinutes', 600 depending on when you set up the TimeControl and how long you sleep. 

data=thingSpeakRead(ChID,'fields',1,'NumMinutes',600,'OutputFormat','timetable');

If you know the threshold for high and low data, you can use the find() function to separate the data.

threshold=YY;

lowIndex=find(data<threshold);

highIndex=find(data>=threshold);

If your channel writes occur at regular intervals, then the length of each index array will be proportional to the relative light and dark times.

Then you can write the data to your other channel for later study.

thingSpeakWrite(otherChID,'writeKey','XXXXXXXXXXXXXXXX','fields',[1 2], 'values',[length(lowIndex) length(highIndex)]);

 

If you want to calculate each duration separately, you can loop through the timetable that you read in the analysis and add to the duration until the index array is non continuous. ... if(lowIndex(i)+1==lowIndex(i+1))..add duration...

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
26 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 272

Vinod: 240

piajola: 95

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 8665

Moderators: 1

Admins: 2

Forum Stats:

Groups: 3

Forums: 14

Topics: 1600

Posts: 5760

Newest Members:

Team_mafia, icXu, emorphistechno, VTVMART, manimozhi, adamhebrew

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457