%% SINAD from Periodogram
% Create a signal with a fundamental frequency of 1 kHz and unit amplitude, sampled at 480 kHz. The signal additionally consists of the first harmonic with amplitude 0.02 and additive white Gaussian noise with standard deviation 0.01. Set the random number generator to the default settings for reproducible results.
% Obtain the periodogram of the signal and use the periodogram as the input to sinad.

fs = 48e4;
t = 0:1/fs:1-1/fs;

rng default
x = cos(2*pi*1000*t)+0.02*sin(2*pi*2000*t)+0.01*randn(size(t));

[pxx,f] = periodogram(x,rectwin(length(x)),length(x),fs);
r = sinad(pxx,f,'psd')

% Copyright 2015 The MathWorks, Inc.