problem with sampling resolution while reading binary data with fread

15 views (last 30 days)
Hi
I have downloaded an ECG data from "physionet.org", aami3a.dat(the link is below). The site says it is recorded with 12-bit resolution (@720Hz). I used the following code to open and plot the waveform:
Fid=fopen('D:\SomeAddress\aami3a.dat','r');
Data=fread(Fid,'*int16');
fclose(Fid);
plot(Data');
The problem is it works!!! and I don't understand why!! while it is recorded with 12-bit precision, I'm reading that with 16-bit precision. How does 'fread' function handles this?! I mean I thought when I use '*int16' precision, the 'fread' function separates my binary data 16-bit-by-16-bit and treats each separation as a 16-bit integer and then converts that into decimal (but seems I was wrong). I also tried '*uint16' , '*bit16' precisions which show the same results. But when I use '*bit12' or '*ubit12' I receive a malformed shape which is definitely wrong. can anyone give me an explanation for this? Thanks in advance.

Accepted Answer

Walter Roberson
Walter Roberson on 21 Nov 2016
Data that is recorded at 12 bits is, by convention, stored in the 12 most significant bits of a 16 bit word.
  2 Comments
Dcember
Dcember on 21 Nov 2016
Edited: Dcember on 21 Nov 2016
Thanks. But if so, why I get wrong answer when I use 12-bit precision?
Walter Roberson
Walter Roberson on 21 Nov 2016
16 bits per sample are stored in the file. The bottom 4 bits of the 16 are 0.
Note: sometimes the values are stored with 16 bits but the top 4 (most significant) bits are the ones that are 0.
If the data is coming from an analog to digital convertor, then typically it would be the bottom 4 (least significant) bits that were 0, as that is the form that generalizes naturally to dropping in higher precision convertors, so that instead of the range changing with higher precision, the values get more precise. Having the data stored in the top 12 bits of 16 also generalizes more naturally to storing signed 2's complement values.
But when people design their own devices and protocols, it is not uncommon for them not to happen to think about these considerations, so you might see either way being used.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!