You are on page 1of 1

# -*- coding: utf-8 -*"""

Created on Fri Dec 12 21:28:50 2014


@author: Anish
"""
import os
os.system('cls')
import numpy as np
N = 500
nvec = np.linspace(0, N, num=N)
a = 0.5
x_n = (a)**nvec
plot(nvec,x_n,label='Function x[n]')
plt.xlabel('Time Index')
plt.ylabel('Function')
legend(bbox_to_anchor=(.5, .9), loc=1, borderaxespad=0.)
# DTFT
w = np.linspace(0,2*pi,num = 60)
x_w = (1-a**(N+1)*exp(-1j*w*(N+1)))/(1-a*exp(-1j*w))
figure(2)
plot(w,np.abs(x_w),'o',label='Amplitude Spectrum 1')
#plot(w,np.angle(x_w),label='Phase Spectrum')
plt.xlabel('Digital Frequency (radians)')
x_num = [0]*60
ix = 0;
for wx in w:
x_num[ix] = sum((a*exp(-1j*wx))**nvec)
ix = ix +1;
mag_x = np.abs(x_num)
plot(w,mag_x,label='Amplitude Spectrum 2')
legend(bbox_to_anchor=(.5, .9), loc=1, borderaxespad=0.)

You might also like