Skip to content

Instantly share code, notes, and snippets.

View mattgaidica's full-sized avatar
💭
Spending most my time at https://github.com/Neurotech-Hub

Matt Gaidica, Ph.D. mattgaidica

💭
Spending most my time at https://github.com/Neurotech-Hub
View GitHub Profile
@mattgaidica
mattgaidica / despike.m
Created October 2, 2019 21:31
Despikes neural data using linear interpolation
function dataDespiked = despike(data,Fs,spikeTs,spikeWidth)
% data: raw neural recording data
% Fs: sampling frequency
% spikeTs: spike timestamps in seconds
% spikeWith: width of average spike in ms to replace
% display a plot of the replaced spikes at the end
doDebug = true;
% convert spikeTs (in s) to samples
timePeriod = 3;
Fs = 1000;
oscillationFreq = [4;6;8];
oscillationOnOff = [0 2;1 3;1.5 2.5];
[lfp,t] = groundTruthLFP(timePeriod,Fs,oscillationFreq,oscillationOnOff);
timePeriod = 10;
Fs = 1000;
oscillationFreq = [4;10;30;75];
oscillationOnOff = [0,10;1,2;0,5;6,9];
oscillationAmp = [1;1;3;2];
[lfp,t] = groundTruthLFP(timePeriod,Fs,oscillationFreq,oscillationOnOff,oscillationAmp);
@mattgaidica
mattgaidica / groundTruthLFP.m
Last active February 8, 2019 15:02
Generates a ground truth local field potential
function [lfp,t] = groundTruthLFP(timePeriod,Fs,oscillationFreq,oscillationOnOff,oscillationAmp)
% timePeriod: LFP length in seconds
% Fs: sampling rate in Hz
% oscillationFreq: n x 1
% oscillationOnset: n x 2
% oscillationAmp: n x 1
% check for errors in inputs
if any(oscillationFreq > Fs / 2)
error('Insufficient resolution for high frequency oscillations');
filename = 'ExampleData.csv';
data = csvread(filename,1);
t = data(:,1);
velocityThresh = 10; % eye-balled this
minpeakdist = 100; % in samples
extractRange = -20:100; % padding not handled
t_compiled = t(1:numel(extractRange));
eyeHorizontal = rad2deg(data(:,2));
eyeVelocity = filterVelocity(diff(eyeHorizontal));
testVals = 0:1000000:100000000; % 0 to 100 million, step 1 million
nTests = numel(testVals);
runTest = true;
if runTest
tVals_uninit = [];
for iTest = 1:nTests
disp(iTest);
a = [];
tic;
@mattgaidica
mattgaidica / workon.m
Last active January 24, 2019 15:36
List or edit recently modified files
function workon(openArr)
% (list) >> workon
% (open) >> workon(1)
% (open) >> workon([2,3,6,14])
% (open) >> workon(1:7)
limitTo = 15; % # of files
listing = dir('**/*.m');
[~,idx] = sort([listing.datenum],'descend');
@mattgaidica
mattgaidica / sz.m
Created December 28, 2018 16:09
output a variable's size using >> sz
% output a variable's size using >> sz
w = whos;
findvar = clipboard('paste');
ii = strcmp({w.name},findvar);
if any(ii)
w(ii).size
else
disp(sprintf("\nNo variable '%s'\n",findvar));
end
clearvars('-except',w(:).name);
@mattgaidica
mattgaidica / spikesorter.rb
Last active December 22, 2018 18:31
SpikeSorter API call in Ruby
require 'rubygems'
require 'spikesorter-sx3'
# Get your account sid and auth token from spikesorter.com
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = SpikeSorterSX3::REST::Client.new(account_sid, auth_token)
spikes = @client.spikes
.extract(
function d1new = equalVectors(d1,d2)
% d1new is the 'dimension' of d2
nd2 = numel(d2);
if isscalar(d2)
nd2 = d2;
end
d1new = interp1(1:numel(d1),d1,linspace(1,numel(d1),nd2));