Skip to content

Commit f851eaf

Browse files
author
Stephanie
committed
bug fixed
1 parent 04859b5 commit f851eaf

File tree

1 file changed

+45
-46
lines changed

1 file changed

+45
-46
lines changed

processing/proc_spectrogram.m

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,34 @@
66
% dat = proc_spectrogram(dat, freq, <OPT>)
77
% dat = proc_spectrogram(dat, freq, Window, <OPT>)
88
% dat = proc_spectrogram(dat, freq, Window, NOverlap,<OPT>)
9-
%
9+
%
1010
%Arguments:
1111
% 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
1515
% usally faster).
1616
% 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
1818
% to the length of WINDOW, and then windows each
1919
% segment with the vector specified in WINDOW. If WINDOW is an integer,
2020
% the data is divided into segments of length equal to that integer value, and a
2121
% Hamming window of equal length is used. If WINDOW is not specified, the
2222
% 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
2626
% representation is defined for each sample)
2727
% 'CLab' - specifies for which channels the spectrogram is calculated.
2828
% (default '*')
2929
% 'Output' - Determines if and how the FFT coefficients are processed.
3030
% 'complex' preserves the complex output (with both phase and
3131
% 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'.
3434
%Returns:
3535
% DAT - updated data structure with a higher dimension.
36-
% For continuous data, the dimensions correspond to
36+
% For continuous data, the dimensions correspond to
3737
% time x frequency x channels. For epoched data, time x
3838
% frequency x channels x epochs.
3939
% The coefficients are complex. You can obtain the amplitude by
@@ -48,30 +48,30 @@
4848
% 2010, 2015
4949

5050
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+
};
5656

5757
if nargin==0,
58-
dat= props; return
58+
dat= props; return
5959
end
6060

6161
misc_checkType(dat,'!STRUCT(x fs)');
6262
misc_checkType(freq,'!DOUBLE[-]');
6363

6464
% Parse other arguments
6565
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
7575
end
7676

7777
opt= opt_proplistToStruct(varargin{:});
@@ -89,9 +89,9 @@
8989
dat = misc_history(dat);
9090

9191
if numel(freq)==1
92-
nfreq = freq;
92+
nfreq = freq;
9393
else
94-
nfreq = numel(freq);
94+
nfreq = numel(freq);
9595
end
9696

9797
%% Spectrogram
@@ -102,12 +102,12 @@
102102
% Process spectrogram channel- and epoch-wise
103103
X=dat.x;
104104
dat.x=[];
105-
if ndims(dat.x) == 2 % cnt
105+
if ndims(X) == 2 % cnt
106106
for chan=1:sz(2)
107107
[S,F,T] = spectrogram(X(:,chan),opt.Window,opt.NOverlap,freq,dat.fs);
108108
dat.x(:,:,chan)=S;
109109
end
110-
elseif ndims(dat.x)==3 % epoched
110+
elseif ndims(X) == 3 % epoched
111111
for chan=1:sz(3)
112112
for seg=1:sz(2)
113113
[S,F,T] = spectrogram(X(:,seg,chan),opt.Window,opt.NOverlap,freq,dat.fs);
@@ -122,19 +122,18 @@
122122
dat.zUnit = 'Hz';
123123

124124
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

Comments
 (0)