How can I get Magnitude and Phase in this code?
Show older comments
i want to get the Magnitude and Phase of G(jw) and i use freqz but The presence of T interferes with me.
my code :
import numpy as np
import matplotlib.pylab as plt
from scipy import signal
b=[1,-np.exp(-1)]
wn=np.linspace(0,10,100)
w,H = signal.freqz(b,worN=wn)
fig, ax = plt.subplots(1, 2, figsize=(6, 3),constrained_layout=True)
ax[0].plot(w,np.abs(H))
ax[0].set_title("Magnitude response");
ax[0].set_xlabel("w,frequency in radians")
ax[1].plot(w, np.angle(H), color='red')
ax[1].set_title("Phashe response")
ax[1].set_yticks([-np.pi, -np.pi/2, 0, np.pi/2, np.pi])
ax[1].set_yticklabels(['$-\pi$', '$-\pi/2$', '$0$', '$\pi/2$', '$\pi$'])
ax[1].set_xlabel("w,frequency in radians")
plt.show()
Answers (1)
That does not appear to be MATLAB syntax.
Symbolically, this is straightforward —
syms omega T real
G(omega) = 1 - exp(-(1+1j*omega)*T)
ReG = real(G)
ImG = imag(G)
Magnitude = abs(G)
phase = atan(ImG/ReG)
.
Categories
Find more on Call Python from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

