% Ideal DFT method to analyze ADC spectral performance
% The ADC output codes must be coherently sampled and with inrange amplitude

%% load file containing ADC output codes 
[datafile, pathname] = uigetfile('*.*', 'Pick a raw data file');  %ask user to pick data file
if isequal(datafile,0) || isequal(pathname,0)
    disp('User pressed cancel, or invalid file')
    return;
end
y = load(fullfile(pathname, datafile));

%% perform DFT on acquired data
ydB=20*log10(abs(fft(y/length(y))));

figure;plot(ydB,'*-');

%% Obtain spectral parameters
[SNR,SDR,SNDR,SFDR,ENOB,THD]=spectraltest(y,10);