%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
x=np.array([0.,0,0,2,4,6,4,2,0,0,0])
plt.stem(x)
<Container object of 3 artists>
y=x*0
y[0]=1/3*(x[0]+x[1]+x[2])
y[1]=1/3*(x[1]+x[2]+x[3])
for ii in range(5):
print(ii)
0 1 2 3 4
for ii in range(len(x)-2):
y[ii]=1/3*(x[ii]+x[ii+1]+x[ii+2])
print(y[ii])
0.0 0.666666666667 2.0 4.0 4.66666666667 4.0 2.0 0.666666666667 0.0
plt.stem(x,'r')
plt.stem(y,'g')
<Container object of 3 artists>
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
n=np.arange(100)
w_hat=2.5
x_n=np.exp(1.0j*w_hat*n)
x_n_1=np.exp(1j*w_hat*(n-1))
x_n_2=np.exp(1j*w_hat*(n-2))
y=(x_n+x_n_1+x_n_2)/3
plt.figure(figsize=(15,5), dpi=300)
plt.plot(np.real(x_n),'r*-')
plt.plot(np.real(x_n_1),'go-')
plt.plot(np.real(x_n_2),'b*-')
params = {'backend': 'ps',
'xtick.labelsize': 24,
'ytick.labelsize': 24,}
plt.rcParams.update(params)
plt.figure(figsize=(15,5), dpi=300)
plt.plot(np.real(x_n_2),'r*-')
plt.plot(np.real(y),'b*-')
print("Amplitude: %f" % np.abs(y)[0])
params = {'backend': 'ps',
'xtick.labelsize': 24,
'ytick.labelsize': 24,}
plt.rcParams.update(params)
Amplitude: 0.200762
ii=0
for w_hat in np.arange(-np.pi*4,np.pi*4,0.1):
x_n=np.exp(1j*w_hat*n)
x_n_1=np.exp(1j*w_hat*(n-1))
x_n_2=np.exp(1j*w_hat*(n-2))
y=(x_n*1/3+x_n_1*1/3+x_n_2*1/3)
#y=(x_n-x_n_1)
if ii==0:
w_hat_all=np.array(w_hat)
y_abs=np.array(np.abs(y)[0])
else:
w_hat_all=np.append(w_hat_all,w_hat)
y_abs=np.append(y_abs,np.abs(y)[0])
ii+=1
plt.plot(w_hat_all,y_abs)
[<matplotlib.lines.Line2D at 0x2411fae0e80>]