Rowan-Classes/6th-Semester-Spring-2024/DSP/Labs/Lab-04/lab4-1.py
2024-04-17 20:02:38 -04:00

40 lines
624 B
Python

import numpy as np
import matplotlib.pyplot as plt
N = 8
# Analytic DFT
'''
k = np.arange(N)
W_N = np.exp(-2j*np.pi*k/N)
plt.stem(k, -W_N)
plt.xlabel("$k$")
plt.ylabel("$W_N$")
'''
# N=8
n = np.arange(N)
x = (-1.0)**n
# 8-point DFT, N=8
DFT_8_point = np.fft.fft(x, 8)
plt.stem(abs(DFT_8_point))
plt.savefig("N8_point_dft.png")
plt.close()
# 9-point DFT, N=8
DFT_9_point = np.fft.fft(x, 9)
plt.stem(abs(DFT_9_point))
plt.savefig("Q9_point_dft.png")
plt.close()
# 9-point DFT, N=9
N = 9
n = np.arange(N)
x = (-1.0)**n
DFT_9_point = np.fft.fft(x, 9)
plt.stem(abs(DFT_9_point))
plt.savefig("N9_point_dft.png")
plt.show()