-
Notifications
You must be signed in to change notification settings - Fork 0
/
csc2mat.m
67 lines (53 loc) · 1.38 KB
/
csc2mat.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
function [csc]=csc2mat(fname)
% Jeffrey Erlich, March 5, 2007
% jerlich@princeton.edu
%
fid=fopen(fname,'r');
if fid==-1
warning('bad filename');
[fname, pathname, filterindex] = uigetfile('*.Ncs', 'Pick an CSC file');
fid=fopen([pathname filesep fname],'r');
end
hd=fread(fid,16384);
hd=char(hd')
% go to end of file to get filesize.
% note, that this info is also in the header... maybe in future do a double
% check of the header info and the file size.
fseek(fid, 0, 1);
pos=ftell(fid);
fseek(fid, 16384, 'bof');
% the file is a 16K header with a bunch of CSC records afterwards.
% each CSC record is 64+32+32+32+512*16 bits = 1044 bytes
num_recs=(pos-16384)/1044;
if mod(num_recs,1)>0
warning('some bad records or sumptin')
return;
end
ts=zeros(num_recs, 1);
channel=ts;
sampFreq=ts;
nValSamp=ts;
data=zeros(num_recs, 512);
for recX=1:num_recs
ts(recX)=fread(fid, 1, 'int64');
channel(recX)=fread(fid, 1, 'int32');
sampFreq(recX)=fread(fid, 1, 'int32');
nValSamp(recX)=fread(fid, 1, 'int32');
data(recX,:)=fread(fid,512,'int16');
end
csc.ts=ts;
if numel(unique(channel))==1
csc.channel=channel(1);
else
warning('WIERD channel information')
csc.channel=channel;
end
if numel(unique(sampFreq))==1
csc.sampFreq=sampFreq(1);
else
warning('WIERD sampFreq infomation')
csc.sampFreq=sampFreq;
end
csc.nValSamp=nValSamp;
csc.data=data;
csc.hd=hd;