How do you measure the SNR of a sinewave in the frequency domain? (Assuming no filtering.)
Suppose: $$x(n) = s(n) + n(n)$$
Create the signal (nCycles of a sinewave) in MATLAB...:
sampleRate = 1024;
f0 = sampleRate/8;
nCycles = 11;
time = 0:1/sampleRate:nCycles/f0;
signal = sin(2*pi*f0*time);
Create the noise and scale it by the desired SNR...
SNR = 10;
noise = randn(size(signal));
% scale the noise to obtain the desired SNR
noise = noise / norm(noise) * norm(signal) / 10^(SNR/20);
x = signal + noise;
Calculate the resulting SNR (in the time domain):
actualSNR = 20*log10(norm(signal)/norm(x - signal));
disp(['SNR = ',num2str(actualSNR),' dB'])
Plot the noisy signal in time and frequency
subplot(2,1,1)
% plot the signal in time
plot(time,signal)
hold on; grid on
plot(time,x,'r')
% plot the noisy signal in frequency
NFFT = 4096;
X = fftshift(fft(x,NFFT));
X = X/max(abs(X));
f = sampleRate/2*linspace(-1,1,NFFT);
subplot(2,1,2)
plot(f,20*log10(abs(X)))
grid on;