forked from open-ephys/analysis-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MatData2Kwd.m
56 lines (47 loc) · 2.01 KB
/
MatData2Kwd.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
function MatData2Kwd(data,Output,Name,Fs)
%MatData2Kwd Function to convert matlab data to kwd. (Open Ephys GUI
% compatible file). Variable data must be a ch x samples matrix. For LFP
% signal models, generated in matlab and fluctuating from -1 to 1, we
% recommend a multiplication of 1000 for better visualization on LFP viewer.
%
%
% MatData2Kwd(data,Output,Name,Fs)
% data is a matrix of Channels x Record data; Output is the folder adress
% which .kwd file will be saved; Name is the string which will name your
% file; Fs is the frequency sample or sample rate of your matrix. We
% recommend to use the same sample rate as the options avaible in the
% Rhythm FPGA in Open Ephys GUI
%
% Example:
%
% Fs = 30000;
% dt = 1/Fs;
% for ch = 1:6
% data(ch,:) = 1000*sin(2*pi*4*(0:dt:1*60));
% end
%
% MatData2Kwd(data,'/home/yourDirectory/GUI/','SampleFile',Fs)
%
narginchk(4,4)
kwdfile = [Output Name '.kwd'];
internal_path = ['/recordings/0'];
h5create(kwdfile, [internal_path '/data'], ...
[size(data,1) size(data,2)], ...
'Datatype', 'int16');
h5writeatt(kwdfile,'/recordings/0','name',Name);
h5writeatt(kwdfile,'/recordings/0','start_time',0);
h5writeatt(kwdfile,'/recordings/0','sample_rate',Fs);
h5writeatt(kwdfile,'/recordings/0','bit_depth',(0.195));
h5writeatt(kwdfile, '/', 'kwik_version', 2);
this_block = int16(data);
h5write(kwdfile,'/recordings/0/data', ...
this_block);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% $Authors: Eliezyer Fermino de Oliveira and %
% Cleiton Lopes Aguiar %
% %
% $Data: June 13, 2016 %
% $Version: 1.0.0 %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%