0001 function params = calc_noise_params(imdl, vh, vi )
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 warning('EIDORS:deprecated','CALC_NOISE_PARAMS is deprecated as of 02-Jul-2012. Use CALC_NOISE_FIGURE instead.');
0013
0014 if ischar(imdl) && strcmp(imdl,'UNIT_TEST'), do_unit_test, return, end
0015
0016 if 0
0017
0018 Nnoise = 1000;
0019 noise = 0.01*std(vh)*randn(size(vh,1),Nnoise);
0020 vhn= vh*ones(1,Nnoise) + noise;
0021 else
0022 noise = 0.01*std(vh)*speye(size(vh,1));
0023 vhn= vh*ones(1,size(vh,1)) + noise;
0024 end
0025
0026 signal_y = calc_difference_data( vh, vi, imdl.fwd_model);
0027 noise_y = calc_difference_data( vh, vhn, imdl.fwd_model);
0028
0029 signal_x = inv_solve(imdl, vh, vi); signal_x = signal_x.elem_data;
0030 noise_x = inv_solve(imdl, vh, vhn); noise_x = noise_x.elem_data;
0031
0032 try
0033 VOL = get_elem_volume(imdl.rec_model);
0034 catch
0035 VOL = get_elem_volume(imdl.fwd_model);
0036 end
0037 VOL = spdiags(VOL,0, length(VOL), length(VOL));
0038
0039 signal_x = VOL*signal_x;
0040 noise_x = VOL*noise_x;
0041
0042 signal_x = mean(abs(signal_x),1);
0043 noise_x = mean(std(noise_x));
0044 snr_x = signal_x / noise_x;
0045
0046 signal_y = mean(abs(signal_y),1);
0047 noise_y = mean(std(noise_y));
0048 snr_y = signal_y / noise_y;
0049
0050 params= [snr_y(:)./snr_x(:)]';
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068 function do_unit_test
0069 ll = eidors_msg('log_level',1);
0070 imdl = mk_common_model('a2t2',16); test2(imdl);
0071 imdl = mk_common_model('d2t2',16); test2(imdl);
0072 imdl = mk_common_model('a2c2',16); test2(imdl);
0073 imdl = mk_common_model('d2c2',16); test2(imdl);
0074 test1;
0075 ll = eidors_msg('log_level',ll);
0076
0077 function test1
0078
0079 fmdl = mk_library_model('pig_23kg_16el');
0080 [fmdl.stimulation fmdl.meas_select] = mk_stim_patterns(16,1,'{ad}','{ad}');
0081 fmdl = mdl_normalize(fmdl, 1);
0082 opt.noise_figure = 0.5; opt.imgsz = [64 64];
0083 imdl = mk_GREIT_model(fmdl, 0.25, [], opt);
0084
0085 img = mk_image(fmdl,1);
0086 vh = fwd_solve(img);
0087
0088 select_fcn = inline('(x-0).^2+(y-0).^2+(z-0.5).^2<0.1^2','x','y','z');
0089 mfrac = elem_select(fmdl, select_fcn);
0090 img.elem_data = img.elem_data + mfrac*0.1;
0091 vi = fwd_solve(img);
0092
0093 nf1 = calc_noise_params(imdl, vh.meas, vi.meas);
0094
0095
0096 imdl.hyperparameter.tgt_data.meas_t1 = vh.meas;
0097 imdl.hyperparameter.tgt_data.meas_t2 = vi.meas;
0098 try
0099
0100 nf2 = calc_noise_figure(imdl);
0101 catch
0102 nf2 = 0;
0103 end
0104 unit_test_cmp('Noise fig implementations',nf1, nf2, 1e-2);
0105
0106 function test2(imdl)
0107 fmdl = imdl.fwd_model;
0108
0109 img = mk_image(fmdl,1);
0110 vh = fwd_solve(img);
0111
0112 select_fcn = inline('(x-0).^2+(y-0).^2.^2<15^2','x','y','z');
0113 mfrac = elem_select(fmdl, select_fcn);
0114 img.elem_data = img.elem_data + mfrac*0.1;
0115 vi = fwd_solve(img);
0116
0117 nf1 = calc_noise_params(imdl, vh.meas, vi.meas);
0118 eidors_msg(nf1,0);
0119
0120 imdl.hyperparameter.tgt_data.meas_t1 = vh.meas;
0121 imdl.hyperparameter.tgt_data.meas_t2 = vi.meas;
0122
0123 nf2 = calc_noise_figure(imdl,[],1000);
0124 unit_test_cmp('Noise fig implementations',nf1, nf2, 1e-2);