I'd love have a look at your app as well. My "experimental" app ( actually executed code) is pulling in pulses directly off a decoupling capacitor from a Teensy 3.6 and shaping it for display in MATLAB signal processing. (non soundcard route to experiment with higher A/D rates)
How are you building your app? Do you have a sample of the app so far?
Here is the MATLAB code
Code: Select all
%% Data collection %%
% time to run in seconds
t = 60*60;
% Communication port to the Teensy
COMPORT = 'COM8';
% Prepare file with current date and time
strname = ['data/' char(strjoin(string(fix(clock)), '-')) '.txt'];
fid = fopen(strname, 'w');
% Prepare serial communication
s = serial(COMPORT);
try
fopen(s);
catch %#ok<CTCH>
% Failed, properly because the handle was not closed, so we're freeing
% all the handles and trying again.
delete(instrfindall)
s = serial(COMPORT);
fopen(s);
end
% Using try/catch to safely let go of serial handle in case of trouble
try
% Prepare timer
tic
% Flush buffer
if (s.BytesAvailable > 0)
fread(s, s.BytesAvailable);
end
% Data acquisition
while (toc < t)
% Read value from buffer
val = fscanf(s);
% Save value to file
fwrite(fid, val);
end
catch err
% Deinitialize
fclose(s);
delete(s);
fclose(fid);
clear s t
rethrow(err);
end
% Deinitialize
fclose(s);
delete(s);
fclose(fid);
clear s t
%% Data processing %%
% Read from file
assert(exist('strname', 'var')==1, 'voltage_reader error: strname not set.');
if exist(strname, 'file') ~= 2
error(['voltage_reader error: File (strname=' strname ') doesn''t exist.']);
end
fid = fopen(strname, 'r');
try
% Ignore two first lines in case of data collection started in the middle of a transfer
output = textscan(fid, '%f', 'HeaderLines', 2);
output = output{1};
% Ignore last line in case of data collection ended in the middle of a transfer
output(end) = [];
catch err
fclose(fid);
clear fid
rethrow(err);
end
% Get file last modified date minus creation date (=the duration for the experiment)
listing = dir(strname);
fname = listing.name;
fname = fname(1:end-4);
time = (datenum(listing.date) - datenum(fname, 'yyyy-mm-dd-HH-MM-SS')) * 24*60; % in minutes
% Deinitialize
fclose(fid);
clear fid listing fname
% Make histogram (place into bins)
[n, xout] = histogram(output, 1000);
% Show data
figure;
bar(xout, n);
xlabel('Channel');
ylabel('Counts');
title(['Running time: ' int2str(time) ' minutes (' int2str(time*60) ' seconds)']);
% Show log(data)
figure;
n = log(n);
bar(xout, n);
xlabel('Channel');
ylabel('log(conts)');
title(['Running time: ' int2str(time) ' minutes (' int2str(time*60) ' seconds)']);
% Deinitialize
clear xout n time
%%
function [dnl,inl,misscodes] = dnl_inl_sin(y)
%DNL_INL_SIN
% dnl and inl ADC output
% input y contains the ADC output
% vector obtained from quantizing a
% sinusoid
% Boris Murmann, Aug 2002
% Bernhard Boser, Sept 2002
% histogram boundaries
minbin=min(y);
maxbin=max(y);
% histogram
[h,x] = histogram(y, minbin:maxbin);
% cumulative histogram
ch = cumsum(h);
% transition levels found by:
T = -cos(pi*ch/sum(h));
% linearized histogram
hlin = T(2:end) - T(1:end-1);
% truncate at least first and last
% bin, more if input did not clip ADC
trunc=2;
hlin_trunc = hlin(1+trunc:end-trunc);
% calculate lsb size and dnl
lsb= sum(hlin_trunc) / (length(hlin_trunc));
dnl= [0 hlin_trunc/lsb-1];
misscodes = length(find(dnl<-0.99));
% calculate inl
inl= cumsum(dnl);
figure
subplot(2, 2, 1);
plot(x, h);
xlabel('Channel');
ylabel('Counts');
title('Histogram');
subplot(2, 2, 2);
plot(1:length(dnl), dnl);
xlabel('Channel');
ylabel('DNL [LSB]');
title(['DNL = +' num2str(max(dnl),2) ' / ' num2str(min(dnl),2) ' LSB. No. of missing codes (DNL < -0.99): ' int2str(misscodes)]);
subplot(2, 2, 3);
plot(x, log(h));
xlabel('Channel');
ylabel('log(counts)');
title('Log-histogram');
subplot(2, 2, 4);
plot(1:length(inl), inl);
xlabel('Channel');
ylabel('INL [LSB]');
title(['INL = +' num2str(max(inl),2) ' / ' num2str(min(inl),2) ' LSB.']);
end