Home > vbmeg > functions > device > active_check > vb_merge_histgram_detail.m

vb_merge_histgram_detail

PURPOSE ^

SYNOPSIS ^

function [h,x] = vb_merge_histgram_detail(h1,x1,h2,x2)

DESCRIPTION ^

 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    [h,x] = vb_merge_histgram_detail(h1,x1,h2,x2)
0002 %
0003 % Copyright (C) 2011, ATR All Rights Reserved.
0004 % License : New BSD License(see VBMEG_LICENSE.txt)
0005 
0006 %h(n) = num of data in x(n) +- dx/2, dx =  x(2)-x(1)
0007 N1 = length(x1);
0008 N2 = length(x2);
0009 d1 = x1(2) - x1(1);
0010 d2 = x2(2) - x2(1);
0011 
0012 if max(x1)==max(x2) && N1==N2
0013     h = h1 + h2;
0014     x = x1;
0015 else
0016     XMAX = max(max(x1),max(x2));
0017     XMIN = min(min(x1),min(x2));
0018     dx = min(d1,d2);
0019     N  = ceil((XMAX - XMIN)/dx)+1;
0020     h  = zeros(N,1);
0021     x  = (0:N-1)*dx + XMIN;
0022     
0023     for n=1:N
0024         % n-th bin for new histgram h(n)
0025         xmax = (x(n) + dx/2);
0026         xmin = (x(n) - dx/2);
0027         
0028         % find h1-bin included in  [xmin xmax]
0029         ix = find( x1 >= xmin & x1 < xmax);
0030         if ~isempty(ix)
0031             for j=1:length(ix)
0032                 m  = ix(j); 
0033                 xx = x1(m); % mid point of h1(m)
0034                 % upper % lower bound of h1(m) in [xmin xmax]
0035                 xup  = min(xx + d1/2 , xmax);
0036                 xlow = max(xx - d1/2 , xmin);
0037                 % add number of h1(m) which is included in [xmin xmax]
0038                 h(n) = h(n) + h1(m) * (xup - xlow)/d1;
0039             end
0040         end
0041         
0042         % find h2-bin included in  [xmin xmax]
0043         ix = find( x2 >= xmin & x2 < xmax);
0044         if ~isempty(ix)
0045             for j=1:length(ix)
0046                 m  = ix(j); 
0047                 xx = x2(m); % mid point of h2(m)
0048                 % upper % lower bound of h2(m) in [xmin xmax]
0049                 xup  = min(xx + d2/2 , xmax);
0050                 xlow = max(xx - d2/2 , xmin);
0051                 % add number of h2(m) which is included in [xmin xmax]
0052                 h(n) = h(n) + h2(m) * (xup - xlow)/d2;
0053             end
0054         end
0055     end
0056 end
0057

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005