Index: /tests/testUI.cpp
===================================================================
--- /tests/testUI.cpp (revision 159)
+++ /tests/testUI.cpp (revision 218)
@@ -153,5 +153,5 @@
 	root.Save();
 	cout << "all the transport means were saved correctly" << endl;				
-	getchar();
+	//getchar();
 
 	//////////////////////////////////// LOADING ////////////////////////////////
Index: /pmsm/simulator_zdenek/simulator.cpp
===================================================================
--- /pmsm/simulator_zdenek/simulator.cpp (revision 216)
+++ /pmsm/simulator_zdenek/simulator.cpp (revision 218)
@@ -113,12 +113,12 @@
 // === init of particular modules of simulator ===
   // PWM init
-  smer=1; smer2=1;
+  smer=-1; smer2=-1;
+  citac=0;
+  citac2=abs(0-(int)(DT/h)); //VS: oprava, je to spravne?
   citac_PR=h_reg_counter_mez;
-  citac=citac_PR;
-  citac2=abs(citac_PR-(int)(DT/h)); //VS: oprava, je to spravne?
-  
+
   // first interrupt occur after first period match => add 1 to both counter registers
-//  citac++;smer=1;
-//  citac2--;
+  citac++;smer=1;
+  citac2--;
 
   modulace=1;           // THIPWM
@@ -173,5 +173,5 @@
 
   for (i=0;i<3;i++)
-  { dtr[i]=ubytek(fabs(iabc[i])*0.); //VS
+  { dtr[i]=ubytek(fabs(iabc[i]));
     dd[i]=dtr[i]*.73;
   }
Index: /pmsm/sim_profiles.h
===================================================================
--- /pmsm/sim_profiles.h (revision 217)
+++ /pmsm/sim_profiles.h (revision 218)
@@ -65,5 +65,5 @@
 
 void sim_profile_2slowrevs(double &Ww,bool load=false) {
-	static int k_rampa=10;
+	static int k_rampa=1;
 
 	if ((t>0.2)&&(t<0.8)) {
@@ -76,2 +76,13 @@
 	if (!load) x[8]=0.0;
 }
+
+void sim_profile_vec01t(double &Ww, vec &vecWw){
+	static int ind=0;
+	static double dW;
+	double tn=t;
+	if (t>0.1*ind) {
+		ind++;
+		dW = vecWw(ind)-vecWw(ind-1);
+	}
+	Ww=vecWw(ind-1)+(t-0.1*(ind-1))*dW/0.1;
+}
Index: /pmsm/pmsm_sim.cpp
===================================================================
--- /pmsm/pmsm_sim.cpp (revision 215)
+++ /pmsm/pmsm_sim.cpp (revision 218)
@@ -18,4 +18,5 @@
 #include "pmsm.h"
 #include "simulator.h"
+#include "sim_profiles.h"
 
 using namespace itpp;
@@ -35,19 +36,19 @@
 int main() {
 	// Kalman filter
-	int Ndat = 30000;
+	int Ndat = 9000;
 	double h = 1e-6;
 	int Nsimstep = 125;
-	int Npart = 1;
+	int Npart = 200;
 
 	// internal model
 	IMpmsm fxu;
-	//                  Rs    Ls        dt       Fmag(Ypm) kp   p    J     Bf(Mz)
-	fxu.set_parameters ( 0.28, 0.003465, Nsimstep*h, 0.1989,   1.5 ,4.0, 0.04, 0.0 );
+	//                  Rs    Ls        dt       Fmag(Ypm)    kp   p    J     Bf(Mz)
+	fxu.set_parameters ( 0.28, 0.003465, Nsimstep*h, 0.1989, 1.5 ,4.0, 0.04, 0.0 );
 	// observation model
 	OMpmsm hxu;
 
 	vec mu0= "0.0 0.0 0.0 0.0";
-	vec Qdiag ( "0.01 0.01 0.00001 0.00001" ); //zdenek: 0.01 0.01 0.0001 0.0001
-	vec Rdiag ( "0.0005 0.0005" ); //var(diff(xth)) = "0.034 0.034"
+	vec Qdiag ( "0.001 0.001 1e-6 1e-10" ); //zdenek: 0.01 0.01 0.0001 0.0001
+	vec Rdiag ( "1e-10 1e-10" ); //var(diff(xth)) = "0.034 0.034"
 	chmat Q ( Qdiag );
 	chmat R ( Rdiag );
@@ -59,14 +60,14 @@
 	EKF_unQ KFEp ( rx,ry,ru,rQ );
 	KFEp.set_parameters ( &fxu,&hxu,Q,R );
-	KFEp.set_est ( mu0, chmat ( 1*ones ( 4 ) ) );
+	KFEp.set_est ( mu0, chmat ( zeros ( 4 ) ) );
 
 	mgamma evolQ ( rQ,rQ );
 	MPF<EKF_unQ> M ( rx,rQ,evolQ,evolQ,Npart,KFEp );
 	// initialize
-	evolQ.set_parameters ( 100.0 ); //sigma = 1/10 mu
+	evolQ.set_parameters ( 10.0 ); //sigma = 1/10 mu
 	evolQ.condition ( "0.01 0.01" ); //Zdenek default
 	epdf& pfinit=evolQ._epdf();
 	M.set_est ( pfinit );
-	evolQ.set_parameters ( 1000.0 );
+	evolQ.set_parameters ( 10.0 );
 
 	//
@@ -78,5 +79,5 @@
 	mat Dt=zeros ( Ndat,4+2 ); //observation
 	mat XtE=zeros ( Ndat, 4 );
-	mat XtM=zeros ( Ndat,6 ); //Q + x
+	mat XtM=zeros ( Ndat,2+4 ); //Q + x
 
 	// SET SIMULATOR
@@ -87,4 +88,5 @@
 	vec dt ( 2 );
 	vec ut ( 2 );
+	vec vecW="0.1 0.2 0.4 0.9 0.4 0.2 0.0 -0.4 -0.9 -1.6 -0.4 0.0 0.0";
 
 	for ( int tK=1;tK<Ndat;tK++ ) {
@@ -92,17 +94,10 @@
 		for ( int ii=0; ii<Nsimstep;ii++ ) {
 			//simulator
-			Ww+=k_rampa*2.*M_PI*2e-4;    //1000Hz/s
-			if ( Ww>2.*M_PI*150. ) {
-				Ww=2.*M_PI*150.;
-				if ( k_rampa_tmp<500000 ) k_rampa_tmp++;
-				else {k_rampa=-1;k_rampa_tmp=0;}
-			};
-			if ( Ww<-2.*M_PI*150. ) Ww=-2.*M_PI*150.; /* */
-
+			sim_profile_vec01t(Ww,vecW);
 			pmsmsim_step ( Ww );
 		};
 		// collect data
-		ut ( 0 ) = KalmanObs[0];
-		ut ( 1 ) = KalmanObs[1];
+		ut ( 0 ) = 0.0;//KalmanObs[0];
+		ut ( 1 ) = 0.0;//KalmanObs[1];
 		dt ( 0 ) = KalmanObs[2];
 		dt ( 1 ) = KalmanObs[3];
Index: /pmsm/sim.cpp
===================================================================
--- /pmsm/sim.cpp (revision 217)
+++ /pmsm/sim.cpp (revision 218)
@@ -28,7 +28,6 @@
 	double h = 1e-6;
 	int Nsimstep = 125;
-	int Npart = 50;
 	
-	dirfilelog L("exp/pmsm_sim2",Ndat);
+	dirfilelog L("exp/sim",Ndat);
 	
 	// internal model
@@ -55,5 +54,7 @@
 	int U_log = L.add(ru,"U");
 	int U2_log = L.add(ru,"U2");
-	int R_log = L.add(RV("{_ }","4"),"R");
+	int R_log = L.add(RV("{_ }","16"),"R");
+	int Ww_log = L.add(RV("{_ }","1"),"W");
+	int R2_log = L.add(RV("{_ }","16"),"R2");
 //	int O_log = L.add(RV("{_ }","16"),"O");
 	L.init();
@@ -61,5 +62,5 @@
 	// SET SIMULATOR
 	//pmsmsim_set_parameters ( 0.28,0.003465,0.1989,0.0,4,1.5,0.04, 200., 3e-6, h );
-	pmsmsim_set_parameters ( 0.28,0.003465,0.1989,0.0,4,1.5,0.04, 200., 0.0*3e-6, h );
+	pmsmsim_set_parameters ( 0.28,0.003465,0.1989,0.0,4,1.5,0.04, 200., 6e-6, h );
 	double Ww=0.0;
 	vec dt ( 2 );
@@ -72,7 +73,10 @@
 	vec u=zeros(2);
 	vec u2=zeros(2);
-	ldmat R(eye(4),0.001*ones(4));
-	mat Ch=zeros(4,4);
-	fsqmat eCh(4);
+	ldmat R0(eye(4),1e-6*ones(4));
+	ldmat R(R0);
+	ldmat R2(R0);
+	
+	double frg=0.9;
+	vec vecW="0. 0. 0.2 0.4 0.4 0.2 0.0 -0.4 -0.6 -0.6 -0.4 0.0 0.0";
 	for ( int tK=1;tK<Ndat;tK++ ) {
 		//Number of steps of a simulator for one step of Kalman
@@ -80,5 +84,5 @@
 			//simulator
 			//sim_profile_steps1(Ww);
-			sim_profile_2slowrevs(Ww);
+			sim_profile_vec01t(Ww,vecW);
 			pmsmsim_step ( Ww );
 		};
@@ -92,6 +96,6 @@
 		// Try what our model would predict!
 		xp=fxu.eval(xm,u); 
-		xp2=fxu.eval(xm,u2); 
-		xp3=fxu.eval(xm,u2); 
+		xp2=fxu.eval(xm,zeros(2)); //ZERO input!!!!!!!!
+//		xp3=fxu.eval(xm,u2); 
 
 //		KFE.bayes(concat(dt,u));
@@ -99,9 +103,10 @@
 		xt=vec(x,4); //vec from C-array
 		//Covariance  
-		R*=0.7;
-		R.opupdt(xt-xp2,1.0);
-		Ch = diag(sqrt(R._D()))*R._L();
-		//eCh = KFE._e()->_R();
-		eCh = KFE._R();
+		R*=frg;
+		R.add(R0,1-frg);
+		R.opupdt(xt-xp,1.0);
+		R2*=frg;
+		R2.add(R0,1-frg);
+		R2.opupdt(xt-xp2,1.0);
 		xm = xt;
 		L.logit(X_log, xt	); 
@@ -110,6 +115,7 @@
 		L.logit(U_log, u	); 
 		L.logit(U2_log, u2	); 
-		L.logit(R_log, diag(Ch.T()*Ch) ); //3.33=1/(1-0.7)
-		L.logit(V_log, diag(eCh.to_mat()) ); //3.33=1/(1-0.7)
+		L.logit(Ww_log, vec_1(Ww)); 
+		L.logit(R_log, vec(R.to_mat()._data(), 16 )); //3.33=1/(1-0.7)
+		L.logit(R2_log, vec(R2.to_mat()._data(), 16 )); 
 //		L.logit(E_log, KFE._e()->mean()	); 
 //		L.logit(O_log, vec(iCh._data(),16)); //3.33=1/(1-0.7)
@@ -121,5 +127,5 @@
 
 	L.finalize(); 
-	L.itsave("xxx.it");
+	L.itsave("sim.it");
 	return 0;
 }
Index: /CMakeLists.txt
===================================================================
--- /CMakeLists.txt (revision 213)
+++ /CMakeLists.txt (revision 218)
@@ -27,6 +27,7 @@
 	#This is for UNIX makefile which does only one release at a time.
 	SET(CMAKE_BUILD_TYPE Debug)
-#	SET(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -DNDEBUG -O3 -pipe  -Wno-unknown-pragmas")
-	SET(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -pipe  -Wno-unknown-pragmas")
+	SET(CMAKE_CXX_FLAGS "-Wall -pipe  -Wno-unknown-pragmas")
+	SET(CMAKE_CXX_FLAGS_RELEASE " -DNDEBUG -O2")
+	SET(CMAKE_CXX_FLAGS_DEBUG "-g")
 	INCLUDE(CMakeLocal.txt OPTIONAL)	
 ENDIF(WIN32)
