0001 function [V,t,Err] = evoked(data,Fs,win,width,plt,err)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 if nargin < 2;error('Data, sampling frequency required');end
0024 data=change_row_to_column(data);
0025 N=size(data,1);
0026 data=data';
0027 if nargin <3; win = [0 (N-1)/Fs];end
0028 if nargin <4; width = 50/Fs;end
0029 if nargin <5; plt = 'b';end
0030 if nargin <6;err = 1;end
0031 T=win;
0032 if isempty(T); T = [0 (N-1)/Fs];end
0033 if isempty(width); width = 50/Fs;end
0034 if isempty(plt); plt = 'b';end
0035 if isempty(err);err = 1;end
0036
0037 t = min(T):1/Fs:max(T);
0038 if nargin >= 5
0039 indx = find(t>T(1) & t<T(2));
0040 t = t(indx);
0041 data = data(:,indx);
0042 end
0043
0044 if width > (t(length(t))-t(1))/2
0045 disp('Width is too large for data segment: should be in seconds')
0046 disp('Turn off smoothing')
0047 width = 0;
0048 end
0049
0050 s = t(2)-t(1);
0051 N = fix(width/s);
0052 NT = length(data(:,1));
0053
0054 if NT > 1
0055 mdata = mean(data);
0056 else
0057 mdata = data;
0058 end
0059 if N > 4
0060 smdata = locsmooth(mdata,N,fix(N/2));
0061 else
0062 smdata = mdata;
0063 end
0064
0065
0066
0067 Err = 0;
0068 if NT < 4;
0069 disp('Too few trials: no errorbars calculated')
0070 err = 0;
0071 end
0072
0073 if err ~= 0 && NT > 1
0074 Nboot = 10;
0075 bevk = 0;
0076 sevk = 0;
0077 for b=1:Nboot
0078 indx = floor(NT*rand(1,NT)) + 1;
0079 evktmp = mean(data(indx,:));
0080 if N > 4
0081 evktmp = locsmooth(evktmp,N,fix(N/2));
0082 end
0083 bevk = bevk + evktmp;
0084 sevk = sevk + evktmp.^2;
0085 end
0086 stdevk = sqrt((sevk/Nboot - bevk.^2/Nboot^2));
0087 Err = stdevk;
0088 end
0089
0090 V = smdata;
0091 if plt ~= 'n'
0092 plot(t,smdata,plt)
0093 hold on
0094 mn = mean(smdata);
0095 ax = get(gca,'xlim');
0096 line(ax,mn*[1 1],'color','k')
0097 if err
0098 line(ax,(mn+2*mean(stdevk))*[1 1],'color','r')
0099 line(ax,(mn-2*mean(stdevk))*[1 1],'color','r')
0100 hold off
0101 end
0102 end
0103
0104
0105
0106
0107
0108
0109
0110
0111