Skip to content

Commit

Permalink
add solo_spec_stats to redo statitistics without having to run whole …
Browse files Browse the repository at this point in the history
…parsexchan script over again

xcorr_alltoall has major changes to pick max correlation ina  time window, and to also output the specific time of maximum xcorr in whole time segment
  • Loading branch information
Matt Valley committed May 15, 2010
1 parent d6050a7 commit 7fe8f02
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 28 deletions.
27 changes: 20 additions & 7 deletions compare_sigs.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

sum_sigs = squeeze(sum(sig_breaths_allodors(:,:,:,:),1)); %sig_breaths_allodors dimensions (breaths,sigtype,channel,event_type)

%
%
% for i=1:numodors
% for x=1:rows
% for y=1:cols
Expand All @@ -27,15 +27,28 @@
% hold on;
% end

for x=1:rows
for y=1:cols
indx = tdt_map(x,y);
subplot(rows,cols,(x*cols)-cols+y,'align');
plot(sum_sigs(indx,:));
for f = 1:size(sig_breaths_allodors,3)
max_sig = max(max(sum_sigs));
figure
for x=1:rows
for y=1:cols
indx = tdt_map(x,y);
sig_image(x,y) = sum_sigs(indx,f);
end
end
imagesc(sig_image, [0 max_sig]);colorbar;
end

% for h=1:numodors
% figure
% for x=1:rows
% for y=1:cols
% indx = tdt_map(x,y);
% subplot(rows,cols,(x*cols)-cols+y,'align');
% plot(sum_sigs(indx,:));
% end
% end

% for h=1:numodors
% subplot(numodors,1,h);imagesc(squeeze(sig_breaths_allodors(:,:,h)));
% hold on;
% end
34 changes: 17 additions & 17 deletions spectral analysis/test_breathsig.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@

baseline = find(brthindx <= 0); %get all breaths before stimilus (stim triggered on breath 0, so event occurs on next breath)
signal = find(brthindx >= 1); %get all breaths after stimilus
alpha = .05;
alpha = .01;

% base_mean = squeeze(mean(spec_norm(:,g_freqs,:,baseline),1));
% base_gmean = squeeze(mean(base_mean,1));
% all_mean = squeeze(mean(spec_norm(:,g_freqs,:,:),1));
% all_gmean = squeeze(mean(all_mean,1));
% for i=1:size(all_gmean,2) %for each breath
% [sig_breaths(i,n),sig_vals(i,n),cis(i,:,n)] = ttest2(all_gmean(:,i),base_gmean(:),alpha/size(all_gmean,2),'both'); %do two-tailed t-test
% end
% all_spec = all_gmean;

base_max = squeeze(max(spec_norm(:,g_freqs,:,baseline),[],1));
base_gmax = squeeze(max(base_max,[],1));
all_max = squeeze(max(spec_norm(:,g_freqs,:,:),[],1));
all_gmax = squeeze(max(all_max,[],1));
for i=1:size(all_gmax,2) %for each breath
[sig_breaths(i),sig_vals(i),cis(i,:)] = ranksum(all_gmax(:,i),base_gmax(:),alpha/size(all_gmax,2)); %do two-tailed t-test, use bonferroni correction for n=all breaths
base_mean = squeeze(mean(spec_norm(:,g_freqs,:,baseline),1));
base_gmean = squeeze(mean(base_mean,1));
all_mean = squeeze(mean(spec_norm(:,g_freqs,:,:),1));
all_gmean = squeeze(mean(all_mean,1));
for i=1:size(all_gmean,2) %for each breath
[sig_vals(i),sig_breaths(i),cis(i,:)] = ranksum(all_gmean(:,i),base_gmean(:),alpha);%/size(all_gmean,2),'both'); %do two-tailed t-test
end
all_spec = all_gmax;
all_spec = all_gmean;

% base_max = squeeze(max(spec_norm(:,g_freqs,:,baseline),[],1));
% base_gmax = squeeze(max(base_max,[],1));
% all_max = squeeze(max(spec_norm(:,g_freqs,:,:),[],1));
% all_gmax = squeeze(max(all_max,[],1));
% for i=1:size(all_gmax,2) %for each breath
% [sig_vals(i),sig_breaths(i),cis(i,:)] = ranksum(all_gmax(:,i),base_gmax(:),alpha);%/size(all_gmax,2)); %do ranksum test, use bonferroni correction for n=all breaths
% end
% all_spec = all_gmax;
end
21 changes: 21 additions & 0 deletions testing/solo_spec_stats.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
% import "f" vector
% sequentially load all "spec_norm" matrices for each odor presentation

gamma = [50 100];
g_freqs = find(f>gamma(1) & f<gamma(2));
brthindx = [-10:1:20];

% sequentially import all channels
[pathname] = uipickfiles('refilter', '\.mat$', 'type', {'*.mat', 'MAT-files'},...
'prompt', 'Select all .mat files from MEA channels', 'output', 'cell');

for odor = 1:length(pathname);
load(pathname{odor}); % filename must be "spec_norm"
for n=1:size(spec_norm,5);
[sig_breaths(:,n),sig_vals(:,n),cis(:,n),all_specmax(:,:,n)] = test_breathsig(spec_norm(:,:,:,:,n),brthindx,g_freqs);
end
sig_breaths_allodors(:,:,odor) = sig_breaths;
sig_vals_allodors(:,:,odor) = sig_vals;
end

sumbreaths = squeeze(sum(sig_breaths_allodors,1));
14 changes: 10 additions & 4 deletions xcorrelation/xcorr_alltoall.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function[corr_breath]= xcorr_alltoall(data,FirstChannel,LastChannel,sampFreq,filttype,filtorder)
%function[corr_breath]= xcorr_alltoall(data,FirstChannel,LastChannel,sampFreq,filttype,filtorder)

%function outputs the zerolag correlation per breath, (averaging along
%events) in the matrix Corr_Per_Breath(32X32X11 matrix, last dimension is the number of breaths). It is for plotting correlations
Expand All @@ -8,6 +8,8 @@
%SampFreq is the sampling frequency, in our case 3051.76
%filttype= filttype for sinofilt.m specifies frequency band e.g. [40 100]
%filtorder is order for SimoFilt.m, 200 typically works best for gamma

corr_win = 30; %window in which to find max correlation, in samples
data_filtered = filter_data(data,sampFreq,filttype,filtorder);

t0=clock;
Expand All @@ -18,14 +20,18 @@
finalcorr = xcorr(segs,'coeff');
[qq,ww] = size(segs);
m=1;
for x=1:((LastChannel-FirstChannel)+1) % we are referencing every channels correlation into a separated third dimension
for x=1:((LastChannel-FirstChannel)+1)% we are referencing every channels correlation into a separated third dimension
newmatrix(:,:,x) = finalcorr(:,(m):(m+(LastChannel-FirstChannel)));
m=m+((LastChannel-FirstChannel)+1);
end
corr_event(:,:,event)= newmatrix(qq,:,:); %Check from here, supposed to get the zerolag correlation for all channels, per reference channel, per event
corr_event(:,:,event) = squeeze(max(newmatrix((qq-corr_win/2):(qq+corr_win/2),:,:),[],1));%get max correlation in window around time zero
[C max_index] = squeeze(max(newmatrix,[],1));
max_index = squeeze(max_index)-qq;
corrtime_event(:,:,event) = max_index;
t2=etime(clock,t1);
['xcorr_alltoall will complete in t - ', num2str(t2*size(data,3)*size(data,2)-etime(t1,t0)), ' seconds. Go get some coffee']
end
corr_breath(:,:,:,breath)=corr_event;
corrtime_breath(:,:,:,breath)=corrtime_event;
end
end
%end

0 comments on commit 7fe8f02

Please sign in to comment.