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

- fixed axis limits bugs (Diskrete Faltung), also commenting

parent e4bcc0e2
......@@ -47,11 +47,11 @@
Zusätzlich zu Elementarsignalen kann auch eine frei definierbare Funktion $s_0(t)$ zur Faltung verwendet werden.
%% Cell type:code id: tags:
``` python
s_0 = lambda n: 0.5 * (unitstep(n-2) + unitstep(-(n+2)))
s_0 = lambda n: gauss(n)
```
%% Cell type:code id: tags:
``` python
......@@ -91,31 +91,31 @@
except NameError:
pass
# display s and h plots
if container_s is None:
# plot s
ax = axs0[0];
container_s = ient_stem(ax, m, s(m), 'rwth')
ax.set_xticks(np.arange(-10, 11, step=2))
ax.set_xlabel(r'$\rightarrow n$'); ax.set_ylabel(r'$\uparrow s(n)$')
ax.set_xlim([-10.9, 10.9]); ient_axis(ax); ient_grid(ax);
ient_update_ylim(ax, s(m), .19)
# plot h
ax = axs0[1];
container_h = ient_stem(ax, m, h(m), 'rwth')
ax.set_xticks(np.arange(-10, 11, step=2))
ax.set_xlabel(r'$\rightarrow n$'); ax.set_ylabel(r'$\uparrow h(n)$')
ax.set_xlim(axs0[0].get_xlim()); ient_axis(ax); ient_grid(ax);
ient_update_ylim(ax, s(m), .19)
else:
ient_stem_set_ydata(container_s, s(m))
ient_update_ylim(axs0[0], s(m), .19)
ient_stem_set_ydata(container_h, h(m))
ient_update_ylim(axs0[1], h(m), .19)
# update limits
ient_update_ylim(axs0[0], s(m), .19)
ient_update_ylim(axs0[1], h(m), .19)
# Widgets
w_s_type=widgets.Dropdown(options=list(signal_types.keys()), description=r'Wähle $s(n)$:', style=ient_wdgtl_style)
w_s_n0=widgets.FloatSlider(min=-5, max=5, value=0, step=1, description=r'Verschiebung $n_0$', style=ient_wdgtl_style)
w_h_type=widgets.Dropdown(options=list(signal_types.keys()), description=r'Wähle $h(n)$:', style=ient_wdgtl_style)
......@@ -146,44 +146,56 @@
global container_ss, container_hh, container_gg
global n0
n0 = n
n_ind = np.where(m>=n); n_ind = n_ind[0][0]; g_plot = gn.copy(); g_plot[n_ind+1:] = 0; # hide g(n') with n'>n
if container_gg is None:
# plot g = s * h
ax = axs[1]
container_gg = ient_stem(ax, m, g_plot)
if container_ss is not None:
# update data
ient_stem_set_ydata(container_ss, s(m))
ient_stem_set_ydata(container_hh, h(n-m))
ient_stem_set_ydata(container_gg, g_plot)
# update labels
ax = axs[0]
ax.texts[0].set_x(n); ax.lines[3].set_xdata([n,n]) # update labels
ax.texts[0].set_x(n); ax.lines[3].set_xdata([n,n])
ax = axs[1]
ax.texts[0].set_x(n); ax.lines[2].set_xdata([n,n]); ax.texts[0].set_y(np.min(ax.get_ylim()));
ax.lines[3].set_xdata([n, n]); ax.lines[3].set_ydata([0, gn[n_ind]]);
else:
ax = axs[0];
# plot s and h
ax = axs[0]; # s and h axis
container_ss = ient_stem(ax, m, s(m), 'grun', label=r'$s(m)$')
container_ss[0].set_markerfacecolor('none');
container_ss[0].set_markersize(8);
container_ss[0].set_markeredgewidth(2);
container_hh = ient_stem(ax, m, h(n-m), 'rwth', label=r'$h(n-m)$')
ient_annotate_xtick(ax, r'$n$', n, -0.1, 'rwth', 15); # mark n on m axis
# configure axis settings
ax.set_xlabel(r'$\rightarrow m$');
ax.set_xlim([-10.2,10.2]); ient_update_ylim(ax, np.concatenate((h(m), s(m))), 0.19, 5);
ax.set_xlim([-10.2,10.2]);
ax.set_xticks(np.arange(-10, 11, step=2))
ax.legend(); ient_grid(ax); ient_axis(ax);
ient_annotate_xtick(ax, r'$n$', n, -0.1, 'rwth', 15); # mark n on m axis
# configure g axis settings
ax = axs[1]
ax.set_xlabel(r'$\rightarrow n$'); ax.set_ylabel(r'$\uparrow g(n)=s(n)\ast h(n)$');
ax.set_xlim(axs[0].get_xlim()); ient_update_ylim(ax, gn, 0.19, 20);
ax.set_xlabel(r'$\rightarrow n$'); ax.set_ylabel(r'$\uparrow g(n)=s(n)\ast h(n)$');
ax.set_xlim(axs[0].get_xlim())
ax.set_xticks(np.arange(-10, 11, step=2))
ient_grid(ax); ient_axis(ax);
ient_annotate_xtick(ax, r'$n$', n, np.min(ax.get_ylim()), 'black', 15);
ax.plot([n, n], [0, gn[n_ind]], 'ko--', lw=1);
ient_update_ylim(axs[0], np.concatenate([s(m), h(n-m)]), .19)
ient_update_ylim(axs[1], gn, .19, ymax=1e3)
# update limits
if np.all(gn>0):
gn[0] = 0
ient_update_ylim(axs[0], np.concatenate([s(m), h(n-m)]), .19, ymax = 1e3)
ient_update_ylim(axs[1], gn, np.max(np.abs(gn))/10, ymax = 1e3)
```
%% Cell type:markdown id: tags:
## Aufgaben
......
Markdown is supported
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