Tag Info

New answers tagged

5

I recently had a similar task decoding 12-bit binary 24-channel electroencephalogram data files and found that bit shifting and masking with BitAnd are the way to go. The specific approach depends on file structure, endianness and channel number. In the case of this 'format 212' binary data file containing two interlaced signals, the following procedure ...


4

Change this {x_, y_} -> x + I y to {x_?NumberQ, y_?NumberQ} -> x + I y


2

It may be those newlines that are messing with you. How about a different approach? data = Import["imag-data.txt", "Table"]~Select~((# != {}) &) ({#1, I #2} & @@@ Drop[data, 1])~Partition~2 (* {{{0.933975, 0. + 2.39067*10^-16 I}, {-0.966082, 0. - 3.66569*10^-16 I}}, {{1.31581, 0. - 3.72881*10^-16 I}, {0.0535199, 0. - ...


5

If I am not mistaken the 212 format is storing two signals and each 3-byte group provides a 12-bit reading of that pair. Importing with Byte isn't too bad for this set: data = Import["http://physionet.org/physiobank/database/mitdb/100.dat", "Byte"] ~ Partition ~ 3 Then two helpers to parse it: twosComplement[a_, n_] := If[a < 2^(n - 1), a, a - 2^n] ...


1

Another variant.. twoscomplement[bin_] := If[First@bin != 1, FromDigits[bin, 2], BitOr[FromDigits[bin, 2], -2^12]] or to be safe.. twoscomplement[bin_List /; Length[bin] == 12] := If[First@bin != 1, FromDigits[bin, 2], BitOr[FromDigits[bin, 2], -2^12]]


3

This might work... however, it is very inefficient. Slightly faster using Import instead of BinaryReadList: binary= Partition[Import["http://physionet.org/physiobank/database/mitdb/100.dat", "Bit"], 12]; twoscomplement[bin_] := If[First@bin != 1, FromDigits[Rest@bin, 2], -FromDigits[Rest@bin /. {1 -> 0, 0 -> 1}, 2] - 1 ] output = ...


4

Since you requested performance I would avoid Import and DateList and use ReadList and AbsoluteTime. format = {Number, Character, Number, Character, Number, Number, Character, Number, Character, Number, Number, Word}; data = {AbsoluteTime[{#5, #3, #1, #6, #8, #10}], ##11} & @@@ ReadList["data.txt", format]; "data.txt" is of course your data ...


6

Import is very well able to handle this format. As a demonstration I use its nephew ImportString to deal with the few lines from your example: data = ImportString[ "28/04/2013 20:01:36.18 2.5013E-2 W 28/04/2013 20:01:36.26 2.5013E-2 W 28/04/2013 20:01:36.32 2.5013E-2 W 28/04/2013 20:01:36.35 2.5011E-2 W 28/04/2013 20:01:36.48 ...



Top 50 recent answers are included