;pro plot_adc_lin, ps = ps ;restore, 'LOG10-09-09B.sav' ; loads date, and data ; Data is [17, Nsamples] long. data[0, *] is the ADC input, while ; data[1:16, *] are the readouts. input = reform(data[0, *]) ;print, max(input) ;print, min(input) ;print, max(input) - min(input) ;print, (max(input) - min(input)) / 64. for n = 2, 16 do input = [input, reform(data[0, *])] ; transpose the data to make it line up with the index readout = transpose(data[1:16, *]) ; Now screen out everything above 4094, since that's basically ; high rail goodOnes = where(readout le 4094 and readout gt 0) input = input[goodOnes] readout = readout[goodOnes] ; Downward slope slopeStart = ( min(readout) - max(readout) ) / ( max(input) - min(input) ) ; Now infer back to zero to figure out the intercept: interceptStart = max(readout) - slopeStart * min(input) start = [slopeStart, interceptStart] result = MPFITFUN('MYLIN', input, readout, $ fltarr(n_elements(readout)) + 1., start, yfit = yfit, bestnorm = best, dof = dof, /quiet) residuals = yfit - readout inBin = histogram(input, reverse_indices = inds) nbins = n_elements(inBin) vals = fltarr(nbins) index= vals dev = vals for i = 0, nbins - 1 do begin if inBin[i] eq 0 then continue thisInd = inds[inds[i]:inds[i+1]-1] vals[i] = average(residuals[thisInd]) dev[i] = stddev(residuals[thisind]) index[i] = input[inds[inds[i]]] endfor step = nbins / 64. ;print, nbins !p.multi = [0, 1, 1] xrange = [0, max(index) - min(input)] yrange = [-10, 10] ;plot, (input - min(input)) / step, residuals, psym = 3, $ ; /xst, /yst, xrange = xrange, yrange = yrange,$ ; ytit="Residuals",xtit="ADC steps / 64",tit="ADC linearity ; test", charsize=1.5 plot, (index - min(input)), vals, psym = 3, $ /xst, /yst, xrange = xrange, yrange = yrange, $ ytit = "Output ADC Residuals from Linear", xtit ="Input ADC Setting", tit = "ADC Linearity Test", charsize = 1.5 ;oplot, (index - min(input)) / step, vals/inBin, color = 5 ;oplot, (index - min(input)) / step, smooth(vals / inBin, step, /Nan, /edge_truncate),$ ; psym=0, col=250 ;plot, (index - min(input)) / step, smooth(vals / inBin, step, /Nan, /edge_truncate),$ ; xrange = xrange, yrange = yrange / 2.5, psym =4 , /xst,/yst, $ ; xtit="ADC step / 64", charsize=1.5 !p.multi = 0 end