Skip to content

Commit

Permalink
Add uipickfiles.m for better gui functionality for file selection
Browse files Browse the repository at this point in the history
Also debug parsechans.m so that random trials are selected if that eventtype has
many more trials than other eventtpyes - this prevents dataoverflow in some recording situations.
  • Loading branch information
Matt Valley committed Apr 12, 2010
1 parent 53c43e5 commit e66949e
Show file tree
Hide file tree
Showing 4 changed files with 1,066 additions and 17 deletions.
18 changes: 7 additions & 11 deletions spectral analysis/parse_xchan.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
clear all;

% Define Global VARS
eventcodes = [1 2 3];
srate = 3051.76; %Hz
winsize = .5;
brthindx = [-10:1:20];;
Expand Down Expand Up @@ -35,22 +36,17 @@
end

% sequentially open all channels
[datafile, pathname] = uigetfile(...
'*.mat',...
'Please pick a wave files for each ',...
'MultiSelect', 'on');
cd(pathname);
datafile = datafile([2:32 1]); %fix uigetfile bug, 32chan
[pathname] = uipickfiles('refilter', '\.mat$', 'type', {'*.mat', 'MAT-files'},...
'prompt', 'Select all .mat files from MEA channels', 'output', 'cell');

for odor = 1:5;
eventcode = odor;
for n = 1:length(datafile); %n to number of channels
for odor = eventcodes;
for n = 1:length(pathname); %n to number of selected channels
if dead_chans(n)==1
continue
end
load(datafile{n}); % name of array must be "wave"
load(pathname{n}); % name of array must be "wave"
for x = 1:length(brthindx) %x to num of breaths
wave_segs(:,:,x,n) = parsechans(wave,events,breaths,srate,eventcode,brthindx(x),winsize);
wave_segs(:,:,x,n) = parsechans(wave,events,breaths,srate,odor,brthindx(x),winsize,eventcodes);
[S, t, f] = pmtm_cust(squeeze(wave_segs(:,:,x,n)),srate,maxfreq);
spec(:,:,:,x) = S; clear S; %spec = (time, freq, trial, breath)
disp('breath'); disp(x);
Expand Down
22 changes: 16 additions & 6 deletions spectral analysis/parsechans.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [wave_segs] = parsechans(rawwave,events,breaths,srate,eventcode,brth_num,winsize)
function [wave_segs] = parsechans(rawwave,events,breaths,srate,odor,brth_num,winsize,eventcodes)

%INPUTS:
% -- "events" matrix containing vectors with event time(in sec) 1st dim,
Expand All @@ -18,17 +18,27 @@
tdt_allevents(:,1) = (events(:,1)*srate);
tdt_allevents(:,2) = events(:,2);
tdt_breaths = round(breaths*srate);
sel_events = find(tdt_allevents(:,2) == eventcode);
sel_events = find(tdt_allevents(:,2) == odor);

for a = 1:5;
if max(sel_events,[],1) == size(events,1); % don't pick last trial (this leads to overflow errors)
sel_events = sel_events(1:(length(sel_events)-1)); %cut out last event because the experiment is often ended before a sufficient number of breaths are recorded after this event
end

for a = 1:length(eventcodes);
b = find(tdt_allevents(:,2) == a);
c(a) = length(b);
clear b;
end
min_events = min(c); %this is the lowest number of trials of an event type, set all trial num to this and exclude trials occuring aferwards
min_trials = min(c); %this is the lowest number of trials of an event type, set all trial num to this and exclude trials occuring aferwards

for i=1:min_events; %arbitrary number of trials
a = find((tdt_allevents(sel_events(i),1)-seek_time) <= tdt_breaths & tdt_breaths <= (tdt_allevents(sel_events(i),1)+seek_time));
for i=1:min_trials; %arbitrary number of trials
if length(sel_events)>min_trials % if this event type has as ton of trials
xx = randperm(length(sel_events)); % use randomly picked trials
sel_events_short = sel_events(xx(:,1:min_trials));
else
sel_events_short = sel_events(1:min_trials);
end
a = find((tdt_allevents(sel_events_short(i),1)-seek_time) <= tdt_breaths & tdt_breaths <= (tdt_allevents(sel_events_short(i),1)+seek_time));
if length(a) ~= 1 %sometimes the search for breaths matching events returns two breaths. This happens during abnormally quick respiration. Eliminate the second one
a = a(1);
end
Expand Down
Loading

0 comments on commit e66949e

Please sign in to comment.