Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • Adam.Schrey/lecture-tutorials
1 result
Select Git revision
Show changes
Commits on Source (62)
Showing
with 14 additions and 14467 deletions
%% Cell type:markdown id: tags:
# Systemtheorie 2 und JupyterHub
## Wie greife ich auf JupyterHub zu?
Loggen Sie sich unter <a href="https://jupyter.rwth-aachen.de/hub/spawn?profile=sys2"> https://jupyter.rwth-aachen.de/hub/spawn?profile=sys2 </a> mit Ihrem RWTH-Account ein.
## Wie nutze ich JupyterHub?
Auf der Weboberfläche sollten auf der linken Seite verschiedene Ordner angezeigt werden. Unter dem Pfad "lecture-tutorials/notebooks" sind Dateien (Notebooks) zum Thema "Systemtheorie 2".
Auf der Weboberfläche sollten auf der linken Seite verschiedene Ordner angezeigt werden. Unter dem Pfad "sys2/sys2-jupyter-notebooks/lecture_examples" sowie "sys2/sys2-jupyter-notebooks/exam_examples" sind Dateien (Notebooks) zum Thema "Systemtheorie 2".
In diesen Notebooks können Beispiele in Form von Code-Blöcken ausgeführt werden. Meist geben diese einen statischen Graphen aus. Jedoch gibt es auch oft interaktive Elemente, bei denen Werte über einen Schieberegler oder Knopf verändert werden können.
In diesen Notebooks können Beispiele in Form von Code-Blöcken ausgeführt werden. Meist geben diese einen statischen Graphen aus. Jedoch gibt es auch interaktive Elemente, bei denen Werte über einen Schieberegler oder Knopf verändert werden können.
Die Code-Blöcke können im Notebook geändert werden und diese Änderung kann unter dem Unterpunkt "Git" auch wieder rückgängig gemacht werden.
"V01_zeitdiskrete_systeme.ipynb" bis "V10_kalmanfilter_demonstration.ipynb" sind Notebooks zu den Themen der Vorlesung. In "Sandkasten.ipynb" kann man beliebige Funktionen untersuchen, eigene Simulationen erstellen und Verschiedenes ausprobieren.
"In der Template-Datei "sys2/sys2-jupyter-notebooks/template.ipynb" kann man zudem beliebige Funktionen untersuchen, eigene Simulationen (mittels Python 3 Syntax) erstellen und Verschiedenes ausprobieren.
### Ausführen der Code-Blöcke in den Folien:
<img src="introduction_pictures/run.png"/>
### Beispiel eines interaktiven Elementes:
<img src="introduction_pictures/interact.png"/>
### Änderungen rückgängig machen:
<img src="introduction_pictures/git.png"/>
<img src="introduction_pictures/discard_changes.png"/>
## Python und Matlab
Ältere Notebooks, welche Matlab-Code verwenden, können unter dem Pfad "lecture-tutorials/notebooks/alt" gefunden werden.Aber auch andere Notebooks können Matlab-Code beinhalten.Wenn man zwischen verschiedenen Notebooks mit Python-Code und Matlab-Code wechselt, muss man den Kernel womöglichmanuell ändern (Octave Kernel für Matlab):
## Python vs. Matlab
Einige der Jupyter-Notebooks können Matlab-Code beinhalten. Wenn man zwischen verschiedenen Notebooks mit Python-Code und Matlab-Code wechselt, muss man den Kernel gegebenenfalls manuell umstellen (Octave Kernel für Matlab; Python 3 (ipykernel) für Python).
### Ändern des Kernels:
<img src="introduction_pictures/switch_kernel.png"/>
## Fehlerbehebung
Sollte es zu Fehlern kommen oder das System in eine Endlosschleife geraten, so kann man unter dem Menü-Punkt "Kernel" >> "Restart Kernel" die aktuellen Berechnungen und gespeicherten Variablen zurücksetzen.
Sollten die Notebooks oder zugehöriger Python-Code fehlerhaft sein, können Sie dies gerne melden.
Auch können Sie das Systemtheorie 2 Jupyter auf "Werkseinstellungen" zurücksetzen (Achtung: alle selbst getätigten Änderungen gehen dabei verloren!) indem Sie unter dem Menü-Punkt "Git" >> "Open Git Repository in Terminal" den Befehl <code>git fetch origin && git reset --hard origin/master</code> eingeben.
Sollten die Notebooks oder zugehöriger Code trotzdem nicht richtig funktionieren, so können Sie dies jederzeit gerne an "acs-teaching-sys2@eonerc.rwth-aachen.de" melden.
......
%% Cell type:markdown id: tags:
# <span style='color:OrangeRed'>V1-Zeitdiskrete Systeme </span>
%% Cell type:markdown id: tags:
## <span style='color:Gray'>Beispiel #1 </span>
%% Cell type:markdown id: tags:
<div style="font-family: 'times'; font-size: 13pt; text-align: justify">
<b>Wie kann sich die Abtastfrequenz auf eine Zahlenfolge auswirken?</b>
- Wir nehmen folgende Abtastfrequenz: $f_{a}=10.000 Hz$
- Hier gilt: $T=\frac{1}{f_{a}}$ , $K_{max}=20.000$ , $k=[1...K_{max}]$ , $t=Tk$.
- Wähle einen Ton mit 440 Hz. Es gilt:$\omega=2\pi440$
- Die Zahlenfolge wird definiert mit:$y=sin(\omega.t)$
<b> Codes: </b>
<br><br>
Folgender Matlab Befehl erzeugt die Wiedergabe des Tons <code>y</code> mit der Frequenz <code>fa</code>:
%% Cell type:code id: tags:
``` octave
% Abstast Frequenz
fa = 10000;
T = 1/fa;
maxk = 20000;
k=1:maxk;
t=k.*T;
% A Tone 440 Hz
om = 2*pi*440;
y = sin(om*t);
```
%% Cell type:code id: tags:
``` octave
soundsc(y,fa)
```
%% Cell type:markdown id: tags:
<div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Ändern Sie nun die Abtastfrequenz wie folgt:
%% Cell type:code id: tags:
``` octave
soundsc(y,fa/2)
```
%% Cell type:markdown id: tags:
<div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Der Ton wurde <span style='color:red'> fehlerhaft </span> übersetzt und weicht von dem Originalton ab!
%% Cell type:markdown id: tags:
## <span style='color:Gray'>Beispiel #2 </span>
%% Cell type:markdown id: tags:
<div style="font-family: 'times'; font-size: 13pt; text-align: justify">
<b> Abtastung und Quantisierung</b>
- Die Frequenzen für das Signal 1 und 2 werden gewählt: $\omega_{1}=1$, $\omega_{2}=1+2\pi$
- Die Abtastkreisfrequenz und Abtastzeit entsprechen:$\omega_{T}=2\pi$, $T=\frac{2\pi}{\omega_T}$
- Des Weiteren wird für die Folge bestimmt:$K_{max}=200$, $k=[1...K_{max}]$ , $t=Tk$.
Im Folgenden erzeugen wir zwei abgetastete Signale <code>y1</code> und <code>y2</code>:
%% Cell type:code id: tags:
``` octave
% Frequenz Signal 1
om1 = 1;
% Frequenz Signal 2
om2 = 1+2*pi;
% Abtast Frequenz
om_T = 2*pi;
% Abtast Zeit
T = 2*pi/om_T;
maxk = 200;
k=1:maxk;
t=k.*T;
```
%% Cell type:markdown id: tags:
<div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Das Ergebnis kann mit folgendem Matlab Befehl geplottet werden:
%% Cell type:code id: tags:
``` octave
%Signal 1
y1 = sin(om1*k*T);
%Signal 2
y2 = sin(om2*k*T);
plot(t,y1,t,y2)
```
%% Cell type:markdown id: tags:
<div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Durch Abtastung erhält man nur eine unvollständige Information über das betrachtete
Signal. Es gibt sehr viele Funktionen die durch die Abtastwerte verlaufen können.
<br>
<span style='color:Gray'>Beispiel </span> : Es werden zwei sinusförmige Signale betrachtet:
<br>
$y_1(t)=sin(\omega_1t)$ , $y_2(t)=sin(\omega_2t)$
die auf die Abtastfolgen führen:
<br> $y_1(k)=sin(k\omega_1t)$ , $y_2(k)=sin(k\omega_2t)$
Die Abtastwerte für beide Funktionen sind an allen Abtastpunkten gleich wenn
$sin(k\omega_1T)=sin(k\omega_2T)$
$(k=0, 1,...)$ gilt, was in
$\omega_1=\omega_2+l\frac{2\pi}{kT}$
umgeformt werden kann.
%% Cell type:markdown id: tags:
<div style="font-family: 'times'; font-size: 13pt; text-align: justify">
- $\omega_1=\omega_2+l\frac{2\pi}{kT}$
($l$ ganzzahlig)
<br><br>
- $\omega_1=\omega_2+\omega{T}$
($ \omega_T$ Abtastkreisfrequenz)
%% Cell type:markdown id: tags:
<div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Erfüllen zwei Frequenzen die obere Beziehung, so können die von der Sinusschwingung
mit der Kreisfrequenz $\omega_1$ erzeugten Abtastwerte auch durch eine Sinusschwingung mit der
Kreisfrequenz $\omega_2$ erzeugt werden.
<span style='color:OrangeRed'>Das heißt Signale mit diesen beiden Frequenzen können hinter dem Abtaster nicht mehr
unterschieden werden! </span>
%% Cell type:markdown id: tags:
# <span style='color:OrangeRed'>V2 - Die z-Transformation</span>
%% Cell type:markdown id: tags:
## <span style='color:Gray'>Beispiel #1 </span>
%% Cell type:markdown id: tags:
<div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Gegeben ist die Funktion im Zähler mit: $8z^{-1}$
Des Weiteren ist die Nennerfunktion gegeben mit:$1-3z^{-1}+2z^{-2}$
%% Cell type:code id: tags:
``` octave
N = [8 0]
D = [1 -3 2]
```
%% Cell type:markdown id: tags:
<div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Da <code>N</code> und <code>D</code> Vektorpolynome sind , entspricht eine Entfaltung(.eng.: deconvolution) einer einfachen
Division. Die Matlab Funktion hierfür lautet:
%% Cell type:code id: tags:
``` octave
[fo R] = deconv(N,D)
```
%% Cell type:markdown id: tags:
<div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Bei erstmaliger Anwendung der Funktion erhalten wir den ersten Koeffizienten der Folge <code>fo</code> und den
Rest ( eng.: remainder) <code>R</code>.
Der Rest <code>R</code> wird mit $z^{-1}$ multipliziert und weiter dividiert
%% Cell type:code id: tags:
``` octave
R = conv(R,[1 0])
[f2 R] = deconv(R,D)
```
%% Cell type:code id: tags:
``` octave
R = conv(R,[1 0])
[f3 R] = deconv(R,D)
```
%% Cell type:markdown id: tags:
### Die Potenzreihenentwicklung
<div style="font-family: 'times'; font-size: 13pt; text-align: justify">
<br><br>
<b> Mathematische Berechnungen: </b>
<br><br>
Es ist $f(k)$ für $k=0, 1, 2,...$ zu bestimmen, wenn
$F_z(z)= \frac{8z^{-1}}{(z-1)(z-2)}$
egeben ist.
<span style='color:OrangeRed'> Lösung:</span>
Durch Umschreiben folgt:
$F_z(z)= \frac{8z^{-1}}{1-3z^{-1}+2z^{-2}}$
Durch Division erhält man:
$F_z(z)=8z^{-1}+24z^{-2}+56z^{-3}+120z^{-4}+...$
Aus dieser Beziehung können direkt die Werte der Zahlenfolge $f(k)$ abgelesen werden:
$f(0)=0$, $f(1)=8$, $f(2)=24$, $f(3)=56$, $f(4)=120$,...
%% Cell type:markdown id: tags:
## <span style='color:Gray'>Beispiel #2 </span>
%% Cell type:code id: tags:
``` octave
N = [8 2 3 2 1];
D = [1 0 0 0 0];
```
%% Cell type:code id: tags:
``` octave
[fo R] = deconv(N,D)
```
%% Cell type:code id: tags:
``` octave
R = conv(R,[1 0])
[f1 R] = deconv(R,D)
```
%% Cell type:code id: tags:
``` octave
R = conv(R,[1 0])
[f2 R] = deconv(R,D)
```
%% Cell type:code id: tags:
``` octave
R = conv(R,[1 0])
[f3 R] = deconv(R,D)
```
%% Cell type:code id: tags:
``` octave
R = conv(R,[1 0])
[f4 R] = deconv(R,D)
```
%% Cell type:code id: tags:
``` octave
R = conv(R,[1 0])
[f5 R] = deconv(R,D)
```
%% Cell type:markdown id: tags:
<div style="font-family: 'times'; font-size: 13pt; text-align: justify">
- Die Koeffizienten der Folge <code>f</code> entsprechen den Elementen des Zählervektors <code>N</code>.
- <code>R</code> wird lediglich = $ 0$.
- Gezeigt wurde ein <span style='color:OrangeRed'>„Finite Impulse Response“ </span>(kurz: <span style='color:OrangeRed'>FIR </span>) Filter.
%% Cell type:markdown id: tags:
## <span style='color:Gray'>Beispiel #3 </span>
%% Cell type:markdown id: tags:
<div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Es gelten weiterhin die Werte aus dem <span style='color:Gray'>Beispiel #1 </span>:
$num$=$8z^{-1}$
$den$=$1-3z^{-1}+2z^{-2}$
Wir bestimmen außerdem die Anzahl der Abtastpunkte:
$npoint$ = $20$
Wie zuvor, wird wiederholt die Entfaltung, also Division durchgeführt. Der Code wird in
einer Funktion „ longdiv “ zusammengefasst.
%% Cell type:code id: tags:
``` octave
function y = longdiv(num,den,npoint)
[y(1) R] = deconv(num,den);
for i=2:npoint
num = conv(R,[1 0]);
[f R] = deconv(num,den);
y(i) = f(length(f));
end
end
```
%% Cell type:code id: tags:
``` octave
num = [8 0];
den = [1 -3 2];
npoint = 20;
y = longdiv(num, den, npoint);
plot(y)
```
%% Cell type:markdown id: tags:
<div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Das System ist instabil.
%% Cell type:markdown id: tags:
## <span style='color:Gray'>Beispiel #4 </span>
%% Cell type:code id: tags:
``` octave
pkg load control
Ts = 0.1;
p = -1;
npoint = 20;
y1 = longdiv([1 0],[1 -exp(Ts*p)],npoint);
t =(1:npoint)*Ts-Ts;
```
%% Cell type:code id: tags:
``` octave
yc = impulse(tf(1,[1 1]),t);
plot(t,yc,'r',t,y1,'*')
```
%% Cell type:code id: tags:
``` octave
yh = longdiv(1-exp(Ts*p),[1 -exp(Ts*p)],npoint);
plot(t,yh,'+')
```
%% Cell type:markdown id: tags:
## <span style='color:Gray'>Beispiel #5 </span>
%% Cell type:code id: tags:
``` octave
function [G Ph] = BodeZOH(Ts,ommax,dom)
k=0;
kmax = round(ommax/dom);
for k=1:kmax
om(k) = k*dom;
Renum = 1 -cos(-om(k)*Ts);
Imnum = -sin(-om(k)*Ts);
Gnum = sqrt(Renum*Renum+Imnum*Imnum);
G(k) = Gnum/(om(k)*Ts);
Ph(k) = atan2(Imnum,Renum)-pi/2;
end
end
Ts = 0.1;
ommax = 100;
dom = 0.1;
om=[0.1:0.1:100];
[G Ph] = BodeZOH(Ts,ommax,dom);
subplot(2,1,1), semilogx(om,20*log10(G));
subplot(2,1,2), semilogx(om,Ph*90/pi);
```
%% Cell type:markdown id: tags:
<div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Die Amplitude ist im z Bereich kleiner als 20dB.
%% Cell type:markdown id: tags:
## <span style='color:Gray'>Beispiel #6 </span>
%% Cell type:markdown id: tags:
<div style="font-family: 'times'; font-size: 13pt; text-align: justify">
- Wir stellen drei Verfahren vor, wie in Matlab die Transformation von kontinuierlichen Systemen zu diskreten Systemen erfolgen kann.
- Dabei wird die Matlabfunktion<code>c2d</code> verwendet
- Gegeben sei das System:
$G(s)=\frac{1}{s+1}$ und $T_s=0,1$
%% Cell type:code id: tags:
``` octave
pkg load control
```
%% Cell type:code id: tags:
``` octave
disp('Abtastzeit')
Ts = 0.1
disp('Kontinuierliche Systeme')
G = tf(1,[1 1])
disp('Beispiel 1: ZOH')
Gh = c2d(G,Ts,'zoh')
disp('Beispiel 2: Impulse')
Gz = c2d(G,Ts,'impulse')
disp('Bespiel 3: Verfahren G(s)/s')
Gi = tf([1],[1 0])
Gs = G*Gi
Gsz = c2d(Gs,Ts,'impulse')
Gh = tf([1 -1], [1 0],Ts)
Gf = Gh*Gsz/Ts;
minreal(Gf)
```
%% Cell type:code id: tags:
``` octave
% Set the Octave Engine to run the simulatio
% Simulation Parameters
pkg load control
addpath("./Octsim");
% Start time
tini = 0;
% End time
tfinal = 5;
% Time Step
dt = 0.001;
% Number of data flows in the schematic
nflows = 5;
% Sampling time for discrete time
Ts = 0.1;
% Instance of the simulation schematic
sc = Schema(tini,tfinal,dt,nflows);
% List of components
c{1} = SinusoidalSignalSource(1,1,2*pi,0);
c{2} = TransferFunction(1,2,1,[1,1]); %G(s)
c{3} = ZOH(1,3,Ts);
c{4} = TransferFunction(3,4,1,[1,1]); %Example 1 - ZOH at the input
c{5} = DTTransferFunction(1,5,[0.09516],[1 -exp(-0.1)],Ts); %Example 2
c{6} = DTTransferFunction(1,6,[0.1 0],[1 -exp(-0.1)],Ts) ;%Example 3
sc.AddListComponents(c);
% Run the schematic and plot
out = sc.Run([ 2 3 4 5 6]);
%plot(out(1,:),out(2,:),out(1,:),out(3,:),out(1,:),out(4,:));
plot(out(1,:),out(2,:),out(1,:),out(4,:),out(1,:),out(5,:), out(1,:),out(6,:));
```
%% Cell type:markdown id: tags:
## <span style='color:Gray'>Beispiel #7 </span>
%% Cell type:markdown id: tags:
<div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Gegeben ist : $G(z)=\frac{z}{z-e^{-\tau}}$, und $U(z)=\frac{z}{z-1}$ mit $\tau=0,1$
Und nehmen wir an: $Y(z)=G(z)U(z)$
%% Cell type:code id: tags:
``` octave
pkg load control
```
%% Cell type:code id: tags:
``` octave
Ts = 0.1;
Gz = tf([1 0],[1 -exp(-0.1)],Ts);
%Impuls: longdiv(num,den,100)
y1=longdiv(cell2mat(Gz.num),cell2mat(Gz.den),100);
plot(y1);
```
%% Cell type:code id: tags:
``` octave
Uz = tf([1 0],[1 -1],Ts);
Yz = Gz*Uz;
y2=longdiv(cell2mat(Yz.num),cell2mat(Yz.den),100);
plot(y2);
```
%% Cell type:markdown id: tags:
<div style="font-family: 'times'; font-size: 13pt; text-align: justify">
Die Übertragungsfunktion lautet stattdessen:
<br><br>
$G(z)$=$\frac{z(z-e^{-\tau})-(z-1)}{(z-1)(z-e^{-\tau})}$
%% Cell type:code id: tags:
``` octave
Gz2 = tf([1-exp(-0.1) 0],[1 -1-exp(-0.1) exp(-0.1)],Ts);
y3=longdiv(cell2mat(Gz2.num),cell2mat(Gz2.den),100);
plot(y3);
```
%% Cell type:code id: tags:
``` octave
```
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.