Skip to content

Commit

Permalink
Mataveid 6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielMartensson committed Apr 25, 2020
1 parent 160cd35 commit 0120c31
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 19 deletions.
46 changes: 28 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,45 @@ K = 0.01;
R = 1;
L = 0.5;
A = [0 1 0
0 -b/J K/J
0 -K/L -R/L];
B = [0 ; 0 ; 1/L];
C = [1 0 0];
D = [0];
delay = 0;
%% Model
motor_ss = ss(delay,A,B,C,D);
% Matrix A
A = [0 1 0 0;
-K*R*L -(J+K+R*2) 0 1;
0 0 0 1;
0 1 -(b+J) -5*(J+R*2)];
% Matrix B
B = [0 0;
1 0;
0 0;
0 1];
% Matrix C
C = [0 1 0 0;
0 0 1 0];
%% Model
motor_ss = ss(0, A, B, C);
%% Input and time
t = linspace(0, 20, 1000);
u = [linspace(5, -11, 100) linspace(7, 3, 100) linspace(-6, 9, 100) linspace(-7, 1, 100) linspace(2, 0, 100) linspace(6, -9, 100) linspace(4, 1, 100) linspace(0, 0, 100) linspace(10, 17, 100) linspace(-30, 0, 100)];
u = [linspace(1, 11, 100) linspace(7, 3, 100) linspace(6, 9, 100) linspace(-7, -1, 100) linspace(2, -10, 100) linspace(6, -9, 100) linspace(4, 1, 100) linspace(0, 0, 100) linspace(10, 17, 100) linspace(-30, 0, 100)];
u = [u;2*u]; % MIMO
%% Simulation
y = lsim(motor_ss, u, t);
%% Add 5% noise
%% Add 15% noise
load v
for i = 1:length(y)
noiseSigma = 0.05*y(i);
for i = 1:length(y)-1
noiseSigma = 0.05*y(:, i);
noise = noiseSigma*v(i); % v = noise, 1000 samples -1 to 1
y(i) = y(i) + noise;
y(:, i) = y(:, i) + noise;
end
%% Identification
regularization = 838;
modelorder = 3;
modelorder = 10;
[sysd, K] = okid(u, y, t(2) - t(1), 0, regularization, modelorder);
close
Expand All @@ -65,7 +75,7 @@ close
%% Check
plot(t, y, t, yt(:, 1:2:end))
legend("Data", "Identified", 'location', 'northwest')
legend("Data 1", "Data 2", "Identified 1", "Identified 2", 'location', 'northwest')
grid on
```
![a](https://raw.githubusercontent.com/DanielMartensson/Mataveid/master/pictures/OKID_Result.png)
Expand Down Expand Up @@ -330,7 +340,7 @@ close
%% Check
plot(t, yt(1:2, 1:2:end), t, yf(1:2, :))
legend("Data", "Identified", 'location', 'northwest')
legend("Identified 1", "Identified 2", "Data 1", "Data 2", 'location', 'northwest')
grid on
```

Expand Down
Binary file modified pictures/OKID_Result.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions sourcecode/listOfFunctions
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
eradc.m
filtfilt2.m
idbode.m
ocid.m
okid.m
rls.m
spa.m
ssfd.m
updatemataveid.m
2 changes: 1 addition & 1 deletion sourcecode/spa.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

plot(freq, Y)
ylabel('Amplitude')
xlabel('Frequency [rad/s]')
xlabel('Frequency [Hz]')

% Return values
amp = 20*log10(Y);
Expand Down

0 comments on commit 0120c31

Please sign in to comment.