calculating SNR for an A/D system

I am attempting to write a script to be used to characterize a system consisting of an AFE and an A/D by injecting a FS single tone sine wave (any freq) and collecting data at the A/D to then be analyzed for calculation of SNR, ENOB, THD, etc. (essentially the same parameters as the A/D but for the system level with the AFE included).
Fs=5000 N=4096
Problem : I found a few app notes online describing this test method but have yet been able to extract meaningful Pnoise values in the presence of the test tone. I would rather not have to make measurements with and without the tone if possible. Do I need to apply a window of some sort to remove the tone?
Code is :
%% FFT for Spectral Analysis and SNR Calculation
% Import some raw sample data that includes a full scale single tone.
Signal=CH1;
% Setup the sample rate and buffer size
Fs = 5000; N = 4096;
%%
% Calculate the DC component and remove it from the data.
AC_Sig=Signal-mean(Signal);
% Convert the raw data from A/D counts to voltage scaling
Sig_Volts=AC_Sig*2.5/65536; Pk_Pk=peak2peak(Sig_Volts); % Vrms=rms(Sig_Volts); V2rms=rms(Sig_Volts)^2;
power_timedomain=sum(abs(Sig_Volts).^2)/length(Signal);
% try using SPToolbox periodogram to measure the power of the test signal.
dft=spectrum.periodogram('hann'); % psd(dft,Sig_Volts,'Fs',Fs,'SpectrumType','onesided'); msspectrum(dft,Sig_Volts,'Fs',Fs,'SpectrumType','onesided');
v = axis; axis([v(1) v(2) -100 0]); % Zoom in Y set(gcf, 'Color', [1 1 1]);
% Find the discrete Fourier transform of the sample data.
Y = fft(Sig_Volts,N); %% % Compute the single-sided magnitude spectrum of Y
MagY =2*abs(Y(1:N/2)/N);
% Compute the power spectrum of Y
Py = MagY(1:N/2).^2;
Hpsd=dspdata.psd(Py(1:length(Py)),'Fs',Fs);
Psig=avgpower(Hpsd,[450 550]);
f = Fs/N*(1:N/2); figure1 = figure;
% Create axes axes1 = axes('Parent',figure1,'YScale','log','YMinorTick','on',... 'YMinorGrid','on',... 'YGrid','on',... 'XGrid','on'); ylim(axes1,[1e-10 1]); box(axes1,'on'); hold(axes1,'all');
% Create semilogy semilogy(f,Py(1:N/2));
% Create title title('Power Spectral Density');
% Create ylabel ylabel('Volts^2(RMS)/HZ');
% Create xlabel xlabel('Frequency (Hz)');
Pnoise=avgpower(Hpsd,[750 2500])-avgpower(Hpsd,[950 1050])-avgpower(Hpsd,[1450 1550]);
TotPwr=avgpower(Hpsd,[1 2500]);
% Calculate the SNR and SINAD
SNR = 10*log10(Psig/Pnoise);
SINAD = 10*log10((Psig+Pnoise)/Pnoise);
% Calculate the Effective Number of Bits normalized to the input amplitude :
ENOB = (SINAD-1.76+20*log10(2.5/Pk_Pk))/6.02;

Answers (0)

Tags

Asked:

on 5 Nov 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!