Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • e64b067
  • /
  • processed
  • /
  • TDT_MATconvertBDH.m
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:db353c4fa7b90f4d746303e9c8b471acb32f1fb0
directory badge
swh:1:dir:58d640bfd8e188927e6f1b6e8ae0d2fbc1bbee9d

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
TDT_MATconvertBDH.m
%% tdt2mat.m %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Import data from TDT system recording into Matlab structure
%
% S = tdt2mat(filepath, tank, blk, event)
%
% INPUTS
%   filepath: folder where tank is stored
%   tank: tank name
%   blk: block name
%   event: event name (ie 'Wave')
%
% OUTPUT
% data structure with fields
%     sampling_rate: (Hz)
%        timestamps: timestamp corresponding to each data row
%          channels: channel corresponding to each data row
%              data: data in rows, npoints columns
%           npoints: number of data points per timestampt
%
%
% SOURCE: http://jaewon.mine.nu/jaewon/2010/10/04/how-to-import-tdt-tank-into-matlab/
%
%
% Example usage:
%{
filepath = 'C:\TDT\OpenEx\Tanks'; 
tank = 'SETUPTANK';
blk = 'Test1-2';
event = 'Wave';

S = tdt2mat2(filepath, tank, blk, event)
%}
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function S = tdt2mat(filepath,event)

filename = dir(filepath)
filename=filename(5).name;
filename=strsplit(filename,'.');
filename=filename{1};
tev_path = [filepath filesep filename '.tev'];
tsq_path = [filepath filesep filename '.tsq'];

% open the files
tev = fopen(tev_path);

% count number of tsq records (40 bytes/record)
tsq = fopen(tsq_path); fseek(tsq, 0, 'eof'); ntsq = ftell(tsq)/40; fseek(tsq, 0, 'bof');

% read from tsq
data.size      = fread(tsq, [ntsq 1], 'int32',  36); fseek(tsq,  4, 'bof');
data.type      = fread(tsq, [ntsq 1], 'int32',  36); fseek(tsq,  8, 'bof');

data.name(:,1) = fread(tsq, [ntsq 1], '*char*1', 39); fseek(tsq, 9, 'bof');
data.name(:,2) = fread(tsq, [ntsq 1], '*char*1', 39); fseek(tsq, 10, 'bof');
data.name(:,3) = fread(tsq, [ntsq 1], '*char*1', 39); fseek(tsq, 11, 'bof');
data.name(:,4) = fread(tsq, [ntsq 1], '*char*1', 39); fseek(tsq, 12, 'bof');
data.chan      = fread(tsq, [ntsq 1], 'ushort', 38); fseek(tsq, 14, 'bof');
data.sortcode  = fread(tsq, [ntsq 1], 'ushort', 38); fseek(tsq, 16, 'bof');
data.timestamp = fread(tsq, [ntsq 1], 'double', 32); fseek(tsq, 24, 'bof');
data.fp_loc    = fread(tsq, [ntsq 1], 'int64',  32); fseek(tsq, 24, 'bof');
data.strobe    = fread(tsq, [ntsq 1], 'double', 32); fseek(tsq, 32, 'bof');
data.format    = fread(tsq, [ntsq 1], 'int32',  36); fseek(tsq, 36, 'bof');
data.frequency = fread(tsq, [ntsq 1], 'float',  36);

% TDT timestamps are in Unix time (seconds since 1/1/1970--
% http://en.wikipedia.org/wiki/Unix_time )

allnames = unique(data.name,'rows');
%exclude 'names' that contain ASCII Null character, these are special TDT
%codes.
allnames = allnames(all(double(allnames)~=0,2),:);


% Read A/D samples from tev
row = ismember(data.name, event, 'rows');

if sum(row) == 0
  disp(['Requested store name ''' event ''' not found (case-sensitive).'])
  disp('File contains the following TDT store names:');
  disp(allnames);
  error('TDT store name not found.');
else
  disp('File contains the following TDT store names:');
  disp(allnames);
end



table = { 'float',  1, 'float';
  'long',   1, 'int32';
  'short',  2, 'short';
  'byte',   4, 'schar'; }; % a look-up table
first_row = find(1==row,1);
format    = data.format(first_row)+1; % from 0-based to 1-based

S.storename = event;
S.sampling_rate = data.frequency(first_row);
S.timestamps    = data.timestamp(row);
S.channels      = data.chan(row);
S.filepath      = filepath;

fp_loc  = data.fp_loc(row);

if format ~=5
  nsample = (data.size(first_row)-10) * table{format,2};
  S.data = zeros(length(fp_loc),nsample);
  for n=1:length(fp_loc)
    fseek(tev,fp_loc(n),'bof');
    S.data(n,1:nsample) = fread(tev,[1 nsample],table{format,3});
  end
  S.npoints = nsample;
else % epoc_store event has no data, just timestamp, strobe, etc.
  S.data = data.strobe(row);
  S.npoints = 1;
  S.channels = repmat(1, size(S.data,1),1); %#ok
end


back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API