Iam using the "Packet Input" block to receive data from an Arduinoa Due via serial connection. The device sends a binary data packet consisting of 13 bytes, where the first byte is a header and the other 12bytes represent 3 float values of 4bytes each.
I am using the following matlab function inside a matlab function block to reorder the 12 bytes and compose the 3 single values (single values are equivalent to float values here). Afterwards I cast this single to a double to work with it:
function singleV = uint8ToSingle(uintArray)
singleV = zeros(1,3);
uintArray_1 = zeros(1,4);
uintarray_2 = zeros(1,4);
uintarray_3 = zeros(1,4);
uintArray_1 = uintArray(1:4);
uintArray_2 = uintArray(5:8);
uintArray_3 = uintArray(9:12);
uint8Value_1 = typecast(uint8(uintArray_1),'single');
uint8Value_2 = typecast(uint8(uintArray_2),'single');
uint8Value_3 = typecast(uint8(uintArray_3),'single');
singleV_1 = double(uint8Value_1);
singleV_2 = double(uint8Value_2);
singleV_3 = double(uint8Value_3);
singleV = [singleV_1,singleV_2,singleV_3];
A simulink example is attached to this post.
Now to the problem: This algorithm seems to be working fine for almost all the time, but sometimes the numerical value I am extracting explodes from a range of ~[-2 , 2] to something in the order of >10^10, which causes problems for the rest of the program:
when you zoom in:
when you zoom out:
Does anyone know how to "remove the outliers" in real time or how to handle this problem otherwise?
Thanks in advance.