Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
teslakom
tesla-driver
Commits
aeb4e39d
Commit
aeb4e39d
authored
Jun 22, 2017
by
Oystein Smith
Browse files
Worked on matlab scripts
parent
9624d80e
Changes
9
Hide whitespace changes
Inline
Side-by-side
03_Software/matlab/Simulink_transfer.slx
View file @
aeb4e39d
No preview for this file type
03_Software/matlab/inputOutput.asv
0 → 100644
View file @
aeb4e39d
C1 = 1e-7;
C2 = 1e-11;
L1 = 1e-5;
L2 = 1e-1;
k = 0.2;
M = k*sqrt(L1*L2); %2e-6;
R1 = 1e1;
R1 = 1;
R2 = 1e2;
%G1 = 2e-5;
G1 = 2e-6;
% Time domain parameters
fs = 4e6; % Sampling frequency
dt = 1/fs; % Time resolution
T = 1; % Signal duration
t = 0:dt:T-dt; % Total duration
N = length(t); % Number of time samples
f0=1/(2*pi*(sqrt(L1*C1)))
f0_s=1/(2*pi*(sqrt(L2*C2)))
%f0=1.57e+05
x2=square(2*pi*f0*t);
x2 = x2*160;
a = 0;%((C1*C2*G1*L1*L2)-2*(C1*C2*G1*L1*M)+(C1*C2*G1*M^2));
b = ((C1*C2*G1*L1*R2)+(C1*C2*G1*L2*R1)-2*(C1*C2*G1*M*R1)+(C1*C2*L1));
c = ((C1*C2*G1*R1*R2)+(C1*C2*R1)+(C1*G1*L1)+(C2*G1*L2)-2*(C2*G1*M));
d = ((C1*G1*R1)+(C2*G1*R2)+C2);
e = (G1);
f = (-1)*(C1*C2*M);
g = (-1)*(C1*G1*M);
H = tf([f g 0 0],[a b c d e]);
figure;
lsim(H,x2,t);
axis([0 1e-4 -20000 20000]);
xlabel('Time ');
ylabel('Amplitude [V]');
pbaspect([2 1 1]);
03_Software/matlab/inputOutput.m
View file @
aeb4e39d
...
...
@@ -2,11 +2,13 @@ C1 = 1e-7;
C2
=
1e-11
;
L1
=
1e-5
;
L2
=
1e-1
;
M
=
1e-6
;
R1
=
0
;
R2
=
0
;
%G1 = 1e-2;
G1
=
0
;
k
=
0.2
;
M
=
k
*
sqrt
(
L1
*
L2
);
%2e-6;
R1
=
1e1
;
R1
=
1
;
R2
=
1e2
;
%G1 = 2e-5;
G1
=
2e-6
;
% Time domain parameters
fs
=
4e6
;
% Sampling frequency
...
...
@@ -18,7 +20,9 @@ N = length(t); % Number of time samples
f0
=
1
/(
2
*
pi
*
(
sqrt
(
L1
*
C1
)))
f0_s
=
1
/(
2
*
pi
*
(
sqrt
(
L2
*
C2
)))
f0
=
1.57e+05
x2
=
square
(
2
*
pi
*
f0
*
t
);
x2
=
x2
*
160
;
a
=
((
C1
*
C2
*
G1
*
L1
*
L2
)
-
2
*
(
C1
*
C2
*
G1
*
L1
*
M
)
+
(
C1
*
C2
*
G1
*
M
^
2
));
b
=
((
C1
*
C2
*
G1
*
L1
*
R2
)
+
(
C1
*
C2
*
G1
*
L2
*
R1
)
-
2
*
(
C1
*
C2
*
G1
*
M
*
R1
)
+
(
C1
*
C2
*
L1
));
...
...
@@ -30,11 +34,10 @@ g = (-1)*(C1*G1*M);
H
=
tf
([
f
g
0
0
],[
a
b
c
d
e
]);
figure
;
lsim
(
H
,
x2
,
t
);
axis
([
0
1
e-4
-
10
1
0
]);
xlabel
(
'
Seconds
'
);
ylabel
(
'Amplitude'
);
axis
([
0
0.5
e-4
-
20000
2000
0
]);
xlabel
(
'
Time [s]
'
);
ylabel
(
'Amplitude
[V]
'
);
pbaspect
([
2
1
1
]);
03_Software/matlab/inputOutputFeedback.m
0 → 100644
View file @
aeb4e39d
C1
=
1e-7
;
C2
=
1e-11
;
L1
=
1e-5
;
L2
=
1e-1
;
k
=
0.2
;
M
=
k
*
sqrt
(
L1
*
L2
);
%2e-6;
R1
=
1e1
;
R1
=
1
;
R2
=
1e2
;
%G1 = 2e-5;
G1
=
2e-6
;
% Time domain parameters
fs
=
4e6
;
% Sampling frequency
dt
=
1
/
fs
;
% Time resolution
T
=
1
;
% Signal duration
t
=
0
:
dt
:
T
-
dt
;
% Total duration
N
=
length
(
t
);
% Number of time samples
f0
=
1
/(
2
*
pi
*
(
sqrt
(
L1
*
C1
)))
f0_s
=
1
/(
2
*
pi
*
(
sqrt
(
L2
*
C2
)))
f0
=
1.57e+05
x2
=
square
(
2
*
pi
*
f0
*
t
);
x2
=
x2
*
160
;
a
=
2
*
(
C1
*
C2
*
G1
*
M
)
-
(
C1
*
C2
*
G1
*
L2
);
%s^3
b
=
0
-
(
C1
*
C2
*
G1
*
R2
)
-
(
C1
*
C2
);
%s^2
c
=
0
-
(
C1
*
G1
);
%s^1
d
=
0
;
%s^0
% Under brkstreken
e
=
(
C1
*
C2
*
G1
*
L1
*
L2
)
-
2
*
(
C1
*
C2
*
G1
*
L1
*
M
);
%s^4
f
=
(
C1
*
C2
*
G1
*
L1
*
R2
)
+
(
C1
*
C2
*
L1
)
+
(
C1
*
C2
*
G1
*
R1
*
L1
)
-
2
*
(
C1
*
C2
*
G1
*
R1
*
M
);
%s^3
g
=
(
C1
*
G1
*
L1
)
+
(
C1
*
C2
*
R1
)
+
(
C2
*
G1
*
L2
)
-
2
*
(
C2
*
G1
*
M
);
%s^2
h
=
(
C1
*
G1
*
R1
)
+
(
C2
*
G1
*
R2
)
+
C2
;
%s^1
k
=
G1
;
%s^0
H
=
tf
([
a
b
c
d
],[
e
f
g
h
k
]);
figure
;
lsim
(
H
,
x2
,
t
);
axis
([
0
1e-4
-
200
200
]);
xlabel
(
'Time [s]'
);
ylabel
(
'Amplitude [A]'
);
pbaspect
([
2
1
1
]);
03_Software/matlab/limiterfilter.asv
0 → 100644
View file @
aeb4e39d
R2 = 10;
C3 = 1e9;
n1 = 1;
n2 = 100;
H = tf([],[])
loglog(f,H);
\ No newline at end of file
03_Software/matlab/limiterfilter.m
0 → 100644
View file @
aeb4e39d
R2 = 10;
C3 = 1e9;
n1 = 1;
n2 = 100;
H = tf([R2],[R2*C3 1])
bodeplot(H);
[mag,phase,wout] = bode(H);
03_Software/matlab/transfer.asv
0 → 100644
View file @
aeb4e39d
C1 = 1e-7;
C2 = 1e-11;
L1 = 1e-5;
L2 = 1e-1;
k = 0.2;
M = k*sqrt(L1*L2); %2e-6;
R1 = 1;
R2 = 1e2;
%G1 = 2e-5;
G1 = 2e-6;
fprintf('Expected resonance frequency:\n');
fprintf('%i Hz\n', 1./(2*pi()*sqrt(C1*L1)));
H1 = transfertingsak(C1, C2*0.1, L1, L2, M, R1, R2, G1);
H2 = transfertingsak(C1, C2*0.5, L1, L2, M, R1, R2, G1);
H3 = transfertingsak(C1, C2, L1, L2, M, R1, R2, G1);
H4 = transfertingsak(C1, C2*1.5, L1, L2, M, R1, R2, G1);
H5 = transfertingsak(C1, C2*1.9, L1, L2, M, R1, R2, G1);
figure;
bde1 = bodeplot(H1,H2,H3,H4,H5);
setoptions(bde1, 'FreqUnits','Hz','Grid','on','Xlim',[1e4, 2e6]);
legend('0.01','0.1','0.2','0.5','1.0','show','Location','northeast');
[mag, phase, W] = bode(H1);
[val, idx] = max(mag);
fprintf('Max amplitude:\n');
fprintf('%i dB\n', val);
fprintf('%i Hz\n', W(idx));
% figure;
% subplot(2,1,1)
% step(H1, 2e-5); hold on;
% [Y, T] = step(H1, 2e-5);
% %findpeaks(Y)
% [pks1, locs1] = findpeaks(Y);
% [pks2, locs2] = findpeaks(-Y);
% stepfrequency = 1./(2*(T(locs2(1))-T(locs1(1))))
%
%
% subplot(2,1,2)
% impulse(H1, 2e-5);
%
% figure;
% pzplot(H1);
% grid on;
% [P, Z] = pzmap(H1)
function H = transfertingsak(C1, C2, L1, L2, M, R1, R2, G1)
a = 0;%((C1*C2*G1*L1*L2)-2*(C1*C2*G1*L1*M)+(C1*C2*G1*M^2));
b = ((C1*C2*G1*L1*R2)+(C1*C2*G1*L2*R1)-2*(C1*C2*G1*M*R1)+(C1*C2*L1));
c = ((C1*C2*G1*R1*R2)+(C1*C2*R1)+(C1*G1*L1)+(C2*G1*L2)-2*(C2*G1*M));
d = ((C1*G1*R1)+(C2*G1*R2)+C2);
e = (G1);
f = (-1)*(C1*C2*M);
g = (-1)*(C1*G1*M);
H = tf([f g 0 0],[a b c d e]);
end
03_Software/matlab/transfer.m
View file @
aeb4e39d
...
...
@@ -2,85 +2,49 @@ C1 = 1e-7;
C2
=
1e-11
;
L1
=
1e-5
;
L2
=
1e-1
;
M
=
1e-6
;
R1
=
1e1
;
k
=
0.2
;
M
=
k
*
sqrt
(
L1
*
L2
);
%2e-6;
R1
=
1
;
R2
=
1e2
;
%G1 = 1e2;
G1
=
0
;
G1
=
2e-6
;
%k =
fprintf
(
'Expected resonance frequency:\n'
);
fprintf
(
'%i Hz\n'
,
1.
/(
2
*
pi
()
*
sqrt
(
C1
*
L1
)));
H1
=
transfertingsak
(
C1
,
C2
,
L1
,
L2
,
M
,
R1
,
R2
,
0
);
H2
=
transfertingsak
(
C1
,
C2
,
L1
,
L2
,
M
,
R1
,
R2
,
1e-12
);
H3
=
transfertingsak
(
C1
,
C2
,
L1
,
L2
,
M
,
R1
,
R2
,
1e-9
);
H4
=
transfertingsak
(
C1
,
C2
,
L1
,
L2
,
M
,
R1
,
R2
,
1e-6
);
H5
=
transfertingsak
(
C1
,
C2
,
L1
,
L2
,
M
,
R1
,
R2
,
1e-3
);
H1
=
transfertingsak
(
C1
,
C2
,
L1
,
L2
,
M
,
R1
,
R2
,
G1
);
% H2 = transfertingsak(C1, C2*0.5, L1, L2, M, R1, R2, G1);
% H3 = transfertingsak(C1, C2, L1, L2, M, R1, R2, G1);
% H4 = transfertingsak(C1, C2*1.5, L1, L2, M, R1, R2, G1);
% H5 = transfertingsak(C1, C2*1.9, L1, L2, M, R1, R2, G1);
figure
;
bde1
=
bodeplot
(
H1
,
H2
,
H3
,
H4
,
H5
);
setoptions
(
bde1
,
'FreqUnits'
,
'Hz'
,
'Grid'
,
'on'
);
bde1
=
bodeplot
(
H1
);
setoptions
(
bde1
,
'FreqUnits'
,
'Hz'
,
'Grid'
,
'on'
,
'Xlim'
,[
1e4
,
2e6
]);
%legend('0.01','0.1','0.2','0.5','1.0','show','Location','northeast');
[
mag
,
phase
,
W
]
=
bode
(
H1
);
[
val
,
idx
]
=
max
(
mag
);
fprintf
(
'Max amplitude:\n'
);
fprintf
(
'%i dB\n'
,
val
);
fprintf
(
'%i Hz\n'
,
W
(
idx
));
figure
;
subplot
(
2
,
1
,
1
)
% step(H1, 1e-4); hold on;
% step(H2, 1e-4); hold on;
% step(H3, 1e-4); hold on;
step
(
H4
,
2e-5
);
hold
on
;
% step(H5, 1e-4);
step
(
H1
,
2e-5
);
hold
on
;
[
Y
,
T
]
=
step
(
H1
,
2e-5
);
%findpeaks(Y)
[
pks1
,
locs1
]
=
findpeaks
(
-
Y
);
[
pks2
,
locs2
]
=
findpeaks
(
Y
);
stepfrequency
=
1.
/(
2
*
(
T
(
locs2
(
1
))
-
T
(
locs1
(
1
))))
% [y1, t1] = step(H1,1e-4);
% y1 = pruneNaNWonderbar(y1);
% y1(numel(t1)) = 0;
% [y1, ~] = envelope(y1);
%
% [y2, t2] = step(H2,1e-4);
% y2 = pruneNaNWonderbar(y2);
% y2(numel(t2)) = 0;
% [y2, ~] = envelope(y2);
%
% [y3, t3] = step(H3,1e-4);
% y3 = pruneNaNWonderbar(y3);
% y3(numel(t3)) = 0;
% [y3, ~] = envelope(y3);
%
% [y4, t4] = step(H4,1e-4);
% y4 = pruneNaNWonderbar(y4);
% y4(numel(t4)) = 0;
% [y4, ~] = envelope(y4);
%
% [y5, t5] = step(H5,1e-4);
% y6 = y5;
% t6 = t5;
% y5 = pruneNaNWonderbar(y5);
% y5(numel(t5)) = 0;
% [y5, ~] = envelope(y5);
%loglog(t1, y1); hold on;
%loglog(t2, y2); hold on;
%plot(t3, y3); hold on;
%plot(t4, y4); hold on;
%plot(t5, y5); hold on;
%plot(t6, y6); hold on;
subplot
(
2
,
1
,
2
)
impulse
(
H
4
,
2e-5
);
impulse
(
H
1
,
2e-5
);
figure
;
pz
map
(
H
4
);
pz
plot
(
H
1
);
grid
on
;
function
H
=
transfertingsak_old
(
C1
,
C2
,
L1
,
L2
,
M
,
R1
,
R2
,
G1
)
a
=
(
2
*
M
*
L1
*
C2
*
C1
)
-
(
L1
*
L2
*
C2
*
C1
);
b
=
(
2
*
M
*
R1
*
C2
*
C1
)
-
(
L2
*
R1
*
C2
*
C1
)
+
(
2
*
M
*
L1
*
G1
*
C1
)
-
(
L1
*
R2
*
C2
*
C1
);
c
=
(
2
*
M
*
R1
*
G1
*
C1
)
-
(
R1
*
R2
*
C2
*
C1
)
+
(
2
*
M
*
C2
)
-
(
C2
*
L2
)
-
(
L1
*
R2
*
G1
*
C1
)
-
(
L1
*
C1
)
+
(
2
*
M
*
C1
);
d
=
(
2
*
M
*
G1
)
-
(
R1
*
R2
*
G1
*
C1
)
-
(
R1
*
C1
)
-
(
L2
*
G1
);
e
=
-
((
R2
*
G1
)
+
1
);
f
=
(
M
*
C1
);
H
=
tf
([
f
0
0
],[
a
b
c
d
e
]);
H
end
[
P
,
Z
]
=
pzmap
(
H1
)
function
H
=
transfertingsak
(
C1
,
C2
,
L1
,
L2
,
M
,
R1
,
R2
,
G1
)
a
=
((
C1
*
C2
*
G1
*
L1
*
L2
)
-
2
*
(
C1
*
C2
*
G1
*
L1
*
M
)
+
(
C1
*
C2
*
G1
*
M
^
2
));
...
...
@@ -92,18 +56,4 @@ function H = transfertingsak(C1, C2, L1, L2, M, R1, R2, G1)
g
=
(
-
1
)
*
(
C1
*
G1
*
M
);
H
=
tf
([
f
g
0
0
],[
a
b
c
d
e
]);
H
end
function
yo
=
pruneNaNWonderbar
(
y
)
firstnanindex
=
find
(
isnan
(
y
),
1
);
if
~
isempty
(
firstnanindex
)
y
=
y
(
1
:(
firstnanindex
-
1
));
end
firstinfindex
=
find
(
isinf
(
y
),
1
);
if
~
isempty
(
firstinfindex
)
y
=
y
(
1
:(
firstinfindex
-
1
));
end
yo
=
y
;
end
\ No newline at end of file
03_Software/matlab/transferpPrimaryCurrent.m
View file @
aeb4e39d
...
...
@@ -2,86 +2,50 @@ C1 = 1e-7;
C2
=
1e-11
;
L1
=
1e-5
;
L2
=
1e-1
;
M
=
1e-6
;
R1
=
1e-1
;
k
=
0.2
;
M
=
k
*
sqrt
(
L1
*
L2
);
%2e-6;
R1
=
1
;
R2
=
1e2
;
%G1 = 1e2;
G1
=
0
;
G1
=
2e-6
;
%k =
fprintf
(
'Expected resonance frequency:\n'
);
fprintf
(
'%i Hz\n'
,
1.
/(
2
*
pi
()
*
sqrt
(
C1
*
L1
)));
H1
=
transferCurrent
(
C1
,
C2
,
L1
,
L2
,
M
,
R1
,
R2
,
1e-7
);
H2
=
transferCurrent
(
C1
,
C2
,
L1
,
L2
,
M
,
R1
,
R2
,
1e-7
);
H3
=
transferCurrent
(
C1
,
C2
,
L1
,
L2
,
M
,
R1
,
R2
,
1e-7
);
H4
=
transferCurrent
(
C1
,
C2
,
L1
,
L2
,
M
,
R1
,
R2
,
1e7
);
H5
=
transferCurrent
(
C1
,
C2
,
L1
,
L2
,
M
,
R1
,
R2
,
1e7
);
H1
=
transferCurrent
(
C1
,
C2
,
L1
,
L2
,
M
,
R1
,
R2
,
G1
);
%H2 = transferCurrent(C1, C2, L1, L2, M, R1, R2, 1e-7);
%H3 = transferCurrent(C1, C2, L1, L2, M, R1, R2, 1e-7);
%H4 = transferCurrent(C1, C2, L1, L2, M, R1, R2, 1e-7);
%H5 = transferCurrent(C1, C2, L1, L2, M, R1, R2, 1e7);
figure
;
bde1
=
bodeplot
(
H1
,
H2
,
H3
,
H4
,
H5
);
bde1
=
bodeplot
(
H1
);
setoptions
(
bde1
,
'FreqUnits'
,
'Hz'
,
'Grid'
,
'on'
);
%legend('show','Location','northeastoutside');
[
mag
,
phase
,
W
]
=
bode
(
H1
);
[
val
,
idx
]
=
max
(
mag
);
fprintf
(
'Max amplitude:\n'
);
fprintf
(
'%i dB\n'
,
val
);
fprintf
(
'%i Hz\n'
,
W
(
idx
));
figure
;
subplot
(
2
,
1
,
1
)
% step(H1, 1e-4); hold on;
% step(H2, 1e-4); hold on;
% step(H3, 1e-4); hold on;
step
(
H4
,
2e-5
);
hold
on
;
% step(H5, 1e-4);
step
(
H1
,
2e-5
);
hold
on
;
[
Y
,
T
]
=
step
(
H1
,
2e-5
);
%findpeaks(Y)
[
pks1
,
locs1
]
=
findpeaks
(
Y
);
[
pks2
,
locs2
]
=
findpeaks
(
-
Y
);
stepfrequency
=
1.
/(
2
*
(
T
(
locs1
(
1
))
-
T
(
locs2
(
1
))))
% [y1, t1] = step(H1,1e-4);
% y1 = pruneNaNWonderbar(y1);
% y1(numel(t1)) = 0;
% [y1, ~] = envelope(y1);
%
% [y2, t2] = step(H2,1e-4);
% y2 = pruneNaNWonderbar(y2);
% y2(numel(t2)) = 0;
% [y2, ~] = envelope(y2);
%
% [y3, t3] = step(H3,1e-4);
% y3 = pruneNaNWonderbar(y3);
% y3(numel(t3)) = 0;
% [y3, ~] = envelope(y3);
%
% [y4, t4] = step(H4,1e-4);
% y4 = pruneNaNWonderbar(y4);
% y4(numel(t4)) = 0;
% [y4, ~] = envelope(y4);
%
% [y5, t5] = step(H5,1e-4);
% y6 = y5;
% t6 = t5;
% y5 = pruneNaNWonderbar(y5);
% y5(numel(t5)) = 0;
% [y5, ~] = envelope(y5);
%loglog(t1, y1); hold on;
%loglog(t2, y2); hold on;
%plot(t3, y3); hold on;
%plot(t4, y4); hold on;
%plot(t5, y5); hold on;
%plot(t6, y6); hold on;
subplot
(
2
,
1
,
2
)
impulse
(
H
4
,
2e-5
);
impulse
(
H
1
,
2e-5
);
figure
;
pzmap
(
H
4
);
pzmap
(
H
1
);
grid
on
;
function
H
=
transfertingsak
(
C1
,
C2
,
L1
,
L2
,
M
,
R1
,
R2
,
G1
)
a
=
((
C1
*
C2
*
G1
*
L1
*
L2
)
-
2
*
(
C1
*
C2
*
G1
*
L1
*
M
)
+
(
C1
*
C2
*
G1
*
M
^
2
));
b
=
((
C1
*
C2
*
G1
*
L1
*
R2
)
+
(
C1
*
C2
*
G1
*
L2
*
R1
)
-
2
*
(
C1
*
C2
*
G1
*
M
*
R1
)
+
(
C1
*
C2
*
L1
));
c
=
((
C1
*
C2
*
G1
*
R1
*
R2
)
+
(
C1
*
C2
*
R1
)
+
(
C1
*
G1
*
L1
)
+
(
C2
*
G1
*
L2
)
-
2
*
(
C2
*
G1
*
M
));
d
=
((
C1
*
G1
*
R1
)
+
(
C2
*
G1
*
R2
)
+
C2
);
e
=
(
G1
);
f
=
(
-
1
)
*
(
C1
*
C2
*
M
);
g
=
(
-
1
)
*
(
C1
*
G1
*
M
);
H
=
tf
([
f
g
0
0
],[
a
b
c
d
e
]);
H
end
[
P
,
Z
]
=
pzmap
(
H1
)
function
H
=
transferCurrent
(
C1
,
C2
,
L1
,
L2
,
M
,
R1
,
R2
,
G1
)
% Over brkstreken
...
...
@@ -97,18 +61,4 @@ function H = transferCurrent(C1, C2, L1, L2, M, R1, R2, G1)
k
=
G1
;
%s^0
H
=
tf
([
a
b
c
d
],[
e
f
g
h
k
]);
H
end
function
yo
=
pruneNaNWonderbar
(
y
)
firstnanindex
=
find
(
isnan
(
y
),
1
);
if
~
isempty
(
firstnanindex
)
y
=
y
(
1
:(
firstnanindex
-
1
));
end
firstinfindex
=
find
(
isinf
(
y
),
1
);
if
~
isempty
(
firstinfindex
)
y
=
y
(
1
:(
firstinfindex
-
1
));
end
yo
=
y
;
end
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment