From d1ea5843dba01aca3c5567260ad609c4dabb6985 Mon Sep 17 00:00:00 2001 From: Matt Valley Date: Tue, 18 May 2010 19:14:23 -0400 Subject: [PATCH] fix major bug in parsechans where random trial extraction occured within a forloop causing different trials to be chosen every breath. add new script probe_xcorrlab to analyze the time of max correlations between electrodes --- spectral analysis/parse_xchan.m | 26 ++++++++++++++++- spectral analysis/parsechans.m | 44 ++++++++++++++--------------- xcorrelation/corrmap_comparechans.m | 9 ++++-- xcorrelation/probe_xcorrlag.m | 30 ++++++++++++++++++++ 4 files changed, 83 insertions(+), 26 deletions(-) create mode 100644 xcorrelation/probe_xcorrlag.m diff --git a/spectral analysis/parse_xchan.m b/spectral analysis/parse_xchan.m index a04b46f..3a3bbd6 100644 --- a/spectral analysis/parse_xchan.m +++ b/spectral analysis/parse_xchan.m @@ -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 @@ -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); diff --git a/spectral analysis/parsechans.m b/spectral analysis/parsechans.m index e3e9615..7b4dca6 100644 --- a/spectral analysis/parsechans.m +++ b/spectral analysis/parsechans.m @@ -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, @@ -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 diff --git a/xcorrelation/corrmap_comparechans.m b/xcorrelation/corrmap_comparechans.m index 4d33176..7c3d95a 100644 --- a/xcorrelation/corrmap_comparechans.m +++ b/xcorrelation/corrmap_comparechans.m @@ -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;... @@ -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))); @@ -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; diff --git a/xcorrelation/probe_xcorrlag.m b/xcorrelation/probe_xcorrlag.m new file mode 100644 index 0000000..e29367f --- /dev/null +++ b/xcorrelation/probe_xcorrlag.m @@ -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; \ No newline at end of file