Linear Interpolation hard task

2 views (last 30 days)
Sheikh Mohammad Hussain
Sheikh Mohammad Hussain on 6 Jun 2021
Answered: Akira Agata on 18 Jun 2021
Ok so i will try to simplify my problem here and explain it. I have some sensor readings of power with corresponding time stamps. An example extract is shown below.
Timestamp Power
2021-04-01 15:07:19 0.0834
2021-04-01 15:08:02 0.0726
2021-04-01 15:08:42 0.0123
2021-04-01 15:09:24 0.0999
As you can see that the sensor data unfortunately has no fixed time interval between data readings.
My goal is to create a new table with a fixed time interval of one minute. In this table the Timestamp will go from 2021-04-01 00:00:00 till
2021-04-01 23:59:00 ( A total of 1440 readings for 24 hours). I have done this part already.
Now comes my question. How to i linearly interpolate the data above to match up with with my new time stamps? The challenge is also to automatically fill in the power readings with '0' on timestamps where no data was recorded.
What i mean to say is, the raw sensor data file dosent start its readings on 2021-04-01 00:00:00, but on a random time of the day,
like 2021-04-01 07:19:51. Thats why i want to automatically fill in power values with 0 when no data is recorded.
Calling out on all MATLAB heros out there to help me. Thanks alot in advance!
Note: I'll attach the real sensor file so you guys can get the feel of the problem.
  2 Comments
Sheikh Mohammad Hussain
Sheikh Mohammad Hussain on 6 Jun 2021
okay i am dumb. A simple solution worked for me:
Thanks alot anyways guys! you are a wonderful community!
Power_fixed = interp1(Time, Power, Time_fixed);
Power_fixed(isnan(Power_fixed))=0;
Walter Roberson
Walter Roberson on 6 Jun 2021
Consider using a timetable() object and retime()

Sign in to comment.

Answers (1)

Akira Agata
Akira Agata on 18 Jun 2021
As @Walter Roberson -san suggested, timetable and retime is the best solution. Please try the following:
TT = readtimetable('_sd_OPV_OPV_1_dp_2021_04_01.csv',...
'VariableNamingRule','preserve');
TT2 = retime(TT,'minutely','linear');

Categories

Find more on Data Import from MATLAB in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!