%% SINAD for Signal with One Harmonic or One Harmonic Plus Noise
% Create two signals. Both signals have a fundamental frequency of \pi/4 rad/sample with amplitude 1 and the first harmonic of frequency \pi/2 rad/sample with amplitude 0.025. One of the signals additionally has additive white Gaussian noise with variance 0.05^2.
% Create the two signals. Set the random number generator to the default settings for reproducible results. Determine the SINAD for the signal without additive noise and compare the result to the theoretical SINAD.

n = 0:159;
x = cos(pi/4*n)+0.025*sin(pi/2*n);
rng default

y = cos(pi/4*n)+0.025*sin(pi/2*n)+0.05*randn(size(n));
r = sinad(x)
powfund = 1;
powharm = 0.025^2;
thSINAD = 10*log10(powfund/powharm)

%
% Determine the SINAD for the sinusoidal signal with additive noise. Show how including the theoretical variance of the additive noise approximates the SINAD.

r = sinad(y)
varnoise = 0.05^2;
thSINAD = 10*log10(powfund/(powharm+varnoise))

% Copyright 2015 The MathWorks, Inc.