%% Find the Conditional Temporal Moments of Data Measurements in a Timetable
% Real-world measurements often come packaged as part of a time-stamped table that records actual time and readings rather than relative times.  You can use the timetable format for capturing this data.  This example shows how tftmoment operates with a timetable input, in contrast to the data vector inputs used for the other tftmoment examples, such as examples.
% Load the data, which consists of a single timetable (xt_inner1) containing measurement readings and time information for a piece of machinery.  Examine the properties of the timetable.

load tfmoment_tdata.mat xt_inner1;
xt_inner1.Properties

%
% This table consists of  dimensions Time and the Variables, where the only variable is  x_inner1.
% Find the second and fourth conditional temporal moments (order = [2 4]) for the data in the timetable.

order = [2 4];
[momentT_xt_inner1,f] = tftmoment(xt_inner1,order);
size(momentT_xt_inner1)

% The temporal moments are represented by the columns of momentT_xt_inner1, just as they would be for a moment taken from a time series vector input.
% Plot the moments versus returned frequency vector f.

momentT_inner1_2 = momentT_xt_inner1(:,1);
momentT_inner1_4 = momentT_xt_inner1(:,2);

figure
subplot(2,1,1)
plot(f,momentT_inner1_2)
title("Second Temporal Moment")

subplot(2,1,2)
plot(f,momentT_inner1_4)
title("Fourth Temporal Moment")
xlabel('Frequency in Hz')

% Copyright 2018 The MathWorks, Inc.