%% Calculate a Conditional Spectral Moment that is not Centralized
% By default, tfsmoment centralizes the moment as part of its calculation.  That is, it subtracts the sensor-data mean (which is the first moment) from the sensor data as part of the operation.  If you wish to preserve the offset, you can set the input argument Centralize to false.
%
% Load the data, which contains vibration measurements x and sample rate sr for machinery.  Calculate the 2nd moment (order = 2) both with centralization (default), and without centralization (Centralize = false). Plot the histograms together.

load tfmoment_data.mat x_inner1 sr_inner1
momentS_centr = tfsmoment(x_inner1,sr_inner1,2);
momentS_nocentr = tfsmoment(x_inner1,sr_inner1,2,'Centralize',false);

figure
histogram(momentS_centr)
hold on
histogram(momentS_nocentr);
hold off
legend('Centralized','Noncentralized')
title('Second Spectral Moment of x inner1 With and Without Centralization')

% The noncentralized distribution is offset to the right.
% Copyright 2018 The MathWorks, Inc.