calc_difference_data

PURPOSE ^

CALC_DIFFERENCE_DATA: calculate difference data between

SYNOPSIS ^

function dva = calc_difference_data( data1, data2, fwd_model)

DESCRIPTION ^

 CALC_DIFFERENCE_DATA: calculate difference data between
   two eidors data vectors
 dva = calc_difference_data( meas1, meas2, fwd_model)
   
  dva   = Matrix n_meas x n_time_steps of difference meas
  meas1 = measurement object (or matrix) at time1 (homogeneous)
  meas2 = measurement object (or matrix) at time2 (inhomogeneous)
  fwd_model (optional, if provided in meas1 and meas2)

  if data1==0, then just process data2 like absolute data

 This code appears simple, but there are a number of tricks
  to remember, so it is best to factor it out. Issues are
  1) normalize_data, 2) remove zero meas from adjacent systems,
  3) allow both raw data and eidors_obj formats for data

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function dva = calc_difference_data( data1, data2, fwd_model)
0002 % CALC_DIFFERENCE_DATA: calculate difference data between
0003 %   two eidors data vectors
0004 % dva = calc_difference_data( meas1, meas2, fwd_model)
0005 %
0006 %  dva   = Matrix n_meas x n_time_steps of difference meas
0007 %  meas1 = measurement object (or matrix) at time1 (homogeneous)
0008 %  meas2 = measurement object (or matrix) at time2 (inhomogeneous)
0009 %  fwd_model (optional, if provided in meas1 and meas2)
0010 %
0011 %  if data1==0, then just process data2 like absolute data
0012 %
0013 % This code appears simple, but there are a number of tricks
0014 %  to remember, so it is best to factor it out. Issues are
0015 %  1) normalize_data, 2) remove zero meas from adjacent systems,
0016 %  3) allow both raw data and eidors_obj formats for data
0017 
0018 % (C) 2006 Andy Adler. License: GPL version 2 or version 3
0019 % $Id: calc_difference_data.m 3351 2012-07-01 21:37:37Z aadler $
0020 
0021 data_width= max(num_frames(data1), num_frames(data2));
0022 
0023 try if data1.type == 'data'
0024    data1= data1.meas;
0025 end; end
0026 
0027 try if data2.type == 'data'
0028    data2= data2.meas;
0029 end; end
0030 
0031 if all(size(data1) == [1,1]) && (data1 == 0)
0032    dva =  filt_data( fwd_model, data2, data_width );
0033    return;
0034 end
0035 
0036 fwd_model = mdl_normalize(fwd_model,mdl_normalize(fwd_model));
0037 
0038 fdata1 = filt_data( fwd_model, data1, data_width );
0039 fdata2 = filt_data( fwd_model, data2, data_width );
0040 
0041 if mdl_normalize(fwd_model)
0042    dva= fdata2 ./ fdata1 - 1;
0043 else   
0044    dva= fdata2 - fdata1;
0045 end
0046 
0047 function nf= num_frames(d0)
0048    if isnumeric( d0 )
0049       nf= size(d0,2);
0050    elseif strcmp( d0(1).type, 'data' );
0051       nf= size(horzcat(d0(:).meas),2);
0052    else
0053       error('Problem calculating number of frames');
0054    end
0055    
0056 % test for existance of meas_select and filter data
0057 function d2= filt_data(fwd_model, d0, data_width )
0058    if ~isnumeric( d0 )
0059        % we probably have a 'data' object
0060 
0061        l_obj = length(d0);
0062        d1 = zeros( length( d0(1).meas ), l_obj);
0063        for i=1:l_obj
0064           if strcmp( d0(i).type, 'data' )
0065               d1(:,i) = d0(i).meas;
0066           else
0067               error('expecting an object of type data');
0068           end
0069        end
0070 
0071    else
0072       % we have a matrix of data. Hope for the best
0073       d1 = d0;
0074    end
0075 
0076    d1= double(d1); % ensure we can do math on our object
0077 
0078    if isfield(fwd_model,'meas_select') && ...
0079      ~isempty(fwd_model.meas_select);
0080       % we have a meas_select parameter
0081 
0082       meas_select= fwd_model.meas_select;
0083       if     size(d1,1) == length(meas_select)
0084          d2= d1(meas_select,:);
0085       elseif size(d1,1) == sum(meas_select==1)
0086          d2= d1;
0087       else
0088          error('data size does not match meas_select');
0089       end
0090    else
0091       d2= d1;
0092    end
0093 
0094    if nargin==3 % expand to data width
0095       d2_width= size(d2,2);
0096       if d2_width == data_width
0097          % ok
0098       elseif d2_width == 1
0099          d2= d2(:,ones(1,data_width));
0100       else
0101          error('inconsistent difference data: (%d ~= %d)',  ...
0102                d2_width, data_width);
0103       end
0104    end
0105

Generated on Fri 30-Dec-2022 19:44:54 by m2html © 2005