01-30-2015 06:39 PM
I am trying to follow a example from MATLAB using Mathscript Kalman Filter Design
When I run the code, it shows "Error in function lsim at line 39 column 7: The inputs to this function must be scalar." but I have no idea how to fix it. Any help will be appreciated.
A=[1.1269, -0.4940, 0.1129; 1, 0, 0 ; 0, 1, 0] B = [-0.3832; 0.5919; 0.5191]; C = [1, 0 , 0]; D = 0; plant = ss(A,B,C,D,1) Q = 2.3; R = 1; %Time update: %x[n+1|n] = Ax[n|n-1] + Bu[n] % Measurement update: %x[n|n] = x[n|n-1] + M (yv[n] - Cx[n|n-1]) [SysKal, L, P, M, Z] = kalman(plant, Q, R); a = A; b = [B B 0*B]; c = [C;C]; d = [0 0 0;0 0 1]; P = ss(a,b,c,d,-1) sys = parallel(P,SysKal,1,1,[],[]); SimModel = feedback(sys,1,4,2,1); SimModel = SimModel([1 3],[1 2 3]); % Delete yv form I/O t = (0:100)'; u = sin(t/5); w = sqrt(Q)*randn(length(t),1); v = sqrt(R)*randn(length(t),1); out = lsim(SimModel,u,t); y = out(:,1); % true response ye = out(:,2); % filtered response yv = y + v; % measured response y = out(:,1); % true response ye = out(:,2); % filtered response yv = y + v; % measured response clf plot(t,y,'b',t,ye,'r--') xlabel('No. of samples'), ylabel('Output') title('Kalman filter response') plot(t,y-yv,'g',t,y-ye,'r--') xlabel('No. of samples'), ylabel('Error')
12-24-2016 02:53 PM - edited 12-24-2016 02:55 PM
When I copy/paste into MathScript, it gives me an error at line 9.
I am used to this because I don't have toolboxes so MathWorks toolbox content doesn't exist there. It is the base platform.
Question for you: what version of LabVIEW and MathScript are you using? Do you have MatLab with control system toolbox (or similar) installed?
06-05-2018 04:25 AM
No. If you put the Matlab code inside Mathscript Node, it wouldn't work. Unless you put your Matlab code into Matlab script, then it will work. Are you already install the Matlab on your computer? Otherwise, it wouldn't work because it needs the Matlab runtime engine to run it.
06-05-2018 11:33 PM
If you refer to the example on this help page:
http://zone.ni.com/reference/en-XX/help/371894J-01/lvcdtextmath/cdmc_lsim/
It suggests to me that your t and u need to be transposed compared to what you have. so try
t = (0:100); u = sin(t/5)';