


Multi-taper segmented spectrum for a single time series - continuous process
Usage:
[S,f,varS]=mtspectrumsegc(data,win,tapers,pad,Fs,fpass,segave)
Input:
Note units have to be consistent. See chronux.m for more information.
data (column vector) -- 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)
varS (variance of the log spectrum)

0001 function [S,f,varS,Serr]=mtspectrumsegc(data,win,tapers,pad,Fs,fpass,segave) 0002 % Multi-taper segmented spectrum for a single time series - continuous process 0003 % 0004 % Usage: 0005 % 0006 % [S,f,varS]=mtspectrumsegc(data,win,tapers,pad,Fs,fpass,segave) 0007 % Input: 0008 % Note units have to be consistent. See chronux.m for more information. 0009 % data (column vector) -- 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 % varS (variance of the log spectrum) 0026 0027 if nargin < 2; error('Need data and segment information'); end; 0028 if nargin < 3; tapers=[3 5]; end; 0029 if nargin < 4;pad=0;end; 0030 if nargin < 5; Fs=1; end; 0031 if nargin < 6; fpass=[0 Fs/2]; end; 0032 if nargin < 7; segave=1; end; 0033 if isempty(tapers); tapers=[3 5]; end; 0034 if isempty(pad);pad=0;end; 0035 if isempty(Fs); Fs=1; end; 0036 if isempty(fpass); fpass=[0 Fs/2]; end; 0037 if isempty(segave); segave=1; end; 0038 0039 N=size(data,1); % total length of data 0040 dt=1/Fs; % sampling interval 0041 T=N*dt; % length of data in seconds 0042 E=[dt:win:T]; % fictitious event triggers 0043 win=[0 win]; % use window length to define left and right limits of windows around triggers 0044 data=createdatamatc(data,E,Fs,win); % segmented data 0045 [S,f]=mtspectrumc(data,tapers,pad,Fs,fpass); % spectra of segmented data 0046 lS=log(S); % log spectrum 0047 varS=var(lS')'; % variance of the log spectrum as a function of frequency 0048 if segave; S=squeeze(mean(S,2)); end;% mean of the spectrum averaged across segments