


Multi-taper segmented spectrum for a single time series - binned point process
Usage:
[S,f,R,varS]=mtspectrumsegpt(data,tseg,tapers,pad,Fs,fpass,segave)
Input:
Note units have to be consistent. See chronux.m for more information.
data (structure array of one channel of spike times; also accepts 1d column vector of spike times) -- required
win (duration of the segments) - required.
tapers (precalculated tapers from dpss, or in the form [NW K] e.g [3 5]) -- optional. If not
specified, use [NW K]=[3 5]
pad (padding factor for the FFT) - optional. Defaults to 0.
e.g. For N = 500, if PAD = 0, we pad the FFT
to 512 points; if PAD = 2, we pad the FFT
to 2048 points, etc.
Fs (sampling frequency) - optional. Default 1.
fpass (frequency band to be used in the calculation in the form
[fmin fmax])- optional.
Default all frequencies between 0 and Fs/2
segave (1 for averaging across segments, 0 otherwise; default 1)
Output:
S (spectrum in form frequency x channels/trials)
f (frequencies)
R (spike rate)
varS (variance of the log spectrum)

0001 function [S,f,R,varS]=mtspectrumsegpt(data,win,tapers,pad,Fs,fpass,segave) 0002 % Multi-taper segmented spectrum for a single time series - binned point process 0003 % 0004 % Usage: 0005 % 0006 % [S,f,R,varS]=mtspectrumsegpt(data,tseg,tapers,pad,Fs,fpass,segave) 0007 % Input: 0008 % Note units have to be consistent. See chronux.m for more information. 0009 % data (structure array of one channel of spike times; also accepts 1d column vector of spike times) -- required 0010 % win (duration of the segments) - required. 0011 % tapers (precalculated tapers from dpss, or in the form [NW K] e.g [3 5]) -- optional. If not 0012 % specified, use [NW K]=[3 5] 0013 % pad (padding factor for the FFT) - optional. Defaults to 0. 0014 % e.g. For N = 500, if PAD = 0, we pad the FFT 0015 % to 512 points; if PAD = 2, we pad the FFT 0016 % to 2048 points, etc. 0017 % Fs (sampling frequency) - optional. Default 1. 0018 % fpass (frequency band to be used in the calculation in the form 0019 % [fmin fmax])- optional. 0020 % Default all frequencies between 0 and Fs/2 0021 % segave (1 for averaging across segments, 0 otherwise; default 1) 0022 % Output: 0023 % S (spectrum in form frequency x channels/trials) 0024 % f (frequencies) 0025 % R (spike rate) 0026 % varS (variance of the log spectrum) 0027 0028 if nargin < 2; error('Need data and segment information'); end; 0029 if nargin < 3; tapers=[3 5]; end; 0030 if nargin < 4;pad=0;end; 0031 if nargin < 5; Fs=1; end; 0032 if nargin < 6; fpass=[0 Fs/2]; end; 0033 if nargin < 7; segave=1; end; 0034 0035 if isempty(tapers); tapers=[3 5]; end; 0036 if isempty(pad);pad=0;end; 0037 if isempty(Fs); Fs=1; end; 0038 if isempty(fpass); fpass=[0 Fs/2]; end; 0039 if isempty(segave); segave=1; end; 0040 0041 if isstruct(data); 0042 fnames=fieldnames(data); 0043 eval(['dtmp=data.' fnames{1} ';']) 0044 else 0045 dtmp=data(:); 0046 end; 0047 T=max(dtmp); % total length of data 0048 dt=1/Fs; % sampling interval 0049 T=N*dt; % length of data in seconds 0050 E=[dt:tseg:T]; % fictitious event triggers 0051 win=[0 win]; % use window length to define left and right limits of windows around triggers 0052 [S,f,R]=mtspectrumtrigpt(dtmp,E,win,tapers,pad,Fs,fpass); % spectra of the segments 0053 lS=log(S); % log spectrum 0054 varS=var(lS')'; % variance of the log spectrum as a function of frequency 0055 if segave; 0056 S=squeeze(mean(S,2)); % mean of the spectrum averaged across segments 0057 R=squeeze(mean(R,2)); % mean of the spike rate averaged across segments 0058 end