-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain1ProcessDataFiles.m
More file actions
executable file
·74 lines (70 loc) · 3.05 KB
/
main1ProcessDataFiles.m
File metadata and controls
executable file
·74 lines (70 loc) · 3.05 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
68
69
70
71
72
73
74
% Main script to preprocess a raw data file off the server
% Parameters should be set by the MAIN_findWaves.m file, or uncomment the
% following lines to set parameters to run this script independently.
%
% % Maximum length of recording to store (in seconds). Files with longer
% % recording will be split into multiple files.
% maxFileLengthSecs = 5.5*60;
% % Flag to process single unit spikes if possible, otherwise will be
% % multi unit
% singleUnitFlag = 1;
% % Index of file to load (see list in switch statement below)
% fileIndex = 5;
% % Location to save output file in. To save in the current directory, just
% % use an empty string
% outputLoc = './NewTest';
%
% % Set up output file name
% outputFile1Prefix = strcat(outputLoc, '/LFPsHilbert', spikeType, 'Spikes_');
% Load LFPs and spikes from file
[LFPs, Fs, spikeMatrix, spikeFs] = ...
preprocessDataFile(inputFileName, singleUnitFlag);
% Set all bad channels to NaN, including corner reference electrodes
if exist('badChannels', 'var')
badChannels = unique([1 10 91 100 badChannels]);
else
badChannels = [1 10 91 100];
end
LFPs(badChannels, :) = NaN;
% Split data into multiple files if recording time is longer than
% MAXFILELENGTHSECS
if exist('maxFileLengthSecs', 'var')
maxFileLengthSteps = fix(maxFileLengthSecs*Fs);
end
if exist('maxFileLengthSecs', 'var') && size(LFPs,2) > maxFileLengthSteps
display('Initial recording too long, splitting into multiple files...')
% Store original variables before they are reduced to shorter
longLFPs = LFPs;
longSpikeMatrix = spikeMatrix;
origExperiment = experiment;
% Loop over each MAXFILELENGTHSECS segment that fits into the original
for isegment = 1:ceil(size(LFPs,2)/maxFileLengthSteps)
shortSegment = ((isegment-1)*maxFileLengthSteps + 1) : ...
min(size(longLFPs, 2), isegment*maxFileLengthSteps);
recordingLength = length(shortSegment)/Fs;
LFPs = longLFPs(:,shortSegment);
spikeMatrix = longSpikeMatrix(:,shortSegment);
% Save to a file with a letter appended to the experiment string
iexperiment = strcat(origExperiment, char((isegment-1)+'a'));
outputFile1Name = sprintf('%s%s-%d.mat', outputFile1Prefix, ...
iexperiment, file);
save(outputFile1Name, 'experiment', 'file', 'recordingLength', ...
'LFPs', 'Fs', 'spikeMatrix', 'spikeFs', 'badChannels', 'outputFile1Name')
if exist('stimulusProtocol', 'var')
save(outputFile1Name, 'stimulusProtocol', '-append')
end
end
clearvars longLFPs longSpikeMatrix
else
% Save all variables to a file
recordingLength = size(LFPs,2)/Fs;
if exist('outputFile1Prefix', 'var')
outputFile1Name = sprintf('%s%s-%d.mat', outputFile1Prefix, ...
experiment, file);
save(outputFile1Name, 'experiment', 'file', 'recordingLength', ...
'LFPs', 'Fs', 'spikeMatrix', 'spikeFs', 'badChannels', 'outputFile1Name')
if exist('stimulusProtocol', 'var')
save(outputFile1Name, 'stimulusProtocol', '-append')
end
end
end