<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Complex Numbers
Q1. Return the angle of a in radian.
Step1:  Q2. Return the real part and imaginary part of a.
Step2:  Q3. Replace the real part of a with 9, the imaginary part with [5, 7, 9].
Step3:  Q4. Return the complex conjugate of a.
Step4:  Discrete Fourier Transform
Q5. Compuete the one-dimensional DFT of a.
Step5:  Q6. Compute the one-dimensional inverse DFT of the output in the above question.
Step6:  Q7. Compute the one-dimensional discrete Fourier Transform for real input a.
Step7:  Q8. Compute the one-dimensional inverse DFT of the output in the above question.
Step8:  Q9. Return the DFT sample frequencies of a.
Step9:  Window Functions
<ASSISTANT_TASK:>
Python Code:
a = 1+1j
output = np.angle(a, deg=False)
print(output)
Explanation: Complex Numbers
Q1. Return the angle of a in radian.
End of explanation
a = np.array([1+2j, 3+4j, 5+6j])
real = a.real
imag = a.imag
print("real part=", real)
print("imaginary part=", imag)
Explanation: Q2. Return the real part and imaginary part of a.
End of explanation
a = np.array([1+2j, 3+4j, 5+6j])
a.real = 9
a.imag = [5, 7, 9]
print(a)
Explanation: Q3. Replace the real part of a with 9, the imaginary part with [5, 7, 9].
End of explanation
a = 1+2j
output = np.conjugate(a)
print(output)
Explanation: Q4. Return the complex conjugate of a.
End of explanation
a = np.exp(2j * np.pi * np.arange(8))
output = np.fft.fft(a)
print(output)
Explanation: Discrete Fourier Transform
Q5. Compuete the one-dimensional DFT of a.
End of explanation
print("a=", a)
inversed = np.fft.ifft(output)
print("inversed=", a)
Explanation: Q6. Compute the one-dimensional inverse DFT of the output in the above question.
End of explanation
a = [0, 1, 0, 0]
output = np.fft.rfft(a)
print(output)
assert output.size==len(a)//2+1 if len(a)%2==0 else (len(a)+1)//2
# cf.
output2 = np.fft.fft(a)
print(output2)
Explanation: Q7. Compute the one-dimensional discrete Fourier Transform for real input a.
End of explanation
inversed = np.fft.ifft(output)
print("inversed=", a)
Explanation: Q8. Compute the one-dimensional inverse DFT of the output in the above question.
End of explanation
signal = np.array([-2, 8, 6, 4, 1, 0, 3, 5], dtype=np.float32)
fourier = np.fft.fft(signal)
n = signal.size
freq = np.fft.fftfreq(n, d=1)
print(freq)
Explanation: Q9. Return the DFT sample frequencies of a.
End of explanation
fig = plt.figure(figsize=(19, 10))
# Hamming window
window = np.hamming(51)
plt.plot(np.bartlett(51), label="Bartlett window")
plt.plot(np.blackman(51), label="Blackman window")
plt.plot(np.hamming(51), label="Hamming window")
plt.plot(np.hanning(51), label="Hanning window")
plt.plot(np.kaiser(51, 14), label="Kaiser window")
plt.xlabel("sample")
plt.ylabel("amplitude")
plt.legend()
plt.grid()
plt.show()
Explanation: Window Functions
End of explanation
<END_TASK>