-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata2structGH.m
More file actions
67 lines (65 loc) · 2.3 KB
/
Copy pathdata2structGH.m
File metadata and controls
67 lines (65 loc) · 2.3 KB
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 [data]=data2structGH(cfg)
% This function takes raw LFP data together with SF (obtained from
% and returns a struct usable by field trip
% syntax: [data]=data2structGH(cfg)
%
% Mandatory input:
% ================
% cfg.raw_data = matrix of channels x timestamps
%
% Optional input:
% ===============
% cfg.SF = double, the sampling frequency in Hz. Default= 976.5625;
%
% cfg.ch_names = cell-array of strings with user defined names of the
% output channel names ('labels').
% Default = {'CH001','CH002'...}
%
% cfg.demean = 'yes' or 'no', whether to set the mean of the data to
% 0 (in ft_preprocessing). Default = 'yes'.
%
% cfg.detrend = 'yes' or 'no. Default = 'no'.
%
% cfg.resample = bool, 0 means no resampling. Default = 0 (don't
% resample).
%
% cfg.resamplefs = double, to which frequency resampling should be done.
% Default: the closest kHz to the original sf.
%
% Last updated 01/10/2017, by Golan Karvat
try TDT = cfg.raw_data;
catch fprintf ('Problems loading the raw data\n'); return; end
if isfield(cfg,'SF'); SF = cfg.SF; else SF = 976.5625; end %the default is 976.5625
if ~isfield(cfg,'resample'); cfg.resample = 0; end %the default is not to resample.
if ~isfield(cfg,'resamplefs'); cfg.resamplefs = round(SF/1000)*1000; end %the default resampling is to the nearest kHz.
if isfield(cfg,'ch_names')
data.label = cfg.ch_names;
else
for i=1:size(TDT,1)
if i<10
data.label{i,1}=['CH00' num2str(i)];
else
if i<100
data.label{i,1}=['CH0' num2str(i)];
else
data.label{i,1}=['CH' num2str(i)];
end
end
end
end
data.fsample=SF;
data.time{1,1}=[1:size(TDT,2)]/SF;
data.trial{1,1}=TDT;
data.nTrials=1;
data.nSamples=size(TDT,2);
data.hdr.FirstTimeStamp=0;
if cfg.resample
%Resampling
if ~isfield(cfg,'detrend'); cfg.detrend = 'no'; end
if ~isfield(cfg,'demean'); cfg.demean = 'yes'; end
[data] = ft_resampledata(cfg, data);
% data.fsample = cfg.resamplefs;
data.nSamples = length(data.trial{1});
end
% ensure the data is valid in FieldTrip:
data = ft_preprocessing([],data);