我正在进行生物识别的ECG项目:我使用Arduino + Olimex ECG / EKG Shield并将数据传输到MatLab。
我面临两个问题:
提前非常感谢你。 等待你的回复。
亲切的问候, Badreddine
答案 0 :(得分:0)
编辑免责声明,我是从内存中编写此代码的,所以它可能是错误的,提前道歉
1.假设您的数据存储在某个数组data_array
中,每次我们获取样本时都会执行此类操作
data_array = [data_array, sample];
现在让我们在观察者中说我们只想查看20个样本。我们可以做这样的事情
num_visible_samples = 20; %define this somewhere outside your data aquisition loop
%gets new data somehow
data_array = [data_array, new_data_point];
%plots all data
plot(data_array);
length_data_array = length(data_array);
if (length_data_array >= num_visible_samples)
%this makes the plot window only show the current data point and the
%previous few data points, the Yaxis will automatically be scaled
xlim([length_data_array -num_visible_samples, length_data_array ]);
end
你可以做的另一件事(会更快)是只绘制你想要的样本数量
num_visible_samples = 20; %define this somewhere outside your data aquisition loop
%gets new data somehow
data_array = [data_array, new_data_point];
%plots all data
plot(data_array);
length_data_array = length(data_array);
if (length_data_array >= num_visible_samples)
%plots only the specific number of data points
plot(data_array(end-num_visible_samples,end));
%im not sure if you need to specify the axis, but i think you do
xlim([length_data_array -num_visible_samples, length_data_array ]);
else
plot(data_array);
end
2.来回转换值非常简单。这是一些伪问题
maxV = 5.0;
minV = 0.0;
num_of_quantized_values = 1024;
%this says how much the lsb of the adc is, basically we just divide our
%input range (0-5 volts) by our output range (0-1023) => 4.88mV
adc_resolution = (maxV - minV) / num_of_quantized_values;
将数字值转换回模拟电压,我们将分辨率乘以返回值
val_in_volts = adc_digital_reading * adc_resolution;
所以例如,说adc读取256
256 * 4.88mV = 1.25
<强> EDIT2 强> 由于atmega芯片通常具有10位ADC,因此您可以获得两个字节的数据adc数据。较低的8然后是较高的2.修复也不错,说我们有两个变量
lower_byte是uint8 upper_byte是uint8
所以我会这样做(根据实施方式有各种方法)
adc_digital_reading = bitor(bitshift(uint16(upper_byte ),8), uint16(lower_byte));
%mirrors this c code
%adc_u16 = (upper_byte << 8) | lower_byte;
重要的部分是将uint8类型转换为uint16,否则它将无法正常工作
你可以做到非常安全
adc_digital_reading = bitand(bitor(bitshift(uint16(upper_byte ),8), uint16(lower_byte)),1023);
%adc_u16 = ((upper_byte << 8) | lower_byte) & 0x03FF;