%% Compute Approximate Entropy of Signals
% For this example, generate two signals for comparison - a random signal xRand and a perfectly regular signal xReg. Set rng to default for reproducibility of the random signal.

rng('default');
xRand = double(randn(100,1)>0);
xReg = repmat([1;0],50,1);

%
% Visualize the random and regular signals.

figure;
subplot(2,1,1);
plot(xRand);
title('Random signal');
subplot(2,1,2);
plot(xReg);
title('Perfectly regular signal');

% The plots show that the regular signal is more predictable than the random signal.
%
% Find approximate entropy of the two signals.

valueReg = approximateEntropy(xReg)
valueIrreg = approximateEntropy(xRand)

% The approximate entropy of the perfectly regular signal is significantly smaller than the random signal. Hence, the perfectly regular signal containing many repetitive patterns has a relatively small value of approximate entropy while the less predictable random signal has a higher value of approximate entropy.
% Copyright 2018 The MathWorks, Inc.