Home > functions > estimation > bayes > vb_overlapped_timewindow_weight.m

vb_overlapped_timewindow_weight

PURPOSE ^

Temporal smoothing window function

SYNOPSIS ^

function [weight ,Tindex, Nindex, Nsample] =vb_overlapped_timewindow_weight(Twindow, Tsample, tsubsamp, mode)

DESCRIPTION ^

 Temporal smoothing window function
 [weight ,Tindex, Nindex]= ...
        vb_overlapped_timewindow_weight(Twindow, Tsample, tsubsamp, mode)
 --- Input
 Twindow(n,:) = [Tstart(n), Tend(n)] : Start and end for n-th time window
 Tsample  : Total time sample number in MEG data
 tsubsamp : subsampled time index
 if tsubsamp = [], tsubsamp = 1:Tsample
 mode = 0 : weighted average
      = 1 : non-overlapped concatenation is done
            current time series of each time windows are concatenated
 --- Output
 Tindex{n} : n-th window time index in the absolute time index
 Nindex{n} : n-th window time index within the subsampled data
 weight{n} : n-th window weight for window average
 Nsample   : # of time sample for calculation

 Modified by Taku Yoshioka 2005-07-22
 2005/08/16 Modified O. Yamshita
 2006/10/3 M. Sato
  added non-overlapped concatenation mode

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function   [weight ,Tindex, Nindex, Nsample] = ...
0002                 vb_overlapped_timewindow_weight(Twindow, Tsample, tsubsamp, mode)
0003 % Temporal smoothing window function
0004 % [weight ,Tindex, Nindex]= ...
0005 %        vb_overlapped_timewindow_weight(Twindow, Tsample, tsubsamp, mode)
0006 % --- Input
0007 % Twindow(n,:) = [Tstart(n), Tend(n)] : Start and end for n-th time window
0008 % Tsample  : Total time sample number in MEG data
0009 % tsubsamp : subsampled time index
0010 % if tsubsamp = [], tsubsamp = 1:Tsample
0011 % mode = 0 : weighted average
0012 %      = 1 : non-overlapped concatenation is done
0013 %            current time series of each time windows are concatenated
0014 % --- Output
0015 % Tindex{n} : n-th window time index in the absolute time index
0016 % Nindex{n} : n-th window time index within the subsampled data
0017 % weight{n} : n-th window weight for window average
0018 % Nsample   : # of time sample for calculation
0019 %
0020 % Modified by Taku Yoshioka 2005-07-22
0021 % 2005/08/16 Modified O. Yamshita
0022 % 2006/10/3 M. Sato
0023 %  added non-overlapped concatenation mode
0024 %
0025 % Copyright (C) 2011, ATR All Rights Reserved.
0026 % License : New BSD License(see VBMEG_LICENSE.txt)
0027 
0028 if ~exist('mode','var'), mode = 0; end;
0029 
0030 Nperiod = size(Twindow,1);
0031 Tbegin  = Twindow(:,1);
0032 Tend    = Twindow(:,2);
0033 
0034 
0035 % Temporal subsampling index
0036 if nargin <2 | isempty(tsubsamp),
0037     tsubsamp = 1:Tsample;
0038 end
0039 
0040 % Subsampling index flag
0041 Nsample = length(tsubsamp);    % # of subsampled data
0042 tflag   = zeros(1,Tsample);    
0043 tflag(tsubsamp) = 1:Nsample;
0044 
0045 % Smoothing time window function by sin^2
0046 w_smooth = cell(Nperiod,1);
0047 
0048 % First smoothing window
0049 Tperiod = Tend(1)-Tbegin(1)+1; 
0050 w_smooth{1} = ones(1,Tperiod);
0051 
0052 %
0053 % Following code is for multiple time windows
0054 %
0055 if Nperiod>=2, 
0056   if Tend(1)>Tbegin(2), 
0057     Toverlap = Tend(1)-Tbegin(2)+1;
0058     w_smooth{1}((Tperiod-Toverlap+1):Tperiod) ...
0059     = sin((pi/2)*(Toverlap:-1:1)./Toverlap).^2;
0060   end
0061 
0062   % Middle smoothing window
0063   for i=2:Nperiod-1
0064     Tperiod = Tend(i)-Tbegin(i)+1; 
0065     w_smooth{i} = sin(pi*(1:Tperiod)./Tperiod).^2;
0066   end
0067 
0068   % Last smoothing window
0069   Tperiod = Tend(end)-Tbegin(end)+1; 
0070   w_smooth{end} = ones(1,Tperiod);
0071   if Tbegin(end)<Tend(end-1), 
0072     Toverlap = Tend(end-1)-Tbegin(end)+1;
0073     w_smooth{end}(1:Toverlap) ...
0074     = sin((pi/2)*(1:Toverlap)/Toverlap).^2; 
0075   end
0076 end
0077 
0078 % Subsampling time index for each time window
0079 Tindex = cell(Nperiod,1);
0080 Nindex = cell(Nperiod,1);
0081 
0082 % Time window weighting correction
0083 cnt    = zeros(1,Nsample);
0084 
0085 % Normalized time window function
0086 weight = cell(Nperiod,1);
0087 
0088 % mode = 1 : non-overlapped concatenation
0089 nid = 0;
0090 
0091 % Time window loop
0092 for j=1:Nperiod
0093   % Subsampling time index
0094   t1  = Tbegin(j);     % start time in this period
0095   t2  = Tend(j);     % end time   in this period
0096   tt  = tflag(t1:t2);     % time index flag in this period
0097   id  = find( tt > 0 );    % subsampled index
0098   Nid = tt(id);            % index within 'tsubsamp'
0099 %  Tid = id + t1 -1;    % subsampled time index
0100   Tid = tsubsamp(Nid);    % subsampled time index
0101   T   = length(Tid);
0102 
0103   Tindex{j} = Tid;
0104   
0105   if mode == 0,
0106       Nindex{j} = Nid;
0107       weight{j} = w_smooth{j}(id); 
0108       cnt(Nid)  = cnt(Nid) + w_smooth{j}(id);
0109   else
0110       n1 = nid + 1;
0111       n2 = nid + T;
0112       Nindex{j} = n1:n2;
0113       weight{j} = ones(1,T);
0114       nid = n2;
0115   end
0116 end;
0117 
0118 % Normalization of weighting function
0119 if mode == 0,
0120     for j=1:Nperiod
0121       weight{j} = weight{j}./cnt(Nindex{j});
0122     end
0123 else
0124     Nsample = nid;
0125 end
0126 
0127 return
0128 %----- END of program -----%
0129 
0130 % DEBUG check sum is 1
0131 cnt    = zeros(1,Nsample);
0132 
0133 for j=1:Nperiod
0134   Nid = Nindex{j};
0135   cnt(Nid)  = cnt(Nid) + weight{j};
0136 end
0137 
0138 subplot(2,2,1);
0139 plot(cnt)
0140 
0141 subplot(2,2,2);
0142 
0143 for j=1:Nperiod
0144   plot(Nindex{j},weight{j});
0145   hold on
0146 end
0147 
0148 subplot(2,2,3);
0149 
0150 for j=1:Nperiod
0151   plot(Nindex{j},Tindex{j},'.');
0152   hold on
0153 end

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005