Skip to content

Commit

Permalink
small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
raltodo committed Nov 25, 2024
1 parent 19d32d0 commit 9d22944
Show file tree
Hide file tree
Showing 25 changed files with 255 additions and 248 deletions.
3 changes: 2 additions & 1 deletion SharpWaveRipples/DetectSWR.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [ripples] = DetectSWR(Channels, varargin)
function ripples = DetectSWR(Channels, varargin)

%DetectSWR - Detect Sharp Wave Ripple in epochs of continuous data.
%
Expand Down Expand Up @@ -1483,6 +1483,7 @@

end

% ------------------------------- Helper functions -------------------------------

function logAnalysisFile(AnalysisFileName, writePath)
% The purpose of this utility is to provide a record of analyses run by
Expand Down
2 changes: 1 addition & 1 deletion lfp/FilterLFP.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
% gamma [30 80]
% ripples [100 250]

% Copyright (C) 2004-2021 by Michaël Zugaro
% Copyright (C) 2004-2021 by Michaël Zugaro (C) 2021 by Ralitsa Todorova
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
Expand Down
14 changes: 13 additions & 1 deletion lfp/FindThetaCycles.m
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,16 @@
troughs = troughs(ok);
peaktopeak = peaktopeak(ok,:);
amplitude = amplitude(ok,2);
end


% ------------------------------- Helper functions -------------------------------
function peaks = FindLocalMaxima(signal)
%FindLocalMaxima - find local peaks
if isdmatrix(signal,'@2'),
iPeaks = FindLocalMaxima(signal(:,2));
peaks = signal(iPeaks,1);
return
end

d = [nan;diff(signal(:))>0];
peaks = strfind(d',[1 0])';
4 changes: 2 additions & 2 deletions lfp/WaveletSpectrogram.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
% -------------------------------------------------------------------------
% 'range' frequency range (in Hz) (default = all)
% 'resolution' desired frequency resolution (sub-octaves per octave, default = 0.05)
% 'step' desired step between successive windows (default = window/2):
% 'step' desired step between successive windows (default = window/2):
% output will be downsampled to this value
% 'interpolate' interpolate to create equidistant frequency bins instead
% of bins in power of 2 (default = false)
Expand Down Expand Up @@ -167,7 +167,7 @@

% loop through all scales and compute transform
for a1 = 1:J1+1
[daughter,fourier_factor,coi,dofmin]=wave_bases(mother,k,scale(a1),param);
[daughter,fourier_factor,coi,dofmin]=wave_bases(mother,k,scale(a1),param);
wave(a1,:) = ifft(f.*daughter); % wavelet transform[Eqn(4)]
end

Expand Down
53 changes: 27 additions & 26 deletions plotting/PlotIntervals.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
% =========================================================================
%

% Copyright (C) 2008-2013 by Gabrielle Girardeau & Michaël Zugaro
% Copyright (C) 2008-2013 by Gabrielle Girardeau & Michaël Zugaro,
% (C) 2023 by Ralitsa Todorova (graphics optimization for large numbers of intervals)
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
Expand All @@ -39,67 +40,67 @@
direction = 'v';
yLim = ylim;

if nargin < 1,
if nargin < 1
error('Incorrect number of parameters (type ''help <a href="matlab:help PlotIntervals">PlotIntervals</a>'' for details).');
end
if size(intervals,2) ~= 2,
if size(intervals,2) ~= 2
error('Incorrect list of intervals (type ''help <a href="matlab:help PlotIntervals">PlotIntervals</a>'' for details).');
end

% Backward compatibility: previous versions used the syntax PlotIntervals(intervals,style,direction)
parsed = false;
if (nargin == 2 || nargin == 3) && isstring_FMAT(lower(varargin{1}),'rectangles','bars'),
if (nargin == 2 || nargin == 3) && isastring(lower(varargin{1}),'rectangles','bars')
style = lower(varargin{1});
parsed = true;
end
if nargin == 3 && isstring_FMAT(lower(varargin{2}),'h','v'),
if nargin == 3 && isastring(lower(varargin{2}),'h','v')
direction = lower(varargin{2});
parsed = true;
end

% Parse parameter list
if ~parsed,
for i = 1:2:length(varargin),
if ~ischar(varargin{i}),
if ~parsed
for i = 1:2:length(varargin)
if ~ischar(varargin{i})
error(['Parameter ' num2str(i+1) ' is not a property (type ''help <a href="matlab:help PlotIntervals">PlotIntervals</a>'' for details).']);
end
switch(lower(varargin{i})),
case 'style',
switch(lower(varargin{i}))
case 'style'
style = lower(varargin{i+1});
if ~isstring_FMAT(style,'bars','rectangles'),
if ~isastring(style,'bars','rectangles')
error('Incorrect value for property ''style'' (type ''help <a href="matlab:help PlotIntervals">PlotIntervals</a>'' for details).');
end
case 'direction',
case 'direction'
direction = lower(varargin{i+1});
if ~isstring_FMAT(direction,'h','v'),
if ~isastring(direction,'h','v')
error('Incorrect value for property ''direction'' (type ''help <a href="matlab:help PlotIntervals">PlotIntervals</a>'' for details).');
end
case 'color',
case 'color'
color = lower(varargin{i+1});
if ~isstring_FMAT(color,'r','g','b','c','m','y','k','w') && ~isdvector(color,'#3','>=0','<=1'),
if ~isastring(color,'r','g','b','c','m','y','k','w') && ~isdvector(color,'#3','>=0','<=1')
error('Incorrect value for property ''direction'' (type ''help <a href="matlab:help PlotIntervals">PlotIntervals</a>'' for details).');
end
case 'alpha',
case 'alpha'
alphaValue = varargin{i+1};
if ~isdscalar(alphaValue,'>=0','<=1'),
if ~isdscalar(alphaValue,'>=0','<=1')
error('Incorrect value for property ''alpha'' (type ''help <a href="matlab:help PlotIntervals">PlotIntervals</a>'' for details).');
end
case 'ylim',
case 'ylim'
yLim = varargin{i+1};
if ~isdvector(yLim,'<'),
if ~isdvector(yLim,'<')
error('Incorrect value for property ''yLim'' (type ''help <a href="matlab:help PlotIntervals">PlotIntervals</a>'' for details).');
end
otherwise,
otherwise
error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help PlotIntervals">PlotIntervals</a>'' for details).']);
end
end
end

hold on;
xLim = xlim;
if strcmp(style,'bars'),
for i = 1:size(intervals,1),
if strcmp(direction,'v'),
if strcmp(style,'bars')
for i = 1:size(intervals,1)
if strcmp(direction,'v')
plot([intervals(i,1) intervals(i,1)],yLim,'Color',[0 0.75 0]);
plot([intervals(i,2) intervals(i,2)],yLim,'Color',[0.9 0 0]);
else
Expand All @@ -108,8 +109,8 @@
end
end
else
for i=1:size(intervals,1),
if strcmp(direction,'v'),
for i=1:size(intervals,1)
if strcmp(direction,'v')
dx = intervals(i,2)-intervals(i,1);
dy = yLim(2)-yLim(1);
rec(i) = patch(intervals(i,1)+[0 0 dx dx],yLim(1)+[0 dy dy 0],color,'LineStyle','none');
Expand All @@ -127,7 +128,7 @@
end
end

if nargout>0,
if nargout>0
varargout{1} = rec;
end

2 changes: 1 addition & 1 deletion plotting/RasterPlot.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
% the Free Software Foundation; either version 3 of the License, or
% (at your option) any later version.

if nargin==1,
if nargin==1
height = 1;
end

Expand Down
22 changes: 12 additions & 10 deletions plotting/semplot.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function varargout = semplot(x,y,color,smooth)
function varargout = semplot(x,y,color,smooth,solid)

%semplot - plot mean (line) +/- s.e.m. (shaded area) of a matrix "y"
% semplot(x,y,color,smooth)
Expand All @@ -12,32 +12,34 @@
% the Free Software Foundation; either version 3 of the License, or
% (at your option) any later version.

solid = false; % one day I will make this into an option
if ~exist('solid','var')
solid = false;
end

if nargin<2 || (nargin==2 && ischar(y)),
if nargin==2,
if nargin<2 || (nargin==2 && ischar(y))
if nargin==2
color = y;
end
y = x;
x = 1:size(y,2);
end

if ~exist('color','var'),
if ~exist('color','var')
color = [0 0 0];
end

if ~exist('smooth','var'),
if ~exist('smooth','var')
smooth = 0;
end

if size(y,2)~=length(x),
if size(y,2)~=length(x)
y = y';
if size(y,2)~=length(x),
if size(y,2)~=length(x)
error('Y should have one column for each element in X');
end
end

if isvector(y),
if isvector(y)
handles = plot(x,Smooth(y,smooth),'color',color);
if nargout>0, varargout{1} = handles; end
hold on;
Expand All @@ -54,7 +56,7 @@
y = Smooth(nanmean(y),smooth);
handles = fill(xx,yy,color);

if solid,
if solid
set(handles,'FaceColor',mean([color;1 1 1]),'edgeAlpha',0);
else % transparent
set(handles,'FaceAlpha',0.5,'edgeAlpha',0);
Expand Down
2 changes: 1 addition & 1 deletion reactivation/ActivityTemplates.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
%
% See also ReactivationStrength.

% Copyright (C) 2016-2022 by Michaël Zugaro, Ralitsa Todorova
% Copyright (C) 2016-2024 by Michaël Zugaro, Ralitsa Todorova
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
Expand Down
36 changes: 11 additions & 25 deletions spikes/DeconvolvePETH.m
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
function [deconvolved,t] = DeconvolvePETH(signal,events,varargin)

% [DeconvolvePETH] - [Compute a deconvolved version of PETH which removes the
% smoothing effects of the events' autocorrelogram]
%DeconvolvePETH - Compute a deconvolved version of PETH which removes the
% smoothing effects of the events' autocorrelogram
%
% INPUTS
% [signal] [signal to find events for]
% [events] [events for PETH]
% <options> optional list of property-value pairs (see table below)
% signal signal to find events for
% events events for PETH
% <options> optional list of property-value pairs (see table below)
% =========================================================================
% Properties Values
% -------------------------------------------------------------------------
Expand All @@ -30,15 +30,15 @@
% =========================================================================
%
% OUTPUTS
% [deconvolved] [deconvolved PETH]
% [t] [times of PETH]
% deconvolved deconvolved PETH
% t times of PETH

%
% SEE ALSO
%
% [PETH. This is using similar script as PETH with deconvultion]
% PETH
%
% [Ralitsa Todorova] [2021-2022]
% Copyright (C) 2021-2024 by Ralitsa Todorova
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
Expand All @@ -47,7 +47,7 @@

% default values:
durations = [-1 1];
nBins = [100];
nBins = 100;

argsToPassOn = {};
for i = 1:2:length(varargin)
Expand Down Expand Up @@ -85,7 +85,7 @@
[~,t] = PETH(signal,events,'durations',durations,'nBins',nBins,argsToPassOn{:});
[autoResponse,~] = PETH(events,events,'durations',durations*2,'nBins',nBins*2-1,argsToPassOn{:});
% make sure the binsize stays the same while you double the duration
[rawResponse,~] = PETH(signal,events,'durations',durations*2,'nBins',nBins*2-1,argsToPassOn{:});
[rawResponse,~] = PETH(signal,events,'durations',durations*2,'nBins',nBins*2-1,argsToPassOn{:});

autocorrelogram = sum(autoResponse);
rawPeth = sum(rawResponse);
Expand All @@ -102,17 +102,3 @@
% add the baseline to the final PETH
deconvolved = T \ rawPeth(round(nBins/2 + 0):round(nBins/2*3 - 1))' + const/length(events);
end

%% Old code:
% function deconvolved = DeconvolvePETH(rawPeth,autocorrelogram)
%
% Note: "rawPETH" should be of double the duration of the autocorrelogram for this to work/

% Example:
% [autoResponse,t]= PETH(events,events,'durations',durations,'nBins',nBins);
% [rawResponse,~]= PETH(signal,events,,'durations',durations*2,'nBins',nBins*2-1); % make sure the binsize stays the same while you double the duration
% deconvolved = DeconvolvePETH(sum(rawResponse),sum(autoResponse));
% plot(t,deconvolved);
%
% T = toeplitz([autocorrelogram(:); zeros(numel(rawPeth)-numel(autocorrelogram), 1)], [autocorrelogram(1), zeros(1, length(autocorrelogram)-1)]);
% deconvolved = T \ rawPeth(:);
Loading

0 comments on commit 9d22944

Please sign in to comment.