arduino to matlab_analog signal input

29 Ansichten (letzte 30 Tage)
MINKYUNG KIM
MINKYUNG KIM am 7 Dez. 2018
Beantwortet: Isla Duffy am 7 Aug. 2021
Hi there:')
I have some problems with arduino adc and matlab plotting.
I am using arduino uno, r2018a and arduino supporting package.
I want to do...
input ecg analog signal from circuit -----> arduino adc --------> matlab and plot.
this is my simple code for adc
sport = arduino('COM5');
num = 500; % getting 500 digital samples
ecg = zeros(num,1);
figure
tic
for i = 1:1:num
ecg(i) = readVoltage(sport, 'A3');
pause(0.001); % meaningless on my try
plot(ecg);
end
tt = toc; %tatal time for getting samples
fs = num/tt; % calculate sampling freq
I want to ask
  1. fs = num/tt; It means, (sampling freq) = (sampling data num)/(total getting sample time); is it right?
  2. As a result, I get fs = 27.9Hz. It's too small because it mean I can control only 27.9/2 Hz according to Nyquist Theory, right?
  3. When I try input a sine signal with 10Hz, 1Vpp, 2Vdc to analog input pin using that code, I got this....(useless except for dc voltage)
  4. (second plot is a result of passing LPF with cutoff freq 60Hz)
  5. So, I want to increas sampling rate. So I tried the code below.
clear ecg
fs = 250; % sampling frequency (samplings per second)
mt = 5; % time for measurements (sec)
ind = 1;
nind = 1;
figure
tic;
while toc < mt
time(ind) = toc;
ecg(ind) = readVoltage(sport, 'A3');
plot(ecg);
drawnow;
% wait for appropriate time for next measurement
while( nind == ind )
nind = floor(toc*fs) + 1;
end
ind = nind;
howtime = toc;
end
So I think I can increase sampling rate to 250Hz.
But the problem is that I got datas as below,
1.56402737047898 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.56402737047898 0 0 0 0
no datas beweent two useful datas. So I cannot get proper shape of plot.
I found
For a 16 MHz Arduino the ADC clock is set to 16 MHz/128 = 125 KHz. Each conversion in AVR takes 13 ADC clocks so 125 KHz /13 = 9615 Hz. That is the maximum possible sampling rate, but the actual sampling rate in your application depends on the interval between successive conversions calls.
I cannot understand how the sampling freq go down to only 25Hz. It's useless for almost of the signals.
How can I deal with this situation
to get samples more frequently and
to get proper digital samples to plot the signal that I want?
I'm waiting for your advice, really appreciate in advance.
  1 Kommentar
Ran Chen
Ran Chen am 13 Dez. 2018
In the first code snippet, the way to calculate frequency might be not proper. The "pause" and "plot" will have a big effect on the measurement of time. Please note the function "readVoltage" will also take time to get the data. So we cannot really get the real frequency from this approach. Please also check the following link:

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Isla Duffy
Isla Duffy am 7 Aug. 2021
The arduino support package has a limited set of features. Upgrade the version or buy the extended support package.

Kategorien

Mehr zu Arduino Hardware finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by