6
6
% dat = proc_spectrogram(dat, freq, <OPT>)
7
7
% dat = proc_spectrogram(dat, freq, Window, <OPT>)
8
8
% dat = proc_spectrogram(dat, freq, Window, NOverlap,<OPT>)
9
- %
9
+ %
10
10
% Arguments:
11
11
% DAT - data structure of continuous or epoched data
12
- % FREQ - vector with desired frequency bins (eg 1:100). If a single
13
- % integer is given, it specifies the FFT length from which
14
- % the frequency bins are then automatically chosen (this is
12
+ % FREQ - vector with desired frequency bins (eg 1:100). If a single
13
+ % integer is given, it specifies the FFT length from which
14
+ % the frequency bins are then automatically chosen (this is
15
15
% usally faster).
16
16
% OPT - struct or property/value list of optional properties:
17
- % 'Window' - if a vector, divides the data into segments of length equal
17
+ % 'Window' - if a vector, divides the data into segments of length equal
18
18
% to the length of WINDOW, and then windows each
19
19
% segment with the vector specified in WINDOW. If WINDOW is an integer,
20
20
% the data is divided into segments of length equal to that integer value, and a
21
21
% Hamming window of equal length is used. If WINDOW is not specified, the
22
22
% default is used. Default dat.fs/2 (ie a 500 ms window).
23
- % 'NOverlap' - number of samples each segment of X overlaps. Must be an
24
- % integer smaller than the window length. Default:
25
- % window length -1 (so that a time x frequency
23
+ % 'NOverlap' - number of samples each segment of X overlaps. Must be an
24
+ % integer smaller than the window length. Default:
25
+ % window length -1 (so that a time x frequency
26
26
% representation is defined for each sample)
27
27
% 'CLab' - specifies for which channels the spectrogram is calculated.
28
28
% (default '*')
29
29
% 'Output' - Determines if and how the FFT coefficients are processed.
30
30
% 'complex' preserves the complex output (with both phase and
31
31
% amplitude information), 'amplitude' returns the absolute
32
- % value, 'power' the squared absolute value, 'db' log power,
33
- % and 'phase' the phase in radians. Default 'complex'.
32
+ % value, 'power' the squared absolute value, 'db' log power,
33
+ % and 'phase' the phase in radians. Default 'complex'.
34
34
% Returns:
35
35
% DAT - updated data structure with a higher dimension.
36
- % For continuous data, the dimensions correspond to
36
+ % For continuous data, the dimensions correspond to
37
37
% time x frequency x channels. For epoched data, time x
38
38
% frequency x channels x epochs.
39
39
% The coefficients are complex. You can obtain the amplitude by
48
48
% 2010, 2015
49
49
50
50
props = {' Window' , [] ' DOUBLE' ;
51
- ' DbScaled' 1 ' !BOOL' ;
52
- ' NOverlap' [] ' DOUBLE[1]' ;
53
- ' CLab' , ' *' ' CHAR|CELL{CHAR}|DOUBLE[-]' ;
54
- ' Output' ' complex' ' !CHAR(complex amplitude power db phase)' ;
55
- };
51
+ ' DbScaled' 1 ' !BOOL' ;
52
+ ' NOverlap' [] ' DOUBLE[1]' ;
53
+ ' CLab' , ' *' ' CHAR|CELL{CHAR}|DOUBLE[-]' ;
54
+ ' Output' ' complex' ' !CHAR(complex amplitude power db phase)' ;
55
+ };
56
56
57
57
if nargin == 0 ,
58
- dat= props ; return
58
+ dat= props ; return
59
59
end
60
60
61
61
misc_checkType(dat ,' !STRUCT(x fs)' );
62
62
misc_checkType(freq ,' !DOUBLE[-]' );
63
63
64
64
% Parse other arguments
65
65
if nargin > 2 && isnumeric(varargin{1 })
66
- window = varargin{1 };
67
- remidx = 1 ;
68
- if nargin > 3 && isnumeric(varargin{2 })
69
- noverlap = varargin{2 };
70
- remidx = [remidx 2 ];
71
- varargin = {' Window' varargin{1 } ' NOverlap' varargin{2 : end }};
72
- else
73
- varargin = {' Window' varargin{: }};
74
- end
66
+ window = varargin{1 };
67
+ remidx = 1 ;
68
+ if nargin > 3 && isnumeric(varargin{2 })
69
+ noverlap = varargin{2 };
70
+ remidx = [remidx 2 ];
71
+ varargin = {' Window' varargin{1 } ' NOverlap' varargin{2 : end }};
72
+ else
73
+ varargin = {' Window' varargin{: }};
74
+ end
75
75
end
76
76
77
77
opt= opt_proplistToStruct(varargin{: });
89
89
dat = misc_history(dat );
90
90
91
91
if numel(freq )==1
92
- nfreq = freq ;
92
+ nfreq = freq ;
93
93
else
94
- nfreq = numel(freq );
94
+ nfreq = numel(freq );
95
95
end
96
96
97
97
%% Spectrogram
102
102
% Process spectrogram channel- and epoch-wise
103
103
X= dat .x ;
104
104
dat.x= [];
105
- if ndims(dat . x ) == 2 % cnt
105
+ if ndims(X ) == 2 % cnt
106
106
for chan= 1 : sz(2 )
107
107
[S ,F ,T ] = spectrogram(X(: ,chan ),opt .Window ,opt .NOverlap ,freq ,dat .fs );
108
108
dat .x(: ,: ,chan )=S ;
109
109
end
110
- elseif ndims(dat . x )== 3 % epoched
110
+ elseif ndims(X ) == 3 % epoched
111
111
for chan= 1 : sz(3 )
112
112
for seg= 1 : sz(2 )
113
113
[S ,F ,T ] = spectrogram(X(: ,seg ,chan ),opt .Window ,opt .NOverlap ,freq ,dat .fs );
122
122
dat.zUnit = ' Hz' ;
123
123
124
124
switch (opt .Output )
125
- case ' complex'
126
- % do nothing
127
- case ' amplitude'
128
- dat.x = abs(dat .x );
129
- dat.yUnit= ' amplitude' ;
130
- case ' power'
131
- dat.x = abs(dat .x ).^2 ;
132
- dat.yUnit= ' power' ;
133
- case ' db'
134
- dat.x = 10 * log10( abs(dat .x ).^2 );
135
- dat.yUnit= ' log power' ;
136
- case ' phase'
137
- dat.x = angle(dat .x );
138
- dat.yUnit= ' phase' ;
139
- end
140
-
125
+ case ' complex'
126
+ % do nothing
127
+ case ' amplitude'
128
+ dat.x = abs(dat .x );
129
+ dat.yUnit= ' amplitude' ;
130
+ case ' power'
131
+ dat.x = abs(dat .x ).^2 ;
132
+ dat.yUnit= ' power' ;
133
+ case ' db'
134
+ dat.x = 10 * log10( abs(dat .x ).^2 );
135
+ dat.yUnit= ' log power' ;
136
+ case ' phase'
137
+ dat.x = angle(dat .x );
138
+ dat.yUnit= ' phase' ;
139
+ end
0 commit comments