Commit d0dc6db0 authored by Hafiz Emin Kosar's avatar Hafiz Emin Kosar
Browse files

bug fixes, show H0, set correct ylims, set titles

parent 7ed67c4b
%% Cell type:code id: tags:
``` python
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 src.laplace.laplace_plot import pzPoint, pzPlot
from src.laplace.inline_plot import inline_plot
%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import numpy as np
```
%% Cell type:code id: tags:
``` python
inline_plot('right')
```
%% Cell type:code id: tags:
``` python
inline_plot('left')
```
%% Cell type:code id: tags:
``` python
%matplotlib notebook
%matplotlib notebook
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:
``` python
# mehrfache Polstelle bei komplex funktioniert nicht
# H0 anzeigen
# Achse wandert hoch - ient_axis?
# Achsenlimits anpassen
# Achsenüberschriften P/N- Diagramm, Übertragungsfunktion, Impulsantwort
# update_signal todos beachten
# dirac spitzer!
# f statt omega
# Skript S. 18 2.2 P/N-Diagramm, 2 Cells versch. KBs, pn und t plotten
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
......
......@@ -100,17 +100,22 @@ def getSignalType(array):
def calc_laplace(t=np.linspace(-6, 6, num=1024), omega = np.linspace(-6, 6, num=1024), H0=1, pp=np.array([]), pz=np.array([]), ord_p=np.array([]),
def calc_laplace(t=np.linspace(-6, 6, num=1024), f = np.linspace(-6, 6, num=1024), H0=1, pp=np.array([]), pz=np.array([]), ord_p=np.array([]),
ord_z=np.array([]), roc = [-12, 12]):
Polstellen = np.array([])
KomplexPolstellen = np.array([])
GradPolstellen = np.array([])
GradKomplexPolstellen = np.array([])
for c, point in enumerate(pp):
Polstellen = np.append(Polstellen, point)
GradPolstellen = np.append(GradPolstellen, ord_p[c])
if np.abs(np.imag(point)) > 0:
Polstellen = np.append(Polstellen, np.conj(point))
GradPolstellen = np.append(GradPolstellen, ord_p[c])
KomplexPolstellen = np.append(KomplexPolstellen, np.conj(point))
GradKomplexPolstellen = np.append(GradKomplexPolstellen, ord_p[c])
Polstellen = np.append(Polstellen, KomplexPolstellen)
GradPolstellen = np.append(GradPolstellen, GradKomplexPolstellen)
Nullstellen = np.array([])
GradNullstellen = np.array([])
......@@ -129,23 +134,23 @@ def calc_laplace(t=np.linspace(-6, 6, num=1024), omega = np.linspace(-6, 6, num=
"""
#####
zaehler = H0 * np.ones(omega.shape)
zaehler = H0 * np.ones(f.shape)
for i in range(0, len(pz)):
for j in range(1, ord_z[i] + 1):
zaehler = zaehler * (1j * omega - pz[i])
zaehler = zaehler * (1j * f - pz[i])
if np.abs(np.imag(pz[i])) > 0:
zaehler = zaehler * (1j * omega - np.conj(pz[i]))
zaehler = zaehler * (1j * f - np.conj(pz[i]))
#####
nenner = np.ones(omega.shape)
nenner = np.ones(f.shape)
for i in range(0, len(pp)):
for j in range(1, ord_p[i] + 1):
nenner = nenner * (1j * omega - pp[i])
nenner = nenner * (1j * f - pp[i])
if np.abs(np.imag(pp[i])) > 0:
nenner = nenner * (1j * omega - np.conj(pp[i]))
nenner = nenner * (1j * f - np.conj(pp[i]))
#####
......@@ -216,7 +221,7 @@ def calc_laplace(t=np.linspace(-6, 6, num=1024), omega = np.linspace(-6, 6, num=
b[-1:, 0] = p
try:
A_inv = np.around(np.linalg.inv(A), 3)
A_inv = np.around(np.linalg.inv(A), 8) # precision
except np.linalg.LinAlgError:
# Not invertible.
pass
......@@ -243,7 +248,7 @@ def calc_laplace(t=np.linspace(-6, 6, num=1024), omega = np.linspace(-6, 6, num=
tmp[np.where(t >= 0)] = 0
tmp = -tmp
h = h + tmp
h = np.add(h, tmp)
a[0] = np.real(a[0])
if np.abs(a[0]) > 2e-16:
......
......@@ -8,11 +8,9 @@ def plot(t, y, axes):
# print(sType)
def plot_real():
print("plotting real")
axes.plot(t, np.real(y))
def plot_dirac():
print("plotting dirac")
(ind, val) = findDirac(y)
for i in range(0, len(ind)):
x_value = t[ind[i]]
......
......@@ -47,6 +47,7 @@ class pzPlot():
self.H0 = 1
self.filter = 'unit'
self.H0_txt = None
self.length = 1024
self.t = np.linspace(-6, 6, num=self.length)
......@@ -95,6 +96,7 @@ class pzPlot():
ient_axis(ax)
self.fig = fig
self.ax = ax
self.ax.set_title('Pol- /Nullstellen Diagramm', fontsize='16', fontweight='bold')
def onclick(event):
if event.inaxes != self.ax: return
......@@ -105,9 +107,11 @@ class pzPlot():
self.handles['axh'] = plt.subplot(gs[1, 0])
self.handles['axh'].set_title('Impulsantwort', fontsize='16',fontweight='bold')
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['lineH'], = self.handles['axH'].plot(self.f, self.f)
ient_axis(self.handles['axH'])
# TODO ient_axis für H ändern
......@@ -275,6 +279,14 @@ class pzPlot():
def update_amp(self, H0):
self.H0 = H0
try:
self.H0_txt.remove()
except AttributeError:
pass
self.H0_txt = self.ax.text(4.5, 5,'H0: ' + str(self.H0), fontsize=18)
self.update_plot()
def update_filter(self, filtr):
......@@ -368,9 +380,18 @@ class pzPlot():
roc = self.roc['sigma']
s_t, S_f = func.calc_laplace(self.t, self.f, H0, poles, zeroes, poles_order, zeroes_order, roc)
# TODO - ylims anpassen
# calculate extreme values, for ylims
s_t_extr = [np.amin(np.real(s_t)), np.amax(np.real(s_t))]
S_f_extr = [np.amin(np.real(S_f)), np.amax(np.real(S_f))]
# set ylims
self.handles['axh'].set_ylim(s_t_extr[0] + s_t_extr[0] / 10, s_t_extr[1] + s_t_extr[1] / 10)
self.handles['axH'].set_ylim(S_f_extr[0] + S_f_extr[0] / 10, S_f_extr[1] + S_f_extr[1] / 10)
ient_axis(self.handles['axh'])
plot(self.t, s_t, self.handles['axh'])
# TODO - Eigene Funktion plottet s(t) nicht, was läuft hier schief?
#plot(self.t, s_t, self.handles['axh'])
self.handles['lineh'].set_ydata(s_t)
plot(self.f, S_f, self.handles['axH'])
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