


Multi-taper segmented spectrum for a single time series - binned point process
Usage:
[S,f,R,varS]=mtspectrumsegpb(data,tseg,tapers,pad,Fs,fpass,segave)
Input:
Note units have to be consistent. See chronux.m for more information.
data (in form samples x 1) -- required
tseg (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]=mtspectrumsegpb(data,tseg,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]=mtspectrumsegpb(data,tseg,tapers,pad,Fs,fpass,segave) 0007 % Input: 0008 % Note units have to be consistent. See chronux.m for more information. 0009 % data (in form samples x 1) -- required 0010 % tseg (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 if isempty(tapers); tapers=[3 5]; end; 0035 if isempty(pad);pad=0;end; 0036 if isempty(Fs); Fs=1; end; 0037 if isempty(fpass); fpass=[0 Fs/2]; end; 0038 if isempty(segave); segave=1; end; 0039 0040 N=size(data,1); % total length of data 0041 dt=1/Fs; % sampling interval 0042 T=N*dt; % length of data in seconds 0043 E=[dt:tseg:T]; % fictitious event triggers 0044 win=[0 win]; % use window length to define left and right limits of windows around triggers 0045 [S,f,R]=mtspectrumtrigpb(data,E,win,tapers,pad,Fs,fpass); % spectra of the segments 0046 lS=log(S); % log spectrum 0047 varS=var(lS')'; % variance of the log spectrum as a function of frequency 0048 if segave; 0049 S=squeeze(mean(S,2)); % mean of the spectrum averaged across segments 0050 R=squeeze(mean(R,2)); % mean of the spike rate averaged across segments 0051 end