How to convert 16bit ADC data to fixed point two's complement representation?
14 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
vidyesh
2023-10-6
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!