i am supposed to get ecg signal from the ecg text data however the code should be written following the protocol i am new in matlab so a little help please..

1. read the start bytes: 0x5A and 0xA5
2. As soon you detect this, read the all 17 bytes
3. Double check of these best just only have 0x5A, 0xA5 once. If there
is more you will need to discard the first 0x5A, 0xA5 as your starting
point and go back to step 1. If only once detected go to next step.
4. Read byte 5th and 6th for Ch1. Combine this two bytes: 5th byte for
the high byte and 6th byte for the low byte and convert it to decimal.
5. start the plot figure value versus time. X axes for the time; Y axes
for the value of that byte.
6. Repeat this until the whole data finish.
the data is
E0 06 14 02 7A 02 62 7A FE A5 5A 02 02 02 17 00
24 00 9D 00 21 00 0F 00 0C 0F A5 5A 02 03 01 F6
00 07 00 9C 00 21 00 0F 00 0C 0F A5 5A 02 04 01
E7 03 E9 00 9D 00 21 00 0F 00 0C 0F A5 5A 02 05
02 0C 03 FF 00 9D 00 21 00 0F 00 0C 0F A5 5A 02
06 02 22 01 9B 00 9D 00 21 00 0F 00 0C 0F A5 5A
02 07 02 19 00 2D 00 9D 00 21 00 0F 00 0C 0F A5
5A 02 08 01 F9 00 05 00 9D 00 21 00 0F 00 0C 0F
A5 5A 02 09 01 E6 03 97 00 9D 00 21 00 0F 00 0C
0F A5 5A 02 0A 02 06 03 FF 00 9D 00 21 00 0F 00
0C 0F A5 5A 02 0B 02 21 02 38 00 9D 00 21 00 0F
00 0C 0F A5 5A 02 0C 02 1D 00 3E 00 9D 00 21 00
0F 00 0C 0F A5 5A 02 0D 01 FF 00 07 00 9D 00 21
00 0F 00 0C 0F A5 5A 02 0E 01 E6 03 4B 00 9D 00
21 00 0F 00 0C 0F A5 5A 02 0F 02 00 03 FF 00 9D
00 21 00 0F 00 0C 0F A5 5A 02 10 02 1F 02 FC 00
9D 00 22 00 0F 00 0C 0F A5 5A 02 11 02 1F 00 53
00 9D 00 21 00 0F 00 0C 0F A5 5A 02 12 02 04 00
09 00 9D 00 21 00 0F 00 0C 0F A5 5A 02 13 01 E5
02 CB 00 9D 00 22 00 0F 00 0C 0F A5 5A 02 14 01
FA 03 FF 00 9D 00 22 00 0F 00 0C 0F A5 5A 02 15
02 1C 03 BC 00 9D 00 22 00 0F 00 0C 0F A5 5A 02
16 02 20 00 68 00 9D 00 21 00 0F 00 0C 0F A5 5A
02 17 02 09 00 0C 00 9D 00 21 00 0F 00 0C 0F A5
5A 02 18 01 E8 02 18 00 9D 00 22 00 0F 00 0C 0F
A5 5A 02 19 01 F5 03 FF 00 9D 00 22 00 0F 00 0C
0F A5 5A 02 1A 02 19 03 FF 00 9D 00 22 00 0F 00
0C 0F A5 5A 02 1B 02 22 00 94 00 9D 00 22 00 0F
00 0C 0F A5 5A 02 1C 02 0E 00 10 00 9D 00 22 00

2 Comments

You still did not include a question.
That code will not work as it goes line-by-line but nothing in the protocol you described is line-oriented.
the question is the protocol however there is 256 data in 1 second..

Sign in to comment.

 Accepted Answer

In particular look at "for" and "==" and hex2dec() and fprintf()

7 Comments

I have tried for3 days to get syntax to do just this
like for data= start to end
scand data
if data have a5 5a then
scan 17 byte
if data don't have a5 5a then search 5th and 6th data and display
and yet I have not come up with a running program!!
You will find it easier to read all the data at the same time, and convert it to numeric, and do the searching in the resulting vector.
fid = fopen('YourFile.txt');
datacell = textscan(fid, '%x');
fclose(fid);
data_vector = datacell{1}(:);
'FF'
'A5'
'5A'
'02'
'01'
'00'
'00'
'03'
'FF'
'00'
'39'
'00'
'37'
'00'
'36'
'00'
'36'
'0F'
the output is this however I now need to display the combined value of 3rd and 4th data after searching the A5 5A and I am struggling with the search loop in the file. I really appreciate your help.
is anything can be done to group two datas A5 5A in a single cell using the syntax to make A55A data_vector=datacell{1} (:);
The output would be in decimal, not in hex. The '%x' format that I indicated for the textscan() means to convert hex to decimal. Please recheck what is stored in data_vector . With the data you listed, I would expect the first value to be decimal 240 (E0)
There is an error with the execution of the code. i've attached the text file with it thank you..
I am sorry but it didn't worked and i've pointed the error..

Sign in to comment.

More Answers (0)

Products

Asked:

on 31 Oct 2013

Commented:

on 4 Nov 2013

Community Treasure Hunt

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

Start Hunting!