%% 功能:加噪声百分比,计算标准差
clear;clc;
% 用法:将计算好的标准差与归一化后的值做处理,在进行图像重建。
zsh=randn(1,66); % 12电极ERT共有66个电压测量值;randn:高斯分布;rand:均匀分布。
zsh=zsh/std(zsh); % std(A),用于求向量A的标准差,或者矩阵A中各列元素的标准差;
zsh=zsh-mean(zsh);
save zsh.mat zsh %随机噪声
% nc=nc1.*(1+bc*yt);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%噪声添加程序
%load zsh.mat
%load qiu3dianrong.mat %加载电容值
c0=[-1.5117925232711515E-13 -1.4322213042492657E-14 -1.5123130897932812E-13 -1.5121646697781296E-13 -9.51223779553018E-15 -9.517189884628265E-15 -1.5169754349814652E-13 -6.815596175306932E-15 -3.866957547325481E-15 -2.530125959613966E-15 -3.857495394141595E-15 -1.506747747463111E-13 -1.42902568887826E-14 -1.5140462240785573E-13 -1.5243178257832838E-13 -9.462577407064165E-15 -9.499352748057126E-15 -3.874090829019704E-15 -6.828127901099486E-15 -3.855572164428265E-15 -2.5369658714183915E-15 -1.512001557709205E-13 -9.446848507330196E-15 -1.531620553827627E-13 -1.510793073793441E-13 -9.470433117783518E-15 -2.5410141002844347E-15 -3.86817552261003E-15 -6.7979609028349984E-15 -3.867218575261952E-15 -9.42582616681368E-15 -9.50094222012667E-15 -1.5294709870551905E-13 -1.5143630043785185E-13 -3.855380968679781E-15 -2.5309661638372045E-15 -3.83817511353071E-15 -6.769835265257976E-15 -1.377129373181391E-13 -1.0299881155482145E-14 -1.3628001480886476E-13 -1.5067085984851488E-13 -1.5192663112896076E-13 -9.450767516844925E-15 -9.434333891468226E-15 -1.3749085964698813E-13 -1.0341110572400593E-14 -9.487160715458925E-15 -1.5053393000122257E-13 -1.5119005842333804E-13 -9.49935790996063E-15 -1.3837612822978913E-13 -9.510632793415752E-15 -9.476322373446236E-15 -1.5019476731725693E-13 -1.5139874788176357E-13 -1.5161623526940677E-13 -9.492694774391104E-15 -9.439830529369015E-15 -1.5064077748259136E-13 -1.5084781481347618E-13 -1.430467654879652E-14 -1.5056332013961376E-13 -1.5028887175290893E-13 -1.430298048011502E-14 -1.5011998169094832E-13]*-1E15;
c1=[-2.485978465746143E-13 -5.425629594891946E-14 -2.482967106946029E-13 -2.337432256104551E-13 -3.523898438453706E-14 -3.525969175037706E-14 -2.344397945415713E-13 -2.620864719030978E-14 -1.6155216107424545E-14 -1.0966463590223961E-14 -1.611492136369016E-14 -2.4782786925655755E-13 -5.4140941627877004E-14 -2.339831213852723E-13 -2.3530832706653545E-13 -3.5104182303324706E-14 -3.5204788098966223E-14 -1.6182286385602763E-14 -2.625858212167667E-14 -1.6110510524818545E-14 -1.0995532192627297E-14 -2.482322252404416E-13 -3.502412915485264E-14 -2.3597405293511345E-13 -2.3363928622396505E-13 -3.511528872655983E-14 -1.1012187427854922E-14 -1.6157974646993867E-14 -2.6148689634841295E-14 -1.6148940778033642E-14 -3.493584669844816E-14 -3.518831428355143E-14 -2.3578209505614003E-13 -2.339955555866332E-13 -1.6108483816395217E-14 -1.0971081806950277E-14 -1.603874006781357E-14 -2.6061660118402332E-14 -2.1450911537139014E-13 -3.656363450150927E-14 -2.1299489011993546E-13 -2.328728169125313E-13 -2.343256375815066E-13 -3.500399157239287E-14 -3.495744135281768E-14 -2.1437310967064712E-13 -3.670207295489718E-14 -3.5153320162058614E-14 -2.3287729831882333E-13 -2.3351748968232406E-13 -3.517633991498438E-14 -2.154995912151051E-13 -3.523195645922658E-14 -3.5116440305841546E-14 -2.3224055890584273E-13 -2.3390823692956804E-13 -2.3418678672167666E-13 -3.517067646715002E-14 -3.498542262720153E-14 -2.3296581189006766E-13 -2.480781066158103E-13 -5.4147980752214844E-14 -2.4759784862566475E-13 -2.471319022217223E-13 -5.414123050519812E-14 -2.46867749337775E-13]*-1E15;
clz=[-1.5115123253552843E-13 -1.4763155590806938E-14 -1.5096538139472765E-13 -1.5107926565855653E-13 -9.676537662255217E-15 -9.367734129254848E-15 -1.5152766960043687E-13 -6.739339047432604E-15 -3.7751487608794916E-15 -2.9167736991232825E-15 -4.1228979299502935E-15 -1.517947212178303E-13 -1.3998637852575154E-14 -1.5130801503094675E-13 -1.5245842192720213E-13 -9.76773160187972E-15 -9.310862590020248E-15 -3.781081388339134E-15 -6.679808539333324E-15 -4.4652101844562175E-15 -2.785416333780782E-15 -1.5212172931029522E-13 -9.939293963162666E-15 -1.6410303529381168E-13 -1.5766919367326402E-13 -9.879751113074005E-15 -2.7267327456154767E-15 -4.3102207483309075E-15 -1.1317048833250437E-14 -5.077580521449147E-15 -9.252626124560339E-15 -1.025258929145847E-14 -1.5220724536256403E-13 -1.5117074055084932E-13 -3.7405499731337874E-15 -2.411929498826926E-15 -4.569033077961428E-15 -7.258138223341946E-15 -1.3770052374658712E-13 -1.018250615644883E-14 -1.3601717597162005E-13 -1.5047289967739855E-13 -1.5164714048603783E-13 -1.0343075945371188E-14 -1.0099057212460672E-14 -1.4238377002764205E-13 -1.0669376443355632E-14 -9.638660415631784E-15 -1.5037947981782198E-13 -1.6165077005031857E-13 -1.3505251431894497E-14 -1.3700953442348816E-13 -9.604957118048431E-15 -1.0088234528177653E-14 -1.5933865523653655E-13 -1.5720883297083044E-13 -1.5123138875923884E-13 -9.240653825228916E-15 -1.1500270037430592E-14 -1.522672298914483E-13 -1.5047169571775575E-13 -1.559431850764603E-14 -1.5170444506619106E-13 -1.5156089834286565E-13 -1.5657789866079076E-14 -1.6607007362521096E-13] *-1E15;
nc=(clz'-c0)./(c1-c0);
prompt={'输入要求的百分比%: pp='};%设置提示字符串
name='百分比与标准差';%设置标题
numlines=1; %指定输入数据的行数
defAns={'1'}; %设定默认值
%Resize='on'; %设定对话框尺寸可调节
options.Resize='on';
options.WindowStyle='normal';
options.Interpreter='tex';
answer=inputdlg(prompt,name,numlines,defAns,options);%创建输入对话框.
if isempty(answer)
answer = defAns;
%return
%continue
elseif iscell(answer)
pp=str2double(char(answer(1,1)));
end
bc=1*0.00001;%%%%标准差方法
while(1)
%bc=9.65361*0.01;%%%%标准差方法
%yt=randn(1,nt);
%yt=yt/std(yt);
%yt=yt-mean(yt);
nc1=nc.*(1+bc*zsh);%bc为标准差
pt=norm(nc1-nc)./norm(nc);
pt1=pt*100;
if pt1<=pp
bc=bc+0.0000001;
else
break;
end
end
bc1=bc*100;
hs=msgbox({['噪声标准差为: ',num2str(bc1),'x10-2'];['百分比为:',num2str(pt1),'%']}); %可以实现提示窗口
ht=findobj(hs, 'Type', 'text'); % 查找hs的文本类型
set(ht,'FontSize',20, 'Unit', 'normal'); % 设置字体尺寸,字体单位
set(hs,'Position',[500 300 250 100]); % 设置左,底,宽,高