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