-
Notifications
You must be signed in to change notification settings - Fork 0
/
batch_features_stft.m
53 lines (40 loc) · 1.08 KB
/
batch_features_stft.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
function [FEATURES,F,T,PARAMETERS]=batch_features_stft(DATA,FS,varargin)
% typecast
if ~isa(DATA,'double')
DATA=double(DATA);
end
len=20;
overlap=18;
padding=[.2 .2];
nparams=length(varargin);
if mod(nparams,2)>0
error('ephysPipeline:argChk','Parameters must be specified as parameter/value pairs!');
end
for i=1:2:nparams
switch lower(varargin{i})
case 'padding'
padding=varargin{i+1};
case 'len'
len=varargin{i+1};
case 'overlap'
overlap=varargin{i+1};
end
end
len=round((len/1e3)*FS);
overlap=round((overlap/1e3)*FS);
nfft=2^nextpow2(len);
padding=round(padding*FS);
[nsamples,ntrials]=size(DATA(padding(1):end-padding(2),:));
% get the time and frequency vectors
[T,F]=zftftb_specgram_dim(nsamples,len,overlap,nfft,FS);
FEATURES=zeros(length(F),length(T),ntrials,'single');
fprintf('\n');
for i=1:ntrials
fprintf('Trials %i of %i\r',i,ntrials)
FEATURES(:,:,i)=single(spectrogram(DATA(padding(1):end-padding(2),i),len,overlap,nfft));
end
PARAMETERS.win_size=len;
PARAMETERS.win_nfft=nfft;
PARAMETERS.win_overlap=overlap;
PARAMETERS.padding=padding;
PARAMETERS.fs=FS;