Kappa⁴ Archive

banned-users

Phi Kappa Chi ΦΚΧ <a:yeah:589703000977571860><a:ppHop:536353159615086612>

Jump to date
Pins
legorhin banned-users
"""
(a) Simulate the signal x(t) = u(t) - u(t - 2) in Matlab. 
(b)Compute and plot the magnitude and phase spectra of this signal in Matlab. 
(c) Calculate the low-pass filtered version of this signal xlpf(t) = x(t)h(t) with cut-off frequency at c = pi/3 using an ideal low-pass Filter (LPF) h(t). 
(d) Plot the magnitude and phase spectra of y(t) you calculated in (c) above. 
"""

#Discretize time t
t0=4000.
dt=0.1
t=np.arange(-t0,t0,dt)
x = np.zeros(t.shape)
x[t>=0] = 1
x[t>=2] = 0

# to replicate continuous time matlab functionality a method taken from
# https://stackoverflow.com/a/24077914
# is implemented

w = np.fft.fftfreq(x.size)*2*np.pi/dt
r = dt*np.exp(-1j*w*t0)/(np.sqrt(2*np.pi))

X = np.fft.fft(x)*r

#xlpf filter
h = np.sin(np.pi/3*t)/(np.pi*t)
h[t==0] = 1

y = np.convolve(x,h,'same')
Y = np.fft.fft(y)*r

wr = np.abs(w) <= np.pi

fig2 = plt.figure()
ax1 = fig2.add_subplot(221)
ax2 = fig2.add_subplot(222)
ax3 = fig2.add_subplot(223)
ax4 = fig2.add_subplot(224)

ax1.plot(t[np.abs(t)<4],x[np.abs(t)<4])
ax1.set_title("x(t)")

ax2.plot(w[wr],X[wr].real)
ax2.plot(w[wr],X[wr].imag)
ax2.set_title("X(jω)")

ax3.plot(t[np.abs(t)<4],y[np.abs(t)<4])
ax3.set_title("y(t)")

ax4.plot(w[wr],Y[wr].real)
ax4.plot(w[wr],Y[wr].imag)
ax4.set_title("Y(jω)")

fig2.suptitle("LPF Demonstration") 
plt.show()
here you go pika

This archive is read-only — captured July 2020

Channels:
Density:

Jump to date