Path: news.mathworks.com!not-for-mail
From: "Vihang Patil" <vihang_patil@yahoo.com>
Newsgroups: comp.soft-sys.matlab
Subject: convert LSW and MSW to floating point
Date: Fri, 13 Apr 2012 14:28:18 +0000 (UTC)
Organization: Konem Solutions
Lines: 29
Message-ID: <jm9d62$hg1$1@newscl01ah.mathworks.com>
Reply-To: "Vihang Patil" <vihang_patil@yahoo.com>
NNTP-Posting-Host: www-00-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1334327298 17921 172.30.248.45 (13 Apr 2012 14:28:18 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 13 Apr 2012 14:28:18 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 413701
Xref: news.mathworks.com comp.soft-sys.matlab:764298

Hello
I am getting an array of values from an encoder which is attached to an Data Acquisition Device. The values that I get are in 2 arrays of LSW's amd MSW's
I want that the data to be converted in to floating point representation so that I can use it later for plotting data
I have also made a function to achieve this but the problem is that the function contains bin2dec() which is very slow and due to this my Data Acquisition device throws me an error of Buffer OverRun

function angle = encoder_angle(val)
%Function to calculate Angle from encoder
MSB = val(:,1);
LSB = val(:,2);

LSB = dec2bin(LSB,16);
MSB = dec2bin(MSB,16);
quad_angle = bin2dec([MSB LSB]); % this is slowing my DAQ device
[quad_angle] = TwosComplement(quad_angle, 32);
angle =  quad_angle*360/144000; % encoder PPR is 36000, my DAQ sends (36000* 4) 
angle = angle';

example:
Q1 =[0,65497;0,65503;0,65509;0,65517;0,65523;0,65529;1,1;1,7;1,13;1,21;1,27;]
angle = encoder_angle(Q1)
angle =

  163.7425  163.7575  163.7725  163.7925  163.8075  163.8225  163.8425  163.8575  163.8725  163.8925  163.9075


I need the above function to operate much faster.. 
Thanks

Vihang Patil