hwsolB29

# hwsolB29 - % (iv) V = [cos(2*pi*f0_hat*n)...

This preview shows page 1. Sign up to view the full content.

Sheet1 Page 1 HW 29 Solution ______________ The problem parameters (frequency f0, amplitude A and phase phi) are randomly generated in MATLAB: n = (0:19).' f0 = 0.15 + 0.25*rand(1) A = 10*rand(1) phi = pi*rand(1) x = A*cos(2*pi*f0*n + phi) + 0.3*A*randn(size(n)) % (i), (ii) f1 = (0 : 1/20 : 1-(1/20)).' f2 = (0 : 1/512 : 1-(1/512)).' X1 = abs(fft(x)) X2 = abs(fft(x,512)) clf stem(f1, X1) hold plot(f2, X2) % (iii) i = min(find(X2 == max(X2))) f0_hat = (i-1)/512 f0_error = abs(f0 - f0_hat)
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: % (iv) V = [cos(2*pi*f0_hat*n) -sin(2*pi*f0_hat*n)] c = (V'*V)\(V'*x) z = [1 j]*c A_hat = abs(z) phi_hat = angle(z) A_error = abs((A - A_hat)/A) phi_error = abs((phi - phi_hat)/(2*pi)) Since f0 is in the range [0,1) and phi is in the range [0,2*pi), it is appropriate to normalize the errors by 1 and 2*pi (resp.). In the case of A, which is a random positive number, it is better to use the relative error (i.e, normalize by the true value of A)....
View Full Document

## This note was uploaded on 03/21/2010 for the course ENEE 241 taught by Professor Staff during the Spring '08 term at Maryland.

Ask a homework question - tutors are online