Commit 9e49e834 authored by Hafiz Emin Kosar's avatar Hafiz Emin Kosar
Browse files

- added functions for z-transform

parent add41b08
Pipeline #235150 passed with stages
in 23 minutes and 10 seconds
......@@ -318,7 +318,7 @@ def ient_plot_zroc(ax, roc, rmax=12):
xs[1, :] = xs[1, ::-1]
ys[1, :] = ys[1, ::-1]
ax.fill(np.ravel(xs), np.ravel(ys), facecolor="none", hatch="\\", edgecolor="rwth-50", linestyle='--')
return ax.fill(np.ravel(xs), np.ravel(ys), facecolor="none", hatch="\\", edgecolor="rwth-50", linestyle='--')[0]
def ient_annotate_order(ax, p, ord):
......
import numpy as np
from scipy.signal import residuez
if __package__ is None or __package__ == '':
from ient_signals import eps, findIndOfLeastDiff
else:
......@@ -180,6 +181,82 @@ def ient_ilaplace_Hf(f=np.linspace(-6, 6, num=1024), H0=1, pp=np.array([]), pz=n
return np.abs(numerator / denominator)
def ient_iz_ht(n=np.linspace(-6, 6, num=13), H0=1, pp=np.array([]), pz=np.array([]), ord_p=np.array([]),
ord_z=np.array([]), roc=[-12, 12]):
"""
Calculate inverse z-Transform from z-domain to n-domain
TODO - calculate according ord_p and ord_z, currently not used
"""
# setting up parameters
poles = np.array(pp)
zeroes = np.array(pz)
#poles_order = np.array(ord_p)
#zeroes_order = np.array(ord_z)
nominator = H0 * np.poly(zeroes)
denominator = np.poly(poles)
h = np.zeros(n.shape)
if isinstance(denominator, float):
h[np.where(n == 0)] = H0
return h
p = len(nominator) if not isinstance(nominator, float) else 1
input_nominator = np.zeros(p)
input_nominator[-p:] = nominator
input_nominator = input_nominator[::-1]
input_denominator = denominator
r, p, k = residuez(input_nominator, input_denominator)
#p[::-1].sort()
causal = p.real <= roc[0]
row = 0
for ind, b in enumerate(p):
amplitude = r[row]
row = row + 1
tmp = amplitude * np.power(b, n)
if causal[ind]:
tmp[np.where(n < 0)] = 0
else:
tmp[np.where(n >= 0)] = 0
tmp = -tmp
h = np.add(h, tmp)
return h
def ient_iz_Hf(f=np.linspace(-6, 6, num=1024), H0=1, pp=np.array([]), pz=np.array([]), ord_p=np.array([]),
ord_z=np.array([]), dB=False):
"""
Calculate inverse z-Transform from z-domain to f-domain
"""
numerator = H0 * np.ones(f.shape)
for ind, ppz in enumerate(pz):
for _ in range(1, ord_z[ind] + 1):
numerator = numerator * (np.exp(1j * 2 * np.pi * f) - ppz)
if np.abs(np.imag(ppz)):
numerator = numerator * (np.exp(1j * 2 * np.pi * f) - np.conj(ppz))
denominator = np.ones(f.shape)
for ind, ppp in enumerate(pp):
for _ in range(1, ord_p[ind] + 1):
denominator = denominator * (np.exp(1j * 2 * np.pi * f) - ppp)
if np.abs(np.imag(ppp)):
denominator = denominator * (np.exp(1j * 2 * np.pi * f) - np.conj(ppp))
if dB:
return 20 * np.log10(np.maximum(eps, np.abs(numerator / denominator)))
else:
return np.abs(numerator / denominator), numerator, denominator
def ient_ideal_sample(x, y, T):
def x_mirrored_around_zero(maxval, inc=1):
x = np.arange(inc, maxval + inc, inc)
......
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