Home > bml > signal > bml_envelope_binabs.m

bml_envelope_binabs

PURPOSE ^

BML_ENVELOPE_BINABS Calculate envelope of a signal using the binabs method

SYNOPSIS ^

function env = bml_envelope_binabs(cfg, data)

DESCRIPTION ^

 BML_ENVELOPE_BINABS Calculate envelope of a signal using the binabs method

 The envelope is calculated as the maximum of the absolute value in
 bins of 'bin_size' samples. 

 Use as
   env = bml_envelope_binabs(data)
   env = bml_envelope_binabs(cfg, data)

 cfg is a configureation struct with the following fields
 cfg.freq - integer: intended output sampling frequency (default 100Hz)
 cfg.bin_size - integer: size of the bin. If given overwrites cfg.target_fsample

 data - FT_DATATYPE_RAW
 
 Returns a FT_DATATYPE_RAW

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function env = bml_envelope_binabs(cfg, data)
0002 
0003 % BML_ENVELOPE_BINABS Calculate envelope of a signal using the binabs method
0004 %
0005 % The envelope is calculated as the maximum of the absolute value in
0006 % bins of 'bin_size' samples.
0007 %
0008 % Use as
0009 %   env = bml_envelope_binabs(data)
0010 %   env = bml_envelope_binabs(cfg, data)
0011 %
0012 % cfg is a configureation struct with the following fields
0013 % cfg.freq - integer: intended output sampling frequency (default 100Hz)
0014 % cfg.bin_size - integer: size of the bin. If given overwrites cfg.target_fsample
0015 %
0016 % data - FT_DATATYPE_RAW
0017 %
0018 % Returns a FT_DATATYPE_RAW
0019 
0020 DEFAULT_TARGET_FSAMPLE=100;
0021 
0022 if nargin==1
0023   data=cfg;
0024   cfg=[];
0025 end
0026 
0027 if ~ismember('fsample',fields(data))
0028     data.fsample = round(1/mean(diff(data.time{1})),9,'significant');
0029 end
0030 
0031 freq            = bml_getopt(cfg,'freq',DEFAULT_TARGET_FSAMPLE);
0032 bin_size        = bml_getopt(cfg,'bin_size',round(data.fsample/freq));
0033     
0034 if abs(data.fsample/freq - bin_size) > 0.1
0035   warning(char(strcat('Specified envelope freq ',num2str(freq),' not possible. Using ',num2str(data.fsample/bin_size))));
0036 end
0037 
0038 env=struct();
0039 env.trial={};
0040 env.time={};
0041 
0042 for i=1:numel(data.trial)
0043   
0044     n_bins=floor(size(data.trial{i},2)./bin_size);
0045   
0046   T = data.trial{i};
0047   t = data.time{i};
0048   
0049   env.trial{i} = reshape(max(...
0050         reshape(abs(T(:,1:n_bins*bin_size)),[size(T,1), bin_size, n_bins]),...
0051       [],2),...
0052     [size(T,1) n_bins]);
0053   
0054     env.time{i} = mean(reshape(t(1:n_bins*bin_size),[bin_size, n_bins]),1);
0055   
0056 end
0057 
0058 env.fsample = data.fsample/bin_size;
0059 env.label = data.label;
0060 
0061 env.cfg = struct();
0062 env.cfg.envelope = "binabs";
0063 env.cfg.bin_size = bin_size;
0064 if isfield(data,'cfg')
0065   env.cfg.previous = data.cfg;
0066 end
0067 
0068 if ismember('hdr',fieldnames(data))
0069   env.hdr = data.hdr;
0070 end
0071 
0072

Generated on Tue 25-Sep-2018 10:08:19 by m2html © 2005