How to convert 16bit ADC data to fixed point two's complement representation?
이전 댓글 표시
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?
답변 (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.
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!