Finding table elements, then converting into ASCII.

1 view (last 30 days)
Jorge Cantu
Jorge Cantu on 15 Jan 2016
Commented: Star Strider on 15 Jan 2016
Hi guys. I have a table (1 row with a few hundred entries) named rec1. I am trying to find the sequence 3,3,3,-3,-3,-3,-3,3,3,3 in the table. Then I skip ahead 128 entries, and display the next 64 entries in ASCII, which decodes a message for a user. This occurs 3 times in the table. I found these entries manually, but want to know how to use a loop to find the entries. This problem is all about decoding a message. The table is attached. Here is what I was initially trying: (In case you are confused, I also attached pam2letters.m which converts to ASCII).
% *rec1 columns 91 – 100 contains the preamble 1 for user 1. Preamble + 128 = 227. ...
... Display message of next 64 symbols, which is 227-291.
% *rec1 columns 293 – 302 contains preamble 2 for user 2.
% *rec1 columns 495 – 504 contains preamble 3 for user 3.
disp(pam2letters(rec1))
% x = pam2letters(rec1)
k = strfind(rec1, 3);
k2= strfind(rec1, -3);
S = rec1;
preamble1 = rec1(:,91:100);
for i = {S}
if S == preamble1
disp(S)
else
end
end
  1 Comment
dpb
dpb on 15 Jan 2016
I don't follow...I find that
>> rec1(91:100)
ans =
3 3 3 -3 -3 -3 -3 3 3 3
>>
yes, but don't see how to get from there to Preamble + 128 = 227?
As for finding the locations,
>> crec1=sprintf('%+d',rec1); % convert to char()
>> token='+3+3+3-3-3-3-3+3+3+3'; % the "preamble" token string
>> idx=strfind(crec1,token)
idx =
Columns 1 through 10
181 585 989 1393 1797 2201 2605 3009 3413 3817
>> crec1(idx(1):idx(1)+length(token)-1)
ans =
-1+1-1+1-1+3-1+1+3+3
>>

Sign in to comment.

Answers (1)

Star Strider
Star Strider on 15 Jan 2016
Following on my Answer to your previous Question about this:
D = load('Jorge Cantu rec1.mat');
rec1 = D.rec1;
T = [3,3,3,-3,-3,-3,-3,3,3,3]; % Target Sequence
Ix = strfind(rec1, T); % Find Start Index Of Target Sequence
Ix_shift = Ix + length(T) + 128 - 2; % Shifted Index To Start Of Sequence
for k1 = 1:3
MsgCoded{k1} = rec1(Ix_shift(k1):Ix_shift(k1)+63);
MsgDecoded{k1} = pam2letters(MsgCoded{k1});
end
MsgDecoded{:}
All the indices line up with what you say they should be, but when I call the function, the ‘decoded’ message is just noise. I may not be understanding your Question correctly, so I will let you experiment with this.
I will help as I can if I misunderstood something in your Question.
  2 Comments
Star Strider
Star Strider on 15 Jan 2016
That was essentially my reaction when I found that out from another post some time last summer, after I tried to use filter as the solution, and failed. (That solution was Accepted. My rather complicated approach was not even Voted.)
It’s one of MATLAB’s many coding ‘surprises’. I wonder if there are any others out there waiting to be discovered?
I guess the take-home lesson from all of this is ‘don’t assume that something won’t work’. The world will not come to an end if MATLAB throws an error (unless it’s somehow tied into the U.S. Air Force Strategic Air Command launch codes, but if that was true, with my code crashes alone, the Earth would long since have been reduced to a smouldering cinder).

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!