please help with my code
Show older comments
Im trying to use kalman filters
A = [1.1269 -0.4940 0.1129;
1.0000 0 0;
0 1.0000 0];
B = [-0.3832;
0.5919;
0.5191];
C = [1 0 0];
Plant = ss(A,[B B],C,0,[] ,'inputname',{'u' 'w'},'outputname','y');
Q = 1;
R = 1;
[kalmf,L,P,M] = kalman(Plant,Q,R);
M
kalmf = kalmf(1,:);
a = A;
b = [B B 0*B];
c = [C;C];
d = [0 0 0;0 0 1];
P = ss(a,b,c,d,-1,'inputname',{'u' 'w' 'v'},'outputname',{'y' 'yv'});
sys = parallel(P,kalmf,1,1,[],[]);
SimModel = feedback(sys,1,4,2,1); % Close loop around input #4 and output #2
SimModel = SimModel([1 3],[1 2 3]); % Delete yv from I/O list
SimModel.InputName;
SimModel.OutputName;
src = dsp.SignalSource('SamplesPerFrame',5600);
src.Signal = xlsread('D:\ieee14\trainingset.xlsx',1,'A1:AB5601');
u = src.Signal;
src1 = dsp.SignalSource('SamplesPerFrame',5600);
src1.Signal = xlsread('D:\ieee14\faultset.xlsx',1,'A1:AB5601');
w = src1.Signal;
src2 = dsp.SignalSource('SamplesPerFrame',5600);
src2.Signal = xlsread('D:\ieee14\faultset.xlsx',1,'A5601:AB11201');
v = src2.Signal;
%T = horzcat[w,v,u,...];
%D = vertcat(u,v,w);
[out,x] = lsim(SimModel,[],[w,v,u]);
% sine1 = dsp.SineWave('spf',5600);
% sine1.Signal = xlsread('D:\ieee14\faultset.xlsx',1,'A1:N5601'), 10,xlsread('D:\ieee14\faultset.xlsx',1,'O1:AB5601');
% src = dsp.SignalSource(xlsread('D:\ieee14\faultset.xlsx',1,'A5601:AB11201'));
% %src.Signal = xlsread('D:\ieee14\faultset.xlsx',1,'A5601:AB11201');
%
i keep getting this error , how can i remove it?
Error using horzcat
Dimensions of matrices being concatenated are not consistent.
i have attached my input files as pictures as the files are too big to upload ; input image is a dataset with stable and unstable system voltage and phase (vtg is from A:N and phase from O:AB) and the input image is an excel sheet with 5600 fault values and 5601:16801 are the normal stable system values
input2 image is the values to be tested and using kalman to find how close they are to the dataset
Thanks in advance
I also wanted to keep u to be a input like
src = dsp.SignalSource('SamplesPerFrame',1);
src.Signal = xlsread('D:\ieee14\trainingset.xlsx',1,'A1:AB1');
u = src.Signal;
but as it shows this error
Error using DynamicSystem/lsim (line 84)
When simulating the response to a specific input signal, the input data U must be a matrix with as many rows as samples in the time
vector T, and as many columns as input channels.
Error in kalman15thapril (line 36)
[out,x] = lsim(SimModel,[w,v]);
18 Comments
Geoff Hayes
on 16 Apr 2017
Nana - which line is generating the error? Please copy and paste the full error message to this question.
Walter Roberson
on 16 Apr 2017
Notice that you are using row 5601 in both src1 and src2 . If the intention was that the two should not overlap then src2 would have to start at A5602
Nana Fernandes
on 16 Apr 2017
Walter Roberson
on 16 Apr 2017
Please show size(w), size(v), size(u)
Nana Fernandes
on 16 Apr 2017
Edited: Nana Fernandes
on 16 Apr 2017
Walter Roberson
on 16 Apr 2017
You assigned a new value to u after the code you posted earlier.
You have different number of rows for each of the items, but you are trying to put them together as columns.
You are passing the [w,v,u] into the time input of lsim, which needs a vector.
You appear to be using discrete lsim . For that, t can be omitted or set to a empty array, but the u input (which you set to empty) would need to be an array with as many columns as there are inputs to the system. But perhaps you did omit t: in that case the [w,v,u] would be appearing in the x0 position, but x0 needs to be a vector.
Nana Fernandes
on 16 Apr 2017
Walter Roberson
on 16 Apr 2017
Your SimModel appears to have three inputs and two outputs. The syntax for lsim is
lsim(sys,u,t)
"The input u is an array having as many rows as time samples (length(t)) and as many columns as system inputs. For instance, if sys is a SISO system, then u is a t-by-1 vector. If sys has three inputs, then u is a t-by-3 array. Each row u(i,:) specifies the input value(s) at the time sample t(i). The signal u also appears on the plot."
As you do have three inputs, your u needs to be something-by-3 .
As for t:
"The model sys can be continuous or discrete, SISO or MIMO. In discrete time, u must be sampled at the same rate as the system. In this case, the input t is redundant and can be omitted or set to an empty matrix."
As your model appears to be discrete, you could set t to [].
This would lead to code something like:
U3 = something with three columns derived from w, v and u;
[out,x] = lsim(SimModel, U3, []);
However, I have no idea which of your 28 columns of your three signals should be the inputs. Perhaps you should be using a system with 28 inputs.
Nana Fernandes
on 17 Apr 2017
Nana Fernandes
on 17 Apr 2017
Tell us exactly what these commands display:
size(u)
size(v)
size(w)
Nana Fernandes
on 17 Apr 2017
@Nana Fernandes: the variables have different numbers of rows, so that cannot be concatenated horizontally. They do have the same number of columns, so they could be concatenated vertically:
[w;v;u]
I have no idea if that suits your algorithm though: you should check the input requirements for lsim.
Nana Fernandes
on 17 Apr 2017
Walter Roberson
on 17 Apr 2017
In your line
P = ss(a,b,c,d,[],'inputname',{'u' 'w' 'v'},'outputname',{'y' 'yv'}); %changed -1 to [] here
your b and d would have to have 28 columns (and you would want to add more items to the inputnames)
Nana Fernandes
on 18 Apr 2017
Walter Roberson
on 18 Apr 2017
I am not sure if I understand your question, but it seems to me you could extract appropriate columns from your input. For example,
U3 = [w(:,4), v(:,4), u(:,21)];
[out,x] = lsim(SimModel, U3, []);
Nana Fernandes
on 18 Apr 2017
Edited: Nana Fernandes
on 18 Apr 2017
Answers (0)
Categories
Find more on Time and Frequency Domain Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!