MATLAB: From excel file 12-bit binary signed numbers to decimal values into matlab

dsp

Hello sir, I have 12-bit signed binary numbers in excel sheet ( two columns, inphase and quadrature phase components). How do I read the data into matlab and convert into Decimal values? I tried by using xlsread command but those binary numbers reading as decimal values ( it is giving in xEy format). Please help me…..
Thank you.

Best Answer

It's easier if you force matlab to read these numbers as text:
fid = fopen('data.csv');
text = textscan(fid, '%s%s', 'Delimiter', ','); %read as text
fclose(fid);
text = [text{:}]; %concatenate as a Nx2 cell array
digits = cellfun(@(t) t-'0', text, 'UniformOutput', false); %convert char vector of '0' and '1' into double vector of 0 and 1
numbers = cellfun(@(d) (-1)^d(1) * polyval(d(2:end), 2), digits); %convert binary digits into actual number
A more efficient algorithm would concatenate the text as a 3D char array and permute the dimensions at the end instead of processing cell arrays.