Home > chronux_code > exploratory > functionestimation > continuous > evoked.m

evoked

PURPOSE ^

Function to calculate the evoked response given continuous data in the

SYNOPSIS ^

function [V,t,Err] = evoked(data,Fs,win,width,plt,err)

DESCRIPTION ^

 Function to calculate the evoked response given continuous data in the
 form time x channels
 Usage [V,t,Err] = evoked(data,Fs,win,width,plt,err)
 
 Inputs  
   Note that all times can be in arbitrary units. But the units have to be
   consistent. So, if win is in secs, width is in secs and Fs has to be Hz. 
   If win is in samples, so is width and Fs=1.

    data(times, channels/trials)      (required)    
    Fs  sampling frequency            (required)
    win   subsection of data to be used. Default all available data
    width (s) of smoothing kernel. Default 50 samples                  
    plt plot 'n' for no plot, otherwise plot color. Default blue colored lines.                                  
    err = 0/1. Default 1=calculate bootstrap errorbars.                     
                                                         
    Outputs                                             
    V = evoked potential                                 
    t = times of evaluation                              
    Err = bootstrap statdard deviation

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [V,t,Err] = evoked(data,Fs,win,width,plt,err)
0002 % Function to calculate the evoked response given continuous data in the
0003 % form time x channels
0004 % Usage [V,t,Err] = evoked(data,Fs,win,width,plt,err)
0005 %
0006 % Inputs
0007 %   Note that all times can be in arbitrary units. But the units have to be
0008 %   consistent. So, if win is in secs, width is in secs and Fs has to be Hz.
0009 %   If win is in samples, so is width and Fs=1.
0010 %
0011 %    data(times, channels/trials)      (required)
0012 %    Fs  sampling frequency            (required)
0013 %    win   subsection of data to be used. Default all available data
0014 %    width (s) of smoothing kernel. Default 50 samples
0015 %    plt plot 'n' for no plot, otherwise plot color. Default blue colored lines.
0016 %    err = 0/1. Default 1=calculate bootstrap errorbars.
0017 %
0018 %    Outputs
0019 %    V = evoked potential
0020 %    t = times of evaluation
0021 %    Err = bootstrap statdard deviation
0022 
0023 if nargin < 2;error('Data, sampling frequency required');end
0024 N=size(data,1);
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
0054     mdata = mean(data);
0055 else
0056     mdata = data;
0057 end
0058 if N > 4
0059   smdata = locsmooth(mdata,N,fix(N/2)); 
0060 else
0061   smdata = mdata;  
0062 end
0063   
0064 % if errorbars requested then do a bootstrap over trials...
0065 
0066 Err = 0;
0067 if NT < 4; 
0068   disp('Too few trials: no errorbars calculated')
0069   err = 0;    
0070 end
0071 
0072 if err ~= 0 & NT > 1
0073   Nboot = 10;
0074   bevk = 0;
0075   sevk = 0;
0076   for b=1:Nboot
0077     indx = floor(NT*rand(1,NT)) + 1;
0078     evktmp = mean(data(indx,:));
0079     if N > 4
0080       evktmp = locsmooth(evktmp,N,fix(N/2));
0081     end
0082     bevk = bevk + evktmp;
0083     sevk = sevk + evktmp.^2;
0084   end
0085   stdevk = sqrt((sevk/Nboot - bevk.^2/Nboot^2));
0086   Err = stdevk;
0087 end
0088 
0089 V = smdata;
0090 if plt ~= 'n'
0091   plot(t,smdata,plt)
0092   hold on
0093   mn = mean(smdata);
0094   ax = get(gca,'xlim');
0095   line(ax,mn*[1 1],'color','k')
0096   if err
0097     line(ax,(mn+2*mean(stdevk))*[1 1],'color','r')
0098     line(ax,(mn-2*mean(stdevk))*[1 1],'color','r')
0099     hold off
0100   end
0101 end
0102 
0103 
0104 
0105 
0106 
0107 
0108 
0109 
0110

Generated on Tue 07-Jun-2005 12:20:32 by m2html © 2003