0001 function dva = calc_difference_data( data1, data2, fwd_model)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
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
0057 function d2= filt_data(fwd_model, d0, data_width )
0058 if ~isnumeric( d0 )
0059
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
0073 d1 = d0;
0074 end
0075
0076 d1= double(d1);
0077
0078 if isfield(fwd_model,'meas_select') && ...
0079 ~isempty(fwd_model.meas_select);
0080
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
0095 d2_width= size(d2,2);
0096 if d2_width == data_width
0097
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