1EECS3451: Lab 2 Instructor: Gene Cheung Instructions: Two points per problem. Submit a report for the problems below, as well as accompanied readable MATLAB scripts in .m file format. Comment code for partial credits. PROBLEM 1 Consider a continuous-time real-valued rectangular wave x(t) defined as follows: x(t) = 1, for 2k ( pi ωo ) ≤ t < (2k + 1) ( pi ωo ) , k ∈ Z −1, for (2k + 1) ( pi ωo ) ≤ t < (2k + 2) ( pi ωo ) , k ∈ Z (1) Assuming a sampling frequency of fs = SECRET NUMBER 2 Hz, compute a sampled version of x(t), i.e., x(nTs), n ∈ Z, for 0 ≤ t ≤ 12, using the following MATLAB functions, where ωo is pi/2: (a) Implement (1) directly using MATLAB function floor and assign to vector x1. (Hint: notice that x(t) = 1 if t is inside a region delimited by an even multiple of pi/ωo at the bottom, and odd multiple of pi/ωo at the top. Try using floor on different values of t in a loop toegether with if statements. ) (b) Implement (1) using a combination of MATLAB functions sin and sign, and assign to vector x2. (c) Implement (1) using MATLAB function square in the Signal Processing toolbox1, and assign to vector x3. Plot the three sampled versions, x1, x2, x3, using the following MATLAB code: subplot(3,1,1); plot(t, x1, ’k+-’); title(’wave 1’); xlabel(’time (s)’); ylabel(’amplitude’); subplot(3,1,2); plot(t, x2, ’bo-’); title(’wave 2’); xlabel(’time (s)’); ylabel(’amplitude’); subplot(3,1,3); plot(t, x3, ’rx-’); title(’wave 3’); xlabel(’time (s)’); ylabel(’amplitude’); 1https://www.mathworks.com/help/signal/ref/square.html 2PROBLEM 2 Derive the coefficients cm of the Fourier Series for continuous-time periodic signal x(t) in problem 1. (“Derive” here means writing equations on paper to arrive at a simplified expression for cm. It does NOT mean computing the integral in the definition of Fourier coefficient directly using MATLAB!) Approximate x(t) using Fourier Series of finite terms, i.e., (a) Only Fourier coefficients cm’s, where |m| ≤ 10. (b) Only Fourier coefficients cm’s, where |m| ≤ 50. Assuming a sampling frequency of fs = 100Hz, compute sampled versions xApprox1 and xApprox2 of the two approximations, x˜1(t) and x˜2(t), for 0 ≤ t ≤ 12. Plot xApprox1 and xApprox2 using the following MATLAB code: subplot(2,1,1); plot(t, real(xApprox1), ’b-’); title(’approx wave 1’); xlabel(’time (s)’); ylabel(’amplitude’); subplot(2,1,2); plot(t, real(xApprox2), ’r-’); title(’approx wave 2’); xlabel(’time (s)’); ylabel(’amplitude’); Describe Gibbs phenomenon in your approximations. (Hint: derivations of cm for m = 0 and m 6= 0 are slightly different.) PROBLEM 3 Consider a continuous-time pure sinusoid x(t) defined as follows: x(t) = sin(ωot) (2) Assuming a sampling frequency of fs = 100Hz, compute a sampled version of x(t), i.e., x(nTs), n ∈ Z, for 0 ≤ t ≤ 12, where ωo = pi/2. (a) Construct the baseline sampled version x1= x(nTs). (b) Suppose sampling frequency is now f2 = 2Hz. Construct the sampled version dx2= x(nT2) of x(t). Interpolate back to frequency fs using the sinc ideal interpolator: x(t) = ∞∑ n=−∞ x(nT ) sin[(pi(t− nT )/T ] pi(t− nT )/T (3) resulting in x2. 3(c) Suppose sampling frequency is now f3 = 0.333Hz. Construct the sampled version dx3= x(nT3) of x(t). Interpolate back to frequency fs using the sinc ideal interpolator (3) again, resulting in x3. Plot x1, dx2, x2, dx3 and x3 using the following MATLAB code: subplot(3,1,1); plot(t, x1, ’k-’); title(’wave 1’); xlabel(’time (s)’); ylabel(’amplitude’); subplot(3,1,2); stem(t2, dx2, ’bo-’); hold on; plot(t, x2, ’b-’); title(’wave 2’); xlabel(’time (s)’); ylabel(’amplitude’); subplot(3,1,3); stem(t3, dx3, ’rx-’); hold on; plot(t, x3, ’r-’); title(’wave 3’); xlabel(’time (s)’); ylabel(’amplitude’); PROBLEM 4 (a) What are the Nyquist frequency ranges (NFR) for x2 and x3 above? (b) What are the fundamental frequencies for x2 and x3 above? Which one (if any) is an aliased frequency?
欢迎咨询51作业君