SINAD calculation in MATLAB I want to understand how SINAD is calculated. In MATLAB there is a funciton called SINAD and I would like to see if I can obtain &quot;the same&quot; answer as the inbuilt function does.
From the defintiion, I understand that it is the ratio of RMS of the signal to the noise and it takes all the values including the harmonics of the signal but the DC value.
So given the following code:
Fi = 2500;
Fs = 48e3;
N = 1024;
X = sin(2*pi*Fi/Fs*(1:N)); %Signal 
Y= 0.001*randn(1,N); % Noise
x=X+Y;              %Signal + Noise
SINAD = sinad(x,Fs)

Matlab gives  me the value of SINAD for this particular signal. I believe that DC value is the first input to the signal, so if I wanted to calculate it &quot;by hand&quot; I would calculate the RMS of all the samples but the first one like this:
A=X([2:end]);
B=Y([2:end]);
z=sqrt(mean(A.^2));
w=sqrt(mean(B.^2));
sinad=20*(log10(z/w))

The answers are close, usually within 0.5 but are not the same. Is what I am doing correct? If not, how would I reproduce the SINAD function?
Is what I am doing correct?

Yes

If not, how would I reproduce the SINAD function?

By replicating the exact same algorithm that the Matlab function uses.
Your answer is more correct, but you also &quot;cheated&quot;. You have access to the original sine and noise signals. sinad() ONLY has access to the sum of both. Hence it needs to do an estimation using windowing and Periodogramm analysis. That's less precise than calculating it directly from the original signals. If you really want to replicate what sinad() is doing, try an algorithm that only uses the combined noise+sine signal.