It's not who you are underneath. It's what you do that defines you.
How to import TDT Tank into MATLAB
Posted on Oct 4, 2010
1. Introduction
Tucker-Davis Technologies (TDT) is a company supplying signal processing systems. The signals recorded by their System 3 are stored in a database called TTank and can be read out later. TDT provides application programming interfaces (APIs) for TTank access through ActiveX DLLs and, in any development environment where ActiveX can be incorporated, users can make TTank applications easily.
For example, in MATLAB, you can create a TTank object with the following command. (You need to install OpenDeveloper package before typing the command.)
TTX = actxcontrol('TTank.X');
Then you can call any API functions listed in the OpenDeveloper reference manual with the object. (Some code examples are installed with the OpenDeveloper package in C:\TDT\OpenEx\Examples\TTankX_Example\Matlab) If you do not have a TDT system and just want to read TTank, then you can try out TDT NeuroShare Kit. I have not tested it , but I guess it works in a similar way.
However, sometimes it is not convenient to use particular DLLs to access data, since it means that you are bound to the MS Windows platform and cannot read your data without the TDT software package. Considering that you never know how long you will be able to get necessary technical support from the vendor, it is probably not a bad idea to learn how to read the binary format of the TTank directly.
2. Structure of TTank
A TTank can have many blocks. Each block contains data from one continuous recording and consists of 4 files: *.TBK, *.TDX, *.TEV, *.TSQ. Among them, it is TEV and TSQ that contain real data. The other two are used for an indexing purpose.
WARNING: Although TBK and TDK may not be absolutely necessary to retrieve data, most of TDT software becomes unable to read TTanks if those index files do not match with the records in TEV and TSQ. Therefore, DO NOT try to modify the contents of TTanks if you want to use TDT software (e.g., OpenSorter) on them. Rebuilding the index files requires technical support from TDT.
The TSQ file is a heap of 40-byte blocks called event headers (see the right figure). The first two and the last headers are special. The very first one is a EVTYPE_UNKNOWN(0x00000000) type and its size member has the total size of the TSQ file. The second and the last ones are a EVTYPE_MARK(0x00008801) type, and they have the start and the end time of the recording in their timestamp member, respectively. The other headers are all recorded user data and strictly ordered by time.
The structure of the event header is shown below. Those who are not familiar with C/C++ can refer to the following variable size information: unsigned short (2 bytes), long and float (4 bytes), double and __int64 (8 bytes).
Note that some structure members may not have a meaning in some event types. For example, fp_loc is valid only for the snip- and the stream-type event headers, because only those types have digitized samples which are separately stored in the TEV file. fp_loc indicates the file pointer location in TEV where the sample data points begin. In other event types, fp_loc is filled with meaningless numbers or is used for storing strobed codes. The table below summarizes this relationship.
For the stream type, sample values stored in TEV are voltages, if its format is float. However, if the format is one of the integer types (long, short or byte), raw sample values should be divided by the scaling factor, to be converted into voltages. The scaling factor is a customizable value specified in the data-saving macro. So you should refer to your RPvds circuit, to find this number.
3. tdtread.m: a MATLAB script reading TTank
The script shown below was tested with TDT System 3 Software v72 and OpenEx 2.12. However, using this script is at your own risk. I do not guarantee the accuracy of the results that you will get by using it. It may not work in the future if the binary format of TTank changes. (Note: It works fine with the latest v76 TDT software. 4/23/2013)
Before running the following code, you need to set the values of 4 variables on your own: tev_path, tsq_path, store_id1, and store_id2. The first two are the file paths to TEV and TSQ files, and the last two are the Store IDs of the strobed data and the stream data (e.g., ‘Evnt’ and ‘LFPs’), respectively.