Skip to content

Commit

Permalink
make DenoiseDat used by default
Browse files Browse the repository at this point in the history
  • Loading branch information
raltodo committed Feb 21, 2024
1 parent be000cf commit f69a1ac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion preProcessing/DenoiseDat.m
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function DenoiseDat(datFile,session,varargin)
indicesChunk1 = (1:chunkSize*nChannels)'; % these are the .dat file indices for the first chunk
nChunks = ceil(nSamples/chunkSize);
for chunk = 1:nChunks
indicesChunk = indicesChunk1+(chunkSize*nChannels)*(chunk-1);
indicesChunk = indicesChunk1+(chunkSize*nChannels)*(chunk-1); if indicesChunk(end)>nSamples*nChannels, indicesChunk(indicesChunk>nSamples*nChannels) = []; end
dataChunk = double(reshape(m.Data(indicesChunk),nChannels,[])); % Consider adding a constant if you're re-running denoising!
noise = zeros(size(dataChunk),'int16');
for i=1:nShanks
Expand Down
20 changes: 14 additions & 6 deletions preProcessing/preprocessSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function preprocessSession(varargin)
addParameter(p,'spikeSort',true,@islogical);
addParameter(p,'cleanRez',true,@islogical);
addParameter(p,'getPos',false,@islogical);
addParameter(p,'removeNoise',false,@islogical); % raly: noise removal is bad, it removes periods 20ms after (because of the filter shifting) a peak in high gamma. See ayadata1\home\raly\Documents\notes\script_NoiseRemoval_bad.m for details.
addParameter(p,'removeNoise',true,@islogical); % raly: new denoising method removing the first PCA component
addParameter(p,'runSummary',false,@islogical);
addParameter(p,'SSD_path','D:\KiloSort',@ischar) % Path to SSD disk. Make it empty to disable SSD
addParameter(p,'path_to_dlc_bat_file','',@isfile)
Expand Down Expand Up @@ -212,11 +212,6 @@ function preprocessSession(varargin)
cleanPulses(pulses.ints{1}(:));
end

% remove noise from data for cleaner spike sorting
if removeNoise
NoiseRemoval(basepath); % not very well tested yet
end

%% Get brain states
% an automatic way of flaging bad channels is needed
if stateScore
Expand All @@ -231,6 +226,19 @@ function preprocessSession(varargin)
end
end


% remove noise from data for cleaner spike sorting
if removeNoise
try EMGFromLFP = getStruct(pwd,'EMGFromLFP');
catch
EMGFromLFP = getEMGFromLFP(basepath,'noPrompts',true,'saveMat',true);
end

baseline = EMGFromLFP.timestamps(FindInterval(EMGFromLFP.data>quantile(EMGFromLFP.data,0.99))); % select the period of top 1% EMG activity as the denoising baseline
DenoiseDat(fullfile(basepath,[basename '.dat']),session,'baseline',baseline);
end


%% Kilosort concatenated sessions - Needs to be changed to probes, not shanks HLR 01/05/2023
if spikeSort
if nKilosortRuns>1 % if more than one Kilosort cycle desired, break the shanks down into the desired number of kilosort runs
Expand Down

0 comments on commit f69a1ac

Please sign in to comment.