Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(f) Suppose you have written code to calculate the Fourier transform of a signal

ID: 3717917 • Letter: #

Question

(f) Suppose you have written code to calculate the Fourier transform of a signal. You have an array freq of 128 frequencies and an array FT of the corresponding Fourier components. You want to create a three-column table that lists, on each line, the frequency, the real part of the corresponding Fourier component, and the imaginary part of that component. The rows in the table should give the frequency with one digit after the decimal point, and they should give the Fourier components in scientific notation with three digits after the decimal point. The decimal points should line up. (Assume the frequencies are positive and less than 10000 Hz). Write a two-line (or three-line) Python code for writing the table to standard output.

Explanation / Answer

def dftmatrix(Nfft=128,N=None): 'construct DFT matrix' k= np.arange(Nfft) if N is None: N = Nfft n = arange(N) U = matrix(exp(1j* 2*pi/Nfft *k*n[:,None])) # use numpy broadcasting to create matrix return U/sqrt(Nfft) Nfft=128 v = ones((128,1)) U = dftmatrix(Nfft=Nfft,N=128)