A. Appendix

```
1 function samplResul=BM(para0,weigh)
2 %===== PROBLEM DEFINITION 1 (Required Parameters)================
3 WorkName='Battery'; % work results are saved by WorkName
4 TimeUnit='weeks'; % time unit name
5 time=(0:50)'; % time including both at measurement and at prediction
6 measuData=[0.9951 0.9826 0.9750 0.9736 0.9424 0.9381 ...
7 0.9300 0.9203 0.9114 0.8952]'; % measured data at time (0:9)
8 thres=0.7; % threshold - critical value
9 ParamName=['b'; 's']; % model parameters' name to be estimated
10 prioDisPar=[0 0.05; % parameter prior distributions
11 1e-5 0.1];
12 Ns=5000; % num. of samples for MCMC simulation
13 burnIn=0.2; % burn-in fraction
14 signiLevel=5; % significance level for C.I. and P.I.
15 %============================================================
16 %%% Bayesian parameter estimation with MCMC
17 p=size(ParamName,1); % num. of parameters
18 k1=length(measuData); % num. of data
19 sampl(:,1)=para0; % Initial samples of parameters
20 [,jPdf0]=BMappl(para0,ParamName,time(1:k1),measuData,prioDisPar);
21 for i=2:Ns/(1-burnIn) %% MCMC Process
```
Prognostics 102: Efficient Bayesian-Based Prognostics Algorithm in MATLAB DOI: http://dx.doi.org/10.5772/intechopen.82781

22 para1(:,1)=para0+weigh.\*(2\*rand(p,1)-1); % sample from proposal dist. 23 [,jPdf1]=BMappl(para1,ParamName,time(1:k1),measuData,prioDisPar); 24 if rand<(jPdf1/jPdf0) && jPdf1>0 % acceptance criterion 25 para0=para1; 26 jPdf0=jPdf1; 27 end 28 sampl(:,i)=para0; % new MCMC sample 29 end 30 nBurn=Ns/(1-burnIn)-Ns; % No. of effective MCMC samples 31 samplResul=sampl(:,nBurn+1:end); % Final Sampling results 32 %%% RUL prediction 33 for k=1:length(time(k1:end)) % degradation prediction 34 [degrPreCon(k,:),]=BMappl(samplResul,ParamName,time(k1-1+k),[],[]); 35 degraPredi(k,:)=degrPreCon(k,:)+normrnd(0,samplResul(end,:)); 36 end 37 for i=1:Ns % RUL prediction 38 RUL(i)=interp1(degrPreCon(:,i),time(k1:end),thres,'pchip') - time(k1); 39 end 40 %%% POST-PROCESSING 41 Index=isnan(RUL); RUL(Index)=[]; 42 perceValue=[50 signiLevel 100-signiLevel]; % median & confidence intervals 43 rulPerce=prctile(RUL,perceValue); %percentiles of RUL 44 figure(1); 45 for j=1:p % plotting MCMC sample trace 46 subplot(p,1,j); % for all model parameters 47 plot(samplResul(j,:)); 48 ylabel(ParamName(j,:)); 49 title('MCMC sample trace'); 50 end 51 figure(2); set(gca,'fontsize',14); hist(RUL,30); % RUL histogram 52 xlim([min(RUL) max(RUL)]); xlabel(['RUL' ' (' TimeUnit ')']); 53 titleName=['at ' num2str(time(k1)) ' ' TimeUnit]; title(titleName) 54 fprintf( '\n # Percentiles of RUL at %g cycles \n', time(k1)) 55 fprintf('\n %gprct: %g, median: %g, %gprct: %g \n' , perceValue(2), ... 56 rulPerce(2), rulPerce(1), perceValue(3), rulPerce(3)) 57 Name=[WorkName ' at ' num2str(time(k1)) '.mat']; save(Name); % save work 58 end 59 % 60 function [degraModel, poste]=BMappl(param,ParamName,t,measuData, prioDisPar) 61 % Evaluate the degradation model or posterior PDF 62 for j=1:size(param,1) 63 eval([ParamName(j,:) '=param(j,:);']); 64 end 65 %===== PROBLEM DEFINITION 2 (model equation)==================== 66 degraModel=exp(-b.\*t); 67 %=========================================================== 68 if isempty(measuData) 69 poste=0; 70 else 71 prior=prod(unifpdf(param,prioDisPar(:,1),prioDisPar(:,2))); % prior 72 likel=(1./s).^length(measuData) ... % likelihood

5. Conclusions

Figure 9.

A. Appendix

24

correlation between multiple parameters.

Correlation between the two Paris-Erdogan model parameters.

Fault Detection, Diagnosis and Prognosis

11 1e-5 0.1];

1 function samplResul=BM(para0,weigh)

This paper presents a Bayesian-based prognostics algorithm with a MATLAB code. This code is constructed with simply 76 lines in the case of a battery degradation example. Users can easily modify this code as per their own application. As an example of code modification, the case of crack growth model is also presented. The paper also provided several MATLAB scripts to help plot the degradation curve and

2 %===== PROBLEM DEFINITION 1 (Required Parameters)================ 3 WorkName='Battery'; % work results are saved by WorkName 4 TimeUnit='weeks'; % time unit name 5 time=(0:50)'; % time including both at measurement and at prediction

7 0.9300 0.9203 0.9114 0.8952]'; % measured data at time (0:9) 8 thres=0.7; % threshold - critical value 9 ParamName=['b'; 's']; % model parameters' name to be estimated 10 prioDisPar=[0 0.05; % parameter prior distributions

12 Ns=5000; % num. of samples for MCMC simulation 13 burnIn=0.2; % burn-in fraction 14 signiLevel=5; % significance level for C.I. and P.I. 15 %============================================================

17 p=size(ParamName,1); % num. of parameters 18 k1=length(measuData); % num. of data 19 sampl(:,1)=para0; % Initial samples of parameters 20 [,jPdf0]=BMappl(para0,ParamName,time(1:k1),measuData,prioDisPar); 21 for i=2:Ns/(1-burnIn) %% MCMC Process

6 measuData=[0.9951 0.9826 0.9750 0.9736 0.9424 0.9381 ...

16 %%% Bayesian parameter estimation with MCMC

```
73 .*exp(-0.5./s.^2.*norm(measuData-degraModel)^2);
74 poste=likel.*prior; % posterior
75 end
76 end
```
References

Laboratory; 2004

[1] Giurgiutiu V. Structural Health Monitoring with Piezoelectric Wafer Active Sensors. 2nd Edition. Waltham, MA, USA: Academic Press; 2014

DOI: http://dx.doi.org/10.5772/intechopen.82781

Prognostics 102: Efficient Bayesian-Based Prognostics Algorithm in MATLAB

[9] An D, Choi J-H, Kim NH. Prognostics 101: A tutorial for particle filter-based prognostics algorithm using Matlab. Reliability Engineering and System Safety. 2013;115:161-169. DOI: 10.1016/

[10] Goebel KB, Saha A, Saxena JR, et al.

management. IEEE Instrumentation and Measurement Magazine. 2008;11(4):

[12] Bayes T, Price R. An essay towards solving a problem in the doctrine of chances. By the late rev. Mr. Bayes, communicated by Mr. Price, in a letter

Philosophical Transactions of the Royal Society of London. 1763;53:370-418.

Pattabhiraman S. Fatigue life prediction

[14] Athanasios P, editor. Probability, Random Variables, and Stochastic Processes. New York: McGraw-Hill;

[15] Gelman A, Carlin JB, Stern HS, et al., editors. Bayesian Data Analysis. New York: Chapman & Hall; 2004

[16] Casella G, Robert CP, Wells MT. Generalized Accept-Reject Sampling Schemes. Lecture Notes-Monograph Series. Vol. 45. Beachwood: Institute of

[17] Glynn PW, Iglehart DL. Importance sampling for stochastic simulations.

Mathematical Statistics; 2004.

Prognostics in battery health

[11] Guan X, Jha R, Liu Y. Model selection, updating and averaging for probabilistic fatigue damage prognosis. Structural Safety. 2011;33(3):242-249

to John Canton, A. M. F. R. S.

DOI: 10.1098/rstl.1763.0053

[13] An D, Choi J-H, Kim NH,

based on Bayesian approach to incorporate field data into probability model. Structural Engineering and Mechanics. 2011;37(4):427-442

j.ress.2013.02.019

33-40

1984

pp. 342-347

[2] Sohn H, Farrar CR, Hemez FM, Czarnecki JJ, Shunk DD, Stinemates DW, et al. "A Review of Structural Health Monitoring Literature: 1996– 2001," Report Number LA-13976-MS. Los Alamos, NM: Los Alamos National

[3] Kim NH, An D, Choi J-H. Prognostics and Health Management of Engineering Systems: An introduction. Switzerland: Springer International Publishing; 2017. DOI: 10.1007/978-3-319-44742-1

[4] Si XS, Wang W, Hu CH, Zhou DH. Remaining useful life estimation—A review on the statistical data driven approaches. European Journal of Operational Research. 2011;213:1-14

[5] Lee J, Wu F, Zhao W, Ghaffari M, Liao L, Siegel D. Prognostics and health

[6] Saha B, Goebel K, Christophersen J. Comparison of prognostic algorithms for estimating remaining useful life of batteries. Transactions of the Institute of Measurement and Control. 2009;31

[7] Xing Y, Williard N, Tsui K-L, Pecht M. A comparative review of prognosticsbased reliability methods for Lithium batteries. In: Prognostics and System Health Management Conference, Shenzhen, China; 24-25 May 2011

[8] Zhang J, Lee J. A review on prognostics and health monitoring of Li-ion battery. Journal of Power Sources. 2011;196:6007-6014

management design for rotary machinery systems—reviews, methodology and applications. Mechanical Systems and Signal Processing. 2014;42(1–2):314-334

(3–4):293-308

27
