I am trying to calculate the magnitude and angle of the DFT of a rectangular window. The code below gets the magnitude I expect, but the phase looks wrong. Can anyone help me figure out what I'm doing wrong? Thanks!
This is what I get:
This is what the book I'm reading (by Richard Lyons) has:
fs = 256 # sample freq - number of samples per second
k = 11
window = np.array([0] * 64 + [1] * k + [0] * 64)
freq = fft(window)
plt.stem(fftfreq(len(freq), 1/fs), np.abs(freq), 'r')
plt.show()
plt.stem(fftfreq(len(freq), 1/fs), np.angle(freq), 'r')
plt.xlim([-30, 30])
plt.show()