Skip to content

Commit

Permalink
fix major bug in parsechans where random trial extraction occured wit…
Browse files Browse the repository at this point in the history
…hin a forloop causing different trials to be chosen every breath.

add new script probe_xcorrlab to analyze the time of max correlations between electrodes
  • Loading branch information
Matt Valley committed May 18, 2010
1 parent e1fd182 commit d1ea584
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 26 deletions.
26 changes: 25 additions & 1 deletion spectral analysis/parse_xchan.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,30 @@
[pathname] = uipickfiles('refilter', '\.mat$', 'type', {'*.mat', 'MAT-files'},...
'prompt', 'Select all .mat files from MEA channels', 'output', 'cell');


tdt_allevents(:,1) = (events(:,1)*srate);
tdt_allevents(:,2) = events(:,2);
for odor = eventcodes;
sel_events = find(tdt_allevents(:,2) == odor);
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 = eventcodes;
b = find(tdt_allevents(:,2) == a);
c(a) = length(b);
clear b;
end
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
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
sel_events_all(:,odor) = sort(sel_events_short); %resort event indices back into chronological order
clear sel_events sel_events_short a c
end

for odor = eventcodes;
disp('odor'); disp(odor);
for n = 1:length(pathname); %n to number of selected channels
Expand All @@ -49,7 +73,7 @@
end
load(pathname{n}); % name of imported data must be "wave"
for x = 1:length(brthindx) %x to num of breaths
wave_segs(:,:,x,n) = parsechans(wave,events,breaths,srate,odor,brthindx(x),winsize,eventcodes);
wave_segs(:,:,x,n) = parsechans(wave,events,breaths,srate,sel_events_all(:,odor),winsize,brthindx(x));
[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
44 changes: 22 additions & 22 deletions spectral analysis/parsechans.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [wave_segs] = parsechans(wave,events,breaths,srate,odor,brth_num,winsize,eventcodes)
function [wave_segs] = parsechans(wave,events,breaths,srate,event_indices,winsize,brth_num)

%INPUTS:
% -- "events" matrix containing vectors with event time(in sec) 1st dim,
Expand All @@ -12,33 +12,33 @@
% eventcode - code of events to extract

win_time = (winsize/2)*srate; %time (samples) to window forward (or beackward) from a breath
win_offset = 0*srate; %time (seconds) to forward offset window in time
win_offset = 0*srate; %time (samples) to forward offset window in time
seek_time = 1000; %num samples to seek forward and backwards from event to find corresponding breath

tdt_allevents(:,1) = (events(:,1)*srate);
tdt_allevents(:,2) = events(:,2);
tdt_breaths = round(breaths*srate);
sel_events = find(tdt_allevents(:,2) == odor);
% sel_events = find(tdt_allevents(:,2) == odor);
%
% 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 = eventcodes;
% b = find(tdt_allevents(:,2) == a);
% c(a) = length(b);
% clear b;
% end
% 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
% 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
% sel_events_short = sort(sel_events_short); %resort event indices back into chronological order

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 = eventcodes;
b = find(tdt_allevents(:,2) == a);
c(a) = length(b);
clear b;
end
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
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
sel_events_short = sort(sel_events_short); %resort events back into chronological order

for i=1:min_trials; %arbitrary number of trials
a = find((tdt_allevents(sel_events_short(i),1)-seek_time) <= tdt_breaths & tdt_breaths <= (tdt_allevents(sel_events_short(i),1)+seek_time));
for i=1:length(event_indices); %number of trials
a = find((tdt_allevents(event_indices(i),1)-seek_time) <= tdt_breaths & tdt_breaths <= (tdt_allevents(event_indices(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
9 changes: 6 additions & 3 deletions xcorrelation/corrmap_comparechans.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
% chan1 = 14;
% chan2 = 19;

%data = wave_segs; %[corr, corr, tirals, breaths]
%data = wave_segs; %[corr, corr, trials, breaths]
tdt_map = [8,16,24,32;...
7,15,23,31;...
6,14,22,30;...
Expand All @@ -15,8 +15,11 @@

rows = 8;
cols = 4;
basebreaths = 1:11;
odorbreaths = 13:15;
postbreaths = 16:30;

spec_max = max(max(mean(mean(corr_breath,4),3)));
spec_max = max(max(mean(mean(corr_breath(:,:,:,basebreaths),4),3)));
%spec_max = .3;
spec_min = min(min(mean(mean(corr_breath,4),3)));

Expand All @@ -26,7 +29,7 @@
indx = tdt_map(x,y);
chan1map = squeeze(mean(mean(corr_breath(indx,:,:,:),4),3));
subplot(rows,cols,(x*cols)-cols+y,'align');
imagesc_mea(chan1map,spec_min,spec_max);
imagesc_mea(chan1map,0,spec_max);
end
end
%subplot(2,1,1);imagesc_mea(chan1map);colorbar;
Expand Down
30 changes: 30 additions & 0 deletions xcorrelation/probe_xcorrlag.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
% input data is "corrtime_breath" output from xcorr_alltoall

tdt_map = [8,16,24,32;...
7,15,23,31;...
6,14,22,30;...
5,13,21,29;...
4,12,20,28;...
3,11,19,27;...
2,10,18,26;...
1,9,17,25];
rows = size(tdt_map,1);
cols = size(tdt_map,2);

basebreaths = 1:11;
odorbreaths = 13:15;
postbreaths = 16:30;

avelag_odor = mean(mean(corrtime_breath(:,:,:,odorbreaths),4),3);
avelag_base = mean(mean(corrtime_breath(:,:,:,basebreaths),4),3);

for x=1:rows
for y=1:cols
indx = tdt_map(x,y);
plotlag_base(x,y) = mean(avelag_base(:,indx),1);
plotlag_odor(x,y) = mean(avelag_odor(:,indx),1);
end
end

lagdiff = plotlag_odor-plotlag_base;
imagesc(lagdiff);colorbar;

0 comments on commit d1ea584

Please sign in to comment.