Miscellaneous
-
:math:`z-Transform <#$z$-Transform>`__
Transforms
Following transforms are defined in rwth_nb.misc.transforms:
:math:`z-Transform <#$z$-Transform>`__
Note that plotting basics are described inRWTH Plots.
Fourier Transform
dft(s, fs, NFFT)
[1]:
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);
Inverse Fourier transform
idft(S, Ntime, NFF)
[2]:
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);
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)
[3]:
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);
/usr/local/lib/python3.8/site-packages/matplotlib/axes/_base.py:2503: UserWarning: Warning: converting a masked element to nan.
xys = np.asarray(xys)
\(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)
[4]:
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);
This code is licensed under the MIT license.