How to convert 16bit ADC data to fixed point two's complement representation?
15 views (last 30 days)
Show older comments
Hi all,
how to convert the 16bit ADC data to 1Q15 fixed point two's complement form in Matlab?
I came across some Matlab fourm qestion regarding this conversion using this function fixdt() but I did not get a clear idea about the conversion.
Can anyone tell how to do it in matlab?
0 Comments
Answers (1)
vidyesh
on 6 Oct 2023
Hi kalainan,
I understand that you want to convert your data to 1Q15 fixed point two's complement form.
You can use the following Code to do that. Variable ‘a’ will contain your original ADC data in 16 bit form.
c1=not(a-'0') % one's complement
d=1;
for k=numel(a):-1:1
r=d & c1(k);
c2(1,k)=xor(d,c1(k)); % c2 is two's complement
d=r;
end
[c2]
In case your data is in decimal, you can use function ‘dec2bin(x,16)’ to convert your data into 16 bit binary equivalent number first.
Note that ‘c2’ will have same number of bits as ‘a’. If your data is binary of length less than 16 you can append ‘0’s in front of ‘a’ and make its length equal to 16.
You can find more detailed documentation on ‘dec2bin’ function here:
I hope this answer helps.
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!