How to convert 16bit ADC data to fixed point two's complement representation?
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
vidyesh
am 6 Okt. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!