Miscellaneous

  1. Feedback

  2. Transforms

    1. Fourier Transform

    2. Laplace Transform

    3. :math:`z-Transform <#$z$-Transform>`__

Feedback

[1]:
import rwth_nb.misc.feedback as rwth_feedback

mail_to = "example@rwth-aachen.de" # send feedback via mail
feedback_name = rwth_feedback.get_notebook_name() # get name of notebook automatically
rwth_feedback.rwth_feedback(feedback_name, [
    {'id': 'likes', 'type': 'free-text', 'label': 'Das war gut:'},
    {'id': 'dislikes', 'type': 'free-text', 'label': 'Das könnte verbessert werden:'},
    {'id': 'misc', 'type': 'free-text', 'label': 'Was ich sonst noch sagen möchte:'},
    {'id': 'learning', 'type': 'scale', 'label' : 'Ich habe das Gefühl etwas gelernt zu haben.'},
    {'id': 'supervision', 'type': 'scale', 'label' : 'Die Betreuung des Versuchs war gut.'},
    {'id': 'script', 'type': 'scale', 'label' : 'Die Versuchsunterlagen sind verständlich.'},
], "feedback.json", mail_to)

Transforms

Following transforms are defined in rwth_nb.misc.transforms:

Note that plotting basics are described inRWTH Plots.

Fourier Transform

dft(s, fs, NFFT)

[2]:
import matplotlib.pyplot as plt
import numpy as np

import rwth_nb.plots.mpl_decorations as rwth_plots
import rwth_nb.misc.transforms as rwth_transforms


# Time Domain
fs = 44100 # very high sampling rate assumed, to simulate quasi-continuous time and frequency axis
t = np.linspace(-2.5, 2.5, 5*fs)
s = np.sin(2*np.pi*500*t)

# Fourier Transform
S,f = rwth_transforms.dft(s, fs)

# plots
fig,axs = plt.subplots(2,1, **rwth_plots.landscape);

ax = axs[0]; ax.plot(t*1000, s);
ax.set_xlabel(r'$\rightarrow t$ [ms]'); ax.set_ylabel(r'$\uparrow s(t)$')
ax.set_xlim([-11, 11]); ax.set_ylim([-1.1, 1.19]); rwth_plots.axis(ax);

ax = axs[1]; ax.plot(f, np.abs(S));
ax.set_xlabel(r'$\rightarrow f$ [Hz]'); ax.set_ylabel(r'$\uparrow |S(f)|$')
ax.set_xlim([-1100, 1100]); ax.set_ylim([0, 0.65]); rwth_plots.axis(ax);
/usr/local/lib/python3.8/site-packages/traitlets/traitlets.py:3030: FutureWarning: --rc={'figure.dpi': 96} for dict-traits is deprecated in traitlets 5.0. You can pass --rc <key=value> ... multiple times to add items to a dict.
  warn(
../_images/examples_RWTH_Misc_6_1.svg

Inverse Fourier transform

idft(S, Ntime, NFF)

[3]:
s2 = rwth_transforms.idft(S, len(s));

fig,ax = plt.subplots(**rwth_plots.landscape);
ax.plot(t*1000, np.real(s2));
ax.set_xlabel(r'$\rightarrow t$ [ms]'); ax.set_ylabel(r'$\uparrow \mathcal{F}^{-1}\{S(f)\}$')
ax.set_xlim([-11, 11]); ax.set_ylim([-1.1, 1.19]); rwth_plots.axis(ax);
../_images/examples_RWTH_Misc_8_0.svg

Laplace Transform

Pole-zero plot is explained in RWTH Plots.

Inverse Laplace Transform

ilaplace_ht(t, H0, pp, pz, ord_p, ord_z, roc)

ilaplace_Hf(f, H0, pp, pz, ord_p, ord_z, dB)

[4]:
fig,axs = plt.subplots(1, 2, figsize=(10, 4))

t = np.linspace(-6, 6, 1024)
f = np.linspace(-6, 6, 1024)

pp = np.array([-2]); pz = np.array([]) # Poles and Zeros
ord_p = np.array([1]); ord_z = np.array([]) # Poles' and Zeros' orders
roc = np.array([-2, np.inf]) # region of convergence
H0 = 1

# Time Domain
s1, t1d , s1d = rwth_transforms.ilaplace_ht(t, H0, pp, pz, ord_p, ord_z, roc)

ax = axs[0]
ax.set_xlabel(r'$\rightarrow t$'); ax.set_ylabel(r'$\uparrow s_1(t)$')
rwth_plots.grid(ax); rwth_plots.axis(ax)
ax.set_xlim([-5.5,5.5]); axs[0].set_ylim([-0.1,1.05]);
ax.plot(t, np.real(s1))
rwth_plots.plot_dirac(axs[0], t1d, s1d);

# Frequency Domain
S1f = rwth_transforms.ilaplace_Hf(f, H0, pp, pz, ord_p, ord_z, dB=False)

ax = axs[1]
ax.set_xlabel(r'$\rightarrow f$'); ax.set_ylabel(r'$\uparrow S_1(f)$')
rwth_plots.grid(ax); rwth_plots.axis(ax)
ax.set_xlim([-5.5,5.5]); ax.set_ylim([-0.1,0.55]);
ax.plot(f, S1f);
[4]:
[<matplotlib.lines.Line2D at 0x7f905e2401f0>]
../_images/examples_RWTH_Misc_10_1.svg

\(z\) Transform

Pole-zero plot is explained in RWTH Plots.

Inverse \(z\) Transform

iz_hn(n, H0, pp, pz, ord_p, ord_z, roc)

iz_Hf(f, H0, pp, pz, ord_p, ord_z, dB)

[5]:
fig,axs = plt.subplots(1, 2, figsize=(10, 4))

n = np.linspace(-6, 6, 13)
f = np.linspace(-6, 6, 1024)

zp = np.array([.5, 2]); zz = np.array([0]) # Poles and Zeros
ord_p = np.array([1, 1]); ord_z = np.array([1]) # Poles' and Zeros' orders
roc = np.array([.5, 2]) # region of convergence
H0 = -3/2

# Time Domain
s1= rwth_transforms.iz_hn(n, H0, zp, zz, ord_p, ord_z, roc)

ax = axs[0]
ax.set_xlabel(r'$\rightarrow n$'); ax.set_ylabel(r'$\uparrow s_1(n)$')
rwth_plots.grid(ax); rwth_plots.axis(ax)
ax.set_xlim([-5.5,5.5]); axs[0].set_ylim([-0.1,1.05]);
rwth_plots.stem(axs[0], n, s1);

# Frequency Domain
S1f = rwth_transforms.iz_Hf(f, H0, zp, zz, ord_p, ord_z, dB=False)

ax = axs[1]
ax.set_xlabel(r'$\rightarrow f$'); ax.set_ylabel(r'$\uparrow S_1(f)$')
rwth_plots.grid(ax); rwth_plots.axis(ax)
ax.set_xlim([-5.5,5.5]); ax.set_ylim([0.3, 3.1]);
ax.plot(f, S1f);
[5]:
[<matplotlib.lines.Line2D at 0x7f9062225310>]
../_images/examples_RWTH_Misc_12_1.svg

This code is licensed under the MIT license.