%% Compute Hilbert Spectrum Parameters of Signal
% Load and visualize a nonstationary continuous signal composed of sinusoidal waves with a distinct change in frequency. The vibration of a jackhammer and the sound of fireworks are examples of nonstationary continuous signals. The signal is sampled at a rate fs.

load('sinusoidalSignalExampleData.mat','X','fs')
t = (0:length(X)-1)/fs;
plot(t,X)
xlabel('Time(s)')

% The mixed signal contains sinusoidal waves with different amplitude and frequency values.
%
% To compute the Hilbert spectrum parameters, you need the IMFs of the signal. Perform empirical mode decomposition to compute the intrinsic mode functions and residuals of the signal. Since the signal is not smooth, specify 'pchip' as the interpolation method.

[imf,residual,info] = emd(X,'Interpolation','pchip');

%
% The table generated in the command window indicates the number of sift iterations, the relative tolerance, and the sift stop criterion for each generated IMF. This information is also contained in info. You can hide the table by specifying 'Display' as 0.
%
% Compute the Hilbert spectrum parameters: Hilbert spectrum hs, frequency vector f, time vector t, instantaneous frequency imfinsf, and instantaneous energy imfinse.

[hs,f,t,imfinsf,imfinse] = hht(imf,fs);

% Use the computed Hilbert spectrum parameters for time-frequency analysis and signal diagnostics.
% Copyright 2018 The MathWorks, Inc.