MATLAB Answers

0

Mutiple Time series synchronization

Asked by sriram shastry on 14 Aug 2019
Latest activity Commented on by sriram shastry on 25 Aug 2019 at 5:46
Hi
I want to synchronize multiple time series
Can any suggest how to do it.
Thanks

  10 Comments

My goal is to get a common time series with text data. If for a time instance data is present then choose else skip particular data.look for other data if present on time then put that data.Like this I want to have a common time series for from different readtable.
Guillaume
on 15 Aug 2019
My goal is to get a common time series with text data
If it's textual data, I have no idea why you were asking about extrapolation. How do you extrapolate text?
Anyway, to synchronize several timetables you'd simply do it in a loop. I can show you how it's done once I understand what the inputs are. So far, you seem to have shown date variables, a timeseries or timetable needs date and data to be useful.
I'm not even sure what kind of data you have, so please state whether it's timeseries, timetable, table or something else.
Variable used are
Content.SERVO.servo_v4_uart.formattedDate
Content.SERVO.servo_v4_uart.Message
Content.EC.ec_uart.formattedDate
Content.EC.ec_uart.Message
Content.CR50.cr50_uart.formattedDate
Content.CR50.cr50_uart.Message
Content.INFO.firmware_FAFTSetup_INFO.formattedDate
Content.INFO.firmware_FAFTSetup_INFO.Message
Content.DEBUG.firmware_FAFTSetup_DEBUG.formattedDate
Content.DEBUG.firmware_FAFTSetup_DEBUG.Message
I want to synchronize all five readtable Content.
Say for example :
TT.Time = synchronize(Content.DEBUG.firmware_FAFTSetup_DEBUG.formattedDate,Content.SERVO.servo_v4_uart.formattedDate)
Then I want to use TT.Time which is a common time stamp from table1 and table2.
Expectation is if table1 message is content is present TT.Time then it should display text else skip and similarly for table2 as well and so on. Like this I want to generate common time stamp where I can display for a time vs response.
plot(TT.Time(x-3:x),x-3:x,'r-*'); grid on;title('servo-v4-uart');xlabel('TestTime[sec]');ylabel('Message');
text(TT.Time(x-3:x),x-3:x,Content.SERVO.servo_v4_uart.Message(x-3:x));
plot(TT.Time(x-3:x),(x-3:x),'k-*'); grid on;title('FAFTSetup-DEBUG');xlabel('TestTime[sec]');ylabel('Message');
text(TT.Time(x-3:x),(x-3:x),Content.DEBUG.firmware_FAFTSetup_DEBUG.Message(x-3:x));
Thank you!

Sign in to comment.

1 Answer

Answer by Guillaume
on 16 Aug 2019 at 9:47
 Accepted Answer

I think this does what you want:
contentfields = fieldnames(Content);
for fieldidx = 1:numel(contentfields) %iterate over each field of Content
structtable = struct2cell(Content.(contentfields{fieldidx})); %extract the structure within the field by converting it to cell array (avoids having to work out what its name is)
structtimetable = table2timetable(structtable{1}(:, {'Date', 'Message'})); %convert to timetable, only keeping Date and Message
structtimetable.Properties.VariableNames{1} = sprintf('Message_%s', contentfields{fieldidx}); %rename Message variable so we know where it came from
structtimetable = rmmissing(structtimetable); %remove invalid rows to avoid problems with synchronize
if fieldidx == 1
joinedtimetable = structtimetable; %1st time, create output
else
joinedtimetable = synchronize(joinedtimetable, structtimetable, 'union'); %subsequent times, synchronize. Choose whichever method is prefered
end
end
The main issue is that some (all?) of your tables contain rows with NaT which cause problem with synchronisation. You may want to investigate that. I've removed these rows here.

  11 Comments

Thanks ! but I was wondering where milliseconds count is gone ?
Guillaume
on 22 Aug 2019 at 11:20
Nowhere probably. If it's not visible, it's most likely because the default duration format doesn't display it. You can easily change the Format of the variable to whatever you want:
joinedtimetable.RowTimes.Format = 'hh:mm:ss.SSS';
Sure! Thanks

Sign in to comment.