207 lines
5.8 KiB
Mathematica
207 lines
5.8 KiB
Mathematica
|
function[obj]= plot(varargin)
|
||
|
cla;
|
||
|
hold on;
|
||
|
|
||
|
obj = varargin{1};
|
||
|
settings = struct('BaselineCorrection', 0,...
|
||
|
'FilterSize', 100, ...
|
||
|
'BlinkExtension', [10 10],...
|
||
|
'MaximumBlinkSize', 150,...
|
||
|
'QualityThreshold',50);
|
||
|
|
||
|
if nargin > 1
|
||
|
settings = varargin{2};
|
||
|
end
|
||
|
|
||
|
%% get plotting options
|
||
|
options = get(gcf, 'UserData');
|
||
|
|
||
|
if ~isfield(options,'raw')
|
||
|
options.raw = 0;
|
||
|
options.logtransformed = 1;
|
||
|
options.interpolated = 1;
|
||
|
options.filtered = 1;
|
||
|
options.blinks = 1;
|
||
|
options.markers = 1;
|
||
|
options.labels = 1;
|
||
|
options.baseline = 0;
|
||
|
options.baseline_corrected = 0;
|
||
|
options.deconvolution = 0;
|
||
|
|
||
|
options.drawing = options;
|
||
|
options.drawing.raw = {'-', [1 0 0], 3};
|
||
|
options.drawing.logtransformed = {'-', [0 0 0.5], 3};
|
||
|
options.drawing.interpolated= {'-', [0.5 0 0], 3};
|
||
|
options.drawing.filtered= {'-', [0 0.5 0], 3};
|
||
|
options.drawing.markers= {'-.', [0.5 0 0], 3};
|
||
|
options.drawing.baseline= {'--', [0 0 1], 3};
|
||
|
options.drawing.baseline_corrected= {'--', [0 0 0], 3};
|
||
|
|
||
|
end
|
||
|
|
||
|
if (options.baseline_corrected)
|
||
|
field = 'baseline_corrected';
|
||
|
options.baseline = 0;
|
||
|
else
|
||
|
field = 'uncorrected';
|
||
|
|
||
|
end
|
||
|
|
||
|
|
||
|
miny = 1e6; maxy = 0;
|
||
|
|
||
|
signals = fieldnames(options);
|
||
|
for i = 1:length(signals)
|
||
|
if (strcmp(signals{i}, 'drawing') || ...
|
||
|
strcmp(signals{i}, 'markers') || ...
|
||
|
strcmp(signals{i}, 'labels') || ...
|
||
|
strcmp(signals{i}, 'blinks') || ...
|
||
|
strcmp(signals{i}, 'deconvolution') || ...
|
||
|
strcmp(signals{i}, 'baseline_corrected'))
|
||
|
continue;
|
||
|
end
|
||
|
|
||
|
if getfield(options, signals{i}) %% plotting is enabled
|
||
|
|
||
|
signal = getfield(getfield(obj.data, field), signals{i});
|
||
|
y = [min(signal) max(signal) ];
|
||
|
len = min(length(obj.time), length(signal));
|
||
|
|
||
|
drawing = getfield(options.drawing, signals{i});
|
||
|
ls = drawing{1}; color = drawing{2}; lw = drawing{3};
|
||
|
|
||
|
if (strcmp(signals{i}, 'filtered'))
|
||
|
signal(1:settings.FilterSize) = NaN;
|
||
|
signal(len - settings.FilterSize:len) = NaN;
|
||
|
end
|
||
|
|
||
|
miny = min(min(signal),miny);
|
||
|
maxy = max(max(signal),maxy);
|
||
|
|
||
|
|
||
|
plot(obj.time(1:len), signal(1:len), 'LineWidth', lw, 'Color', color, 'LineStyle', ls);
|
||
|
|
||
|
end
|
||
|
end
|
||
|
|
||
|
|
||
|
|
||
|
if miny > maxy
|
||
|
tmp = maxy;
|
||
|
maxy = miny
|
||
|
miny = tmp;
|
||
|
end
|
||
|
|
||
|
|
||
|
if (options.baseline)
|
||
|
len = length(obj.data.uncorrected.interpolated);
|
||
|
baseline_signal = repmat(obj.baseline, 1,len);
|
||
|
ls = options.drawing.baseline{1};
|
||
|
color = options.drawing.baseline{2};
|
||
|
lw = options.drawing.baseline{3};
|
||
|
|
||
|
len = min(length(obj.time),len);
|
||
|
plot(obj.time(1:len), baseline_signal, 'Color', color, 'LineWidth', lw, 'LineStyle', ls);
|
||
|
|
||
|
%% real baseline signal plotted
|
||
|
baseline_ind = intersect(find(obj.time > obj.baseline_onset), ...
|
||
|
find(obj.time <= obj.baseline_offset));
|
||
|
b_time = obj.time(baseline_ind);
|
||
|
b_value = obj.data.uncorrected.interpolated(baseline_ind);
|
||
|
|
||
|
plot(b_time, b_value, 'Color', color, 'LineWidth', lw, 'LineStyle', ls);
|
||
|
|
||
|
end
|
||
|
|
||
|
if options.blinks
|
||
|
|
||
|
nans = find(isnan(obj.data.uncorrected.raw));
|
||
|
dnans = diff(nans);
|
||
|
|
||
|
i=1;
|
||
|
|
||
|
if (~isempty(nans))
|
||
|
x1=obj.time(nans(i));
|
||
|
end
|
||
|
%end
|
||
|
|
||
|
xlist=[];
|
||
|
while i < length(nans)
|
||
|
if dnans(i) ~=1
|
||
|
x2 = obj.time(nans(i));
|
||
|
xlist = [xlist; x1 x2];
|
||
|
x1 = obj.time(nans(i+1));
|
||
|
end
|
||
|
i=i+1;
|
||
|
end
|
||
|
|
||
|
for t = 1:size(xlist,1);
|
||
|
x = [xlist(t,1) xlist(t,1) xlist(t,2) xlist(t,2)];
|
||
|
y = [miny maxy maxy miny];
|
||
|
fa=fill(x,y,[1 0 0]);
|
||
|
set(fa, 'EdgeAlpha', .5, 'EdgeColor',[1 0 0]);
|
||
|
alpha(fa, 0.5);
|
||
|
end
|
||
|
|
||
|
plot([obj.time(obj.settings.FilterSize) obj.time(obj.settings.FilterSize)], [miny maxy], 'r-');
|
||
|
plot([obj.time(end-obj.settings.FilterSize) obj.time(end-obj.settings.FilterSize)], [miny maxy], 'r-');
|
||
|
end
|
||
|
|
||
|
if ~isempty(miny)
|
||
|
ylim([miny*.9 maxy*1.1]); %% fix y limits
|
||
|
end
|
||
|
|
||
|
% %% add 50% grey squares on top of the filter startup effects
|
||
|
% ends = get(gca,'XLim');
|
||
|
%
|
||
|
% box1 = [ends(1) obj.time(obj.settings.FilterSize) obj.time(obj.settings.FilterSize) ends(1)];
|
||
|
% box2 = [ends(2) obj.time(end-obj.settings.FilterSize) obj.time(end-obj.settings.FilterSize) ends(2)];
|
||
|
% boxy = [miny*.95 miny*.95 maxy*1.1 maxy*1.1];
|
||
|
% %h(1) = fill(box1, boxy,[.5 0 0]);
|
||
|
% %h(2) = fill(box2, boxy,[.5 0 0]);
|
||
|
% %alpha(h, .2);
|
||
|
%
|
||
|
if options.markers
|
||
|
markers = {'trial_start', 'trial_end', 'baseline_onset', 'baseline_offset','stimulus_onset', 'stimulus_offset'};
|
||
|
marker_colors = {[0 0 0], [0 0 0], [0 0 1], [0 0 1], [1 0.5 0], [1 0.5 0]};
|
||
|
|
||
|
for m = 1:length(markers)
|
||
|
if ~isempty(obj.(markers{m}))
|
||
|
obj.(markers{m})
|
||
|
|
||
|
plot([obj.(markers{m})(1) obj.(markers{m})(1)], [miny maxy], 'Color', marker_colors{m}, 'LineWidth', 2);
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
if options.labels
|
||
|
|
||
|
for l = 1:length(obj.labels)
|
||
|
if ~(isfield(obj.labels(l), 'color') && length(obj.labels(l))==3)
|
||
|
obj.labels(l).color = [ .5 .5 .5];
|
||
|
end
|
||
|
plot([obj.labels(l).time obj.labels(l).time], [miny maxy], 'Color', obj.labels(l).color, 'LineWidth', 2);
|
||
|
|
||
|
end
|
||
|
end
|
||
|
|
||
|
|
||
|
if options.deconvolution
|
||
|
|
||
|
if isfield(obj.deconvolution, 'params')
|
||
|
params = obj.deconvolution.params;
|
||
|
modelfit = obj.prf_convolve(obj.stick_model(params(2:end)),params(1));
|
||
|
|
||
|
plot(obj.deconvolution.time,modelfit, 'k:');
|
||
|
|
||
|
end
|
||
|
end
|
||
|
|
||
|
|
||
|
%qt = text((obj.trial_end - (obj.trial_end - obj.trial_start)/4),...
|
||
|
% miny + ((maxy - miny) /5), sprintf('Quality: %2.2f%%', obj.quality));
|
||
|
qt = title(sprintf('Quality: %2.2f%%', obj.quality));
|
||
|
set(qt, 'FontName', 'Verdana');
|
||
|
set(qt, 'FontWeight', 'bold');
|
||
|
set(qt, 'FontSize', 10);
|