%% Frequency Bands and Spectral Metrics of Gear Train
% For this example, consider a simple gear set with an 8-toothed pinion on the input shaft meshing with a 42-toothed spur gear on the output shaft. Assume that the input shaft is driven at 20 Hz. The dataset motorSignal.mat contains vibration data for the gear mesh sampled at 1500 Hz.
% First, construct the gear mesh frequency bands using the physical characteristics of the gear set. Construct the frequency bands with the first 3 sidebands and specify the 'Domain' as 'order'.

Ni = 8;
No = 42;
FR = 20;
FB = gearMeshFaultBands(FR,Ni,No,'Sidebands',1:3,'Domain','order')

% FB is a 15x2 array which includes the primary frequencies and their sidebands.
% Load the vibration data and compute PSD and frequency grid using pspectrum. Use a frequency resolution of 0.5.

load('motorSignal.mat','C');
fs = 1500;
[psd,freqGrid] = pspectrum(C,fs,'FrequencyResolution',0.5);

% Now, use the frequency bands and PSD data to compute the spectral metrics.

spectralMetrics = faultBandMetrics(psd,freqGrid,FB)

% spectralMetrics is a 1x46 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 15 frequencies in FB.
% Copyright 2019 The MathWorks, Inc.