%% Frequency Bands and Spectral Metrics of Ball Bearing
% For this example, consider a ball bearing with a pitch diameter of 12 cm with 10 rolling elements. Each rolling element has a diameter of 0.5 cm. The outer race remains stationary as the inner race is driven at 25 Hz. The contact angle of the ball is 0 degrees. The dataset bearingData.mat contains power spectral density (PSD) and its respective frequency data for the bearing vibration signal in a table.
% First, construct the bearing frequency bands including the first 3 sidebands using the physical characteristics of the ball bearing.

FR = 25;
NB = 10;
DB = 0.5;
DP = 12;
beta = 0;
FB = bearingFaultBands(FR,NB,DB,DP,beta,'Sidebands',1:3)

% FB is a 14x2 array which includes the primary frequencies and their sidebands.
% Load the PSD data. bearingData.mat contains a table X where PSD is contained in the first column and the frequency grid is in the second column, as cell arrays respectively.

load('bearingData.mat','X')
X

% Compute the spectral metrics using the PSD data in table X and the frequency bands in FB.

spectralMetrics = faultBandMetrics(X,FB)

% spectralMetrics is a 1x43 table with peak amplitude, peak frequency and band power calculated for each frequency range in FB. The last column in spectralMetrics is the total band power, computed across all 14 frequencies in FB.
% Copyright 2019 The MathWorks, Inc.