Go Down

Topic: Analogread on Matlab takes input 21 times per second. Very slow! ?? (Read 408 times) previous topic - next topic

mtk93

analog read takes input 21 times per second on Matlab instead of 10,000 times a second as mentioned on website.      Following is the code:

clear, clc
a = arduino('COM6','due');
Fs=88000;   % SAMPLING FREQUENCY = (2.2 X Fmax) X 2mics =88kHz
tic;
i=0;
    while toc<2 %% 2 sec sample
        i=i+1;
        v1(i)= readVoltage(a, 0);
        v2(i)= readVoltage(a, 7);     
    end

t1 = (0:length(v1)-1)/Fs;
t2 = (0:length(v2)-1)/Fs;
    %-----  Signal plot  --------%
figure(1);
subplot(2,1,1)
plot(t1,v1,'r')
title('Left Mic')
xlabel('Time (s)')
subplot(2,1,2)
plot(t2,v2,'r')
title('Right Mic')
xlabel('Time (s)')
----------
when entered >>i
i=42   i.e 41/2 = 21 times per second

pjrc

Well, what is "readVoltage" ?

My guess is it's a poorly designed function that sends a request and waits for a reply, suffering user-level Windows scheduling latency and USB framing latency twice, as well as the slow speed of serial if done over the programming port, plus the tiny amount of time the A/D converter actually requires to make the measurement!

Go Up