Commit 6e3e3fa3 authored by Christian Rohlfing's avatar Christian Rohlfing
Browse files

- added a little text to Laplace-Transform

parent 095aae6f
%% Cell type:code id: tags:
``` python
# Copyright 2019 Institut für Nachrichtentechnik, RWTH Aachen University
%matplotlib notebook
from ipywidgets import interact, interactive, fixed, HBox, VBox
import ipywidgets as widgets
from IPython.display import clear_output, display, HTML
from IPython.display import Markdown as md
from ient_nb.ient_plots import *
from ient_nb.ient_signals import *
from src.laplace.laplace_plot import pzPoint, pzPlot
from src.funcs import calc_Hf, calc_ht
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import numpy as np
t = np.linspace(-6,6,1024)
f = np.linspace(-6,6,1024)
```
%% Cell type:code id: tags:
%% Cell type:markdown id: tags:
``` python
pp = [1+1j]; pz = [2+1j]; ord_p = [2]; ord_z = [1]
roc = [np.amax(np.real(pp)), 12] # rechtsseitige Konvergenz
<div>
<img src="ient_nb/figures/rwth_ient_logo@2x.png" style="float: right;height: 5em;">
</div>
# Übertragungsfunktion im Laplace-Bereich
fig,ax = plt.subplots(1,1)
ient_axis(ax)
ax.set_xlim(-6, 6); ax.set_ylim(-6, 6)
# Laplace-Transformation
ax.plot(np.real(pp), np.imag(pp), **ient_style_poles); ax.plot(np.real(pp), -np.imag(pp), **ient_style_poles)
ax.plot(np.real(pz), np.imag(pz), **ient_style_zeros); ax.plot(np.real(pz), -np.imag(pz), **ient_style_zeros)
ient_plot_roc(ax, roc)
%% Cell type:markdown id: tags:
# print orders
for index, order in enumerate(ord_p+ord_z):
if order > 1:
ax.text(np.real((pp+pz)[index]), np.imag((pp+pz)[index]), '(' + str(order) + ')', color='black')
ax.text(np.real((pp+pz)[index]), -np.imag((pp+pz)[index]), '(' + str(order) + ')', color='black')
Beispiele
H0 = 1
$s_1(t) = \mathrm{e}^{-bt}\cdot\epsilon(t)$
transformiert sich zu
$S_1(p) = \frac{1}{b+p}$ mit Konvergenzbereich $\mathrm{Re}\{p\}>\mathrm{Re}\{-b\}$
# Impulsantwort im Zeitbereich
t = np.linspace(-6,6,1024)
%% Cell type:code id: tags:
h, _ = calc_ht(t, H0, pp, pz, ord_p, ord_z, roc)
fig,ax = plt.subplots(1,1)
ax.plot(t,np.real(h), **ient_style_graph); ax.set_xlabel(r'$t$'); ax.set_ylabel(r'$h(t)$'); # won't work with dirac
``` python
b = 2
pp = np.array([-b]); pz = np.array([])
roc = np.array([-b, np.inf])
fig,axs = plt.subplots(1,2)
# Laplace-Bereich
ax = axs[0]
ient_plot_lroc(ax, roc)
ax.plot(np.real(pp), np.imag(pp), **ient_style_poles); ax.plot(np.real(pp), -np.imag(pp), **ient_style_poles)
ax.set_xlabel(r'$\rightarrow \mathrm{Re}$'); ax.set_ylabel(r'$\uparrow \mathrm{Im}$');
ax.set_xlim(-5, 5); ax.set_ylim(-5, 5); ient_grid(ax); ient_axis(ax)
# Frequenzbereich
f = np.linspace(-6,6,1024)
# Zeitbereich
ax = axs[1]
s1, _ = calc_ht(t, 1, pp, pz, [1], [], roc)
ax.plot(t, np.real(s1), **ient_style_graph);
ax.set_xlabel(r'$\rightarrow t$'); ax.set_ylabel(r'$\uparrow s_1(t)$'); ient_grid(ax); ient_axis(ax)
```
H = calc_Hf(f, H0, pp, pz, ord_p, ord_z)
fig,ax = plt.subplots(1,1)
ax.plot(f, H, **ient_style_graph); ax.set_xlabel(r'$f$'); ax.set_ylabel(r'$H(f) / dB$');
%% Cell type:markdown id: tags:
Konvergenzbereich umschließt imaginäre Achse, also existiert auch die Fouriertransformierte $S_1(f)$
%% Cell type:code id: tags:
``` python
# Frequenzbereich
S1f = 10**(calc_Hf(f, 1, pp, pz, [1], [])/20)
fig, ax = plt.subplots(1,1)
ax.plot(f, S1f, **ient_style_graph);
ax.set_xlabel(r'$\rightarrow f$'); ax.set_ylabel(r'$\uparrow S_1(f)$');
ax.set_xlim([-5.5,5.5]); ax.set_ylim([-0.1,0.55]); ient_grid(ax); ient_axis(ax)
```
%% Cell type:markdown id: tags:
$s_2(t) = -\mathrm{e}^{-bt}\cdot\epsilon(-t)$
transformiert sich zu
$S_2(p) = \frac{1}{b+p}$ mit Konvergenzbereich $\mathrm{Re}\{p\}<\mathrm{Re}\{-b\}$
%% Cell type:code id: tags:
``` python
roc = np.array([-np.inf, -b])
fig,axs = plt.subplots(1,2)
# Laplace-Bereich
ax = axs[0]
ient_plot_lroc(ax, roc); ient_annotate_order(ax, pp, [1]);
ax.plot(np.real(pp), np.imag(pp), **ient_style_poles); ax.plot(np.real(pp), -np.imag(pp), **ient_style_poles)
ax.set_xlabel(r'$\rightarrow \mathrm{Re}$'); ax.set_ylabel(r'$\uparrow \mathrm{Im}$');
ax.set_xlim(-5, 5); ax.set_ylim(-5, 5); ient_axis(ax); ient_grid(ax)
# Zeitbereich
ax = axs[1]
s2, _ = calc_ht(t, 1, pp, pz, [1], [], roc)
ax.plot(t, np.real(s2), **ient_style_graph);
ax.set_ylim([-45,5]); ax.grid();
ax.set_xlabel(r'$\rightarrow t$'); ax.set_ylabel(r'$\uparrow s_2(t)$'); ient_axis(ax)
```
%% Cell type:markdown id: tags:
## Interaktive Demo
%% Cell type:code id: tags:
``` python
pzp = pzPlot()
filter_type = interactive(pzp.update_filter,filtr=widgets.Dropdown(options=list(pzp.filter_types.keys()), value="Sprungfunktion", description='Filter'))
action_type = interactive(pzp.update_action,action=widgets.Dropdown(options=list(pzp.action_types.keys()),value="Hinzufügen", description='Modus'))
point_type = interactive(pzp.update_mode,mode=widgets.Dropdown(options=list(pzp.mode_types.keys()), value="Polstelle", description='Typ'))
amp_type = interactive(pzp.update_amp, H0=widgets.IntSlider(min=1,max=10,step=1,value=1), description="H0")
left_box = VBox([filter_type, amp_type])
right_box = VBox([action_type, point_type])
HBox([left_box, right_box])
```
%% Cell type:code id: tags:
%% Cell type:markdown id: tags:
``` python
```
This notebook is provided as [Open Educational Resource](https://en.wikipedia.org/wiki/Open_educational_resources) (OER). Feel free to use the notebook for your own purposes. The code is licensed under the [MIT license](https://opensource.org/licenses/MIT).
Please attribute the work as follows:
*Emin Kosar, Christian Rohlfing, Übungsbeispiele zur Vorlesung "Grundgebiete der Elektrotechnik 3 - Signale und Systeme"*, gehalten von Jens-Rainer Ohm, 2019, Institut für Nachrichtentechnik, RWTH Aachen University.
......
Subproject commit d25eaaeb45d7cfc6a6432a0dff1136eb3a952fde
Subproject commit 288df39b2f05def6d9a6b7cc536d63cc243197ca
......@@ -84,7 +84,7 @@ class pzPlot():
def open_figure(self):
fig = plt.figure(figsize=(10, 9))
fig = plt.figure(figsize=(8, 8))
gs = gridspec.GridSpec(2, 2)
# First axis for plotting s and h
......@@ -99,7 +99,7 @@ class pzPlot():
ient_axis(ax)
self.fig = fig
self.ax = ax
self.ax.set_title('Pol- /Nullstellen Diagramm', fontsize='16', fontweight='bold')
self.ax.set_title('Pol- /Nullstellen Diagramm', fontsize='12')
def onclick(event):
if event.inaxes != self.ax: return
......@@ -110,9 +110,9 @@ class pzPlot():
self.handles['axh'] = plt.subplot(gs[1, 0])
self.handles['axh'].set_title('Impulsantwort', fontsize='16',fontweight='bold')
self.handles['axh'].set_xlabel(r'$\rightarrow \mathrm{t}$')
self.handles['axh'].set_ylabel(r'$\uparrow \mathrm{s(t)}$')
self.handles['axh'].set_title('Impulsantwort', fontsize='12')
self.handles['axh'].set_xlabel(r'$\rightarrow t$')
self.handles['axh'].set_ylabel(r'$\uparrow h(t)$')
self.pbzErrortxt = self.handles['axh'].text(-4.5,
0.55, # hässlich
'Zählergrad größer als Nennergrad. \nKeine Partialbruchzerlegung möglich!',
......@@ -120,9 +120,9 @@ class pzPlot():
self.handles['lineh'], = self.handles['axh'].plot(self.t, self.t)
ient_axis(self.handles['axh'])
self.handles['axH'] = plt.subplot(gs[1, 1])
self.handles['axH'].set_title('Übertragungsfunktion', fontsize='16', fontweight='bold')
self.handles['axH'].set_title('Übertragungsfunktion', fontsize='12')
self.handles['axH'].set_xlabel(r'$\rightarrow f$')
self.handles['axH'].set_ylabel(r'$\uparrow \mathrm{|S(f)|}$')
self.handles['axH'].set_ylabel(r'$\uparrow \mathrm{|H(f)|}$ [dB]')
self.handles['lineH'], = self.handles['axH'].plot(self.f, self.f)
ient_axis(self.handles['axH'])
self.handles['axH'].spines['bottom'].set_position(('outward', 0))
......@@ -265,15 +265,15 @@ class pzPlot():
y2 = [12, 12]
if self.roc['lleft'] is None:
self.roc['lleft'], = self.ax.plot([xx[0], xx[0]], [y1[0], y2[0]], ls="--", c="b")
self.roc['lright'], = self.ax.plot([xx[1], xx[1]], [y1[0], y2[0]], ls="--", c="b")
self.roc['hatch'] = self.ax.fill_between(xx, y1, y2, facecolor="none", hatch="/", edgecolor="b",
self.roc['lleft'], = self.ax.plot([xx[0], xx[0]], [y1[0], y2[0]], ls="--", c="rwth")
self.roc['lright'], = self.ax.plot([xx[1], xx[1]], [y1[0], y2[0]], ls="--", c="rwth")
self.roc['hatch'] = self.ax.fill_between(xx, y1, y2, facecolor="none", hatch="/", edgecolor="rwth",
linewidth=0.0)
else:
self.roc['lleft'].set_xdata([xx[0], xx[0]])
self.roc['lright'].set_xdata([xx[1], xx[1]])
self.roc['hatch'].remove()
self.roc['hatch'] = self.ax.fill_between(xx, y1, y2, facecolor="none", hatch="/", edgecolor="b",
self.roc['hatch'] = self.ax.fill_between(xx, y1, y2, facecolor="none", hatch="/", edgecolor="rwth",
linewidth=0.0)
self.update_plot()
......@@ -294,7 +294,7 @@ class pzPlot():
except AttributeError:
pass
self.H0_txt = self.ax.text(4.5, 5,'H0: ' + str(self.H0), fontsize=18)
self.H0_txt = self.ax.text(4.5, 5,r'$H_0$: ' + str(self.H0), fontsize=12, bbox=ient_wbbox)
self.update_plot()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment