我正在从事的心电图生物识别项目:我使用Arduino + Olimex /EKG屏蔽,并将数据传输到MatLab。
我面临两个问题:
提前谢谢你。等待你的回复。
你好,巴德雷丁
发布于 2015-03-25 21:11:59
编辑免责声明,我从内存中编写了这段代码,所以它可能是错误的,提前道歉。
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);
end2.来回转换值非常简单。这是jsut的一些psuedocode
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 is uint8 upper_byte is 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;https://stackoverflow.com/questions/29264982
复制相似问题