1 | function smc_simple(N,n)
|
---|
2 | system.sigma=0.01;
|
---|
3 | system.ny=0.02;
|
---|
4 |
|
---|
5 | system.x=0.5;
|
---|
6 | apriori=[0 1];
|
---|
7 |
|
---|
8 | x_1=apriori(:,1)*ones(1,N)+apriori(:,2:end)*(0.5-rand(1,N)); vahy=1/N*ones(1,N);
|
---|
9 | N_tresh=N/2;
|
---|
10 | stav=[]; hranice=stav;
|
---|
11 |
|
---|
12 | for i=1:n
|
---|
13 | x_0=my_sample(vahy,x_1);
|
---|
14 |
|
---|
15 | x_1=model_simple(x_0,system);
|
---|
16 |
|
---|
17 | system.x=model_simple(system.x,system);
|
---|
18 | system.pozorovani=system.x+sqrt(system.ny)*randn;
|
---|
19 |
|
---|
20 | reziduum=system.pozorovani*ones(1,N)-x_1;
|
---|
21 | p_v=exp(-(reziduum.^2/system.ny)/2);
|
---|
22 | vahy=p_v/sum(p_v);
|
---|
23 |
|
---|
24 | %porovnani(x_1,vahy,system.x);
|
---|
25 |
|
---|
26 | if (1/(vahy*vahy')<N_tresh)
|
---|
27 | [x_1 vahy]=my_resample(x_1,vahy);
|
---|
28 | % porovnani(x_1(1,:),vahy,system.x(1));
|
---|
29 | end
|
---|
30 |
|
---|
31 | %x_0=my_sample(vahy,x_1);
|
---|
32 | %H=kalman_filter(H,u(:,i),system);
|
---|
33 |
|
---|
34 | stav=[stav [system.x; mean(x_1,2)]];
|
---|
35 | hranice=[hranice [min(x_1,[],2); max(x_1,[],2)]];
|
---|
36 | %ztrata= ztrata+u'*system.gamma*u+(system.x-system.x_opt)'*system.ksi*(system.x-system.x_opt);
|
---|
37 |
|
---|
38 | end
|
---|
39 | %plot(abs(stav(1,:)-stav(2,:))); hold on
|
---|
40 | kresli(stav,hranice)
|
---|
41 | end |
---|