LAB ASSIGNMENT 4 (due 02/26/14) ___________________________ DATA: The vector chirp04 contains a sinusoid of unit amplitude generated by chirp04 = cos(2*pi*v) ; where the angle 2*pi*v is a NONLINEAR function of the sample index. As a result, the signal frequency varies with time. The command used to generate v is of the form v = n./(a+b*(n/N)) + w ; where N = length of v and chirp04 n = 1:N a and b are constants w = a small amount of random "phase noise" Note that the angle increment (from sample to sample) varies in value from about 2*pi/a initially (time = 1) to about 2*pi/(a+b) finally (time = N). OBJECTIVE: Estimate the coefficients a and b. Based on those estimates, reconstruct chirp04. STEPS: 1. The vector chirp04 is encoded in the MATLAB data file chirp04.mat. Save that file in your working directory and load the vector using load chirp04 Determine the length N of chirp04. 2. Listen to chirp04 using SOUNDSC and note the varying frequency. Also, plot different 100-sample segments of chirp04 to get a visual feel for the variation in frequency. Do not submit any code or plots for this part. 3. Delay chirp04 by one sample by removing its last sample and introducing a dummy sample of value 0 at time 1: delchirp04 = [ 0 chirp04(1:N-1) ] ; 4. A change of algebraic sign between *consecutive* samples of chirp04 will show up as a difference in algebraic sign between *corresponding* samples of chirp04 and delchirp04. Using the fact that x and y have different sign if and only if x*y < 0 , write a command that produces a logical vector of size N, containing 1's in positions where those sign differences occur; and 0's elsewhere. Call this vector signchanges 5. Use the CUMSUM function to obtain the cumulative sum of signchanges, also a vector of size N. Call it no_halfcycles This name is not arbitrary. The algebraic sign of a sinusoid changes twice in each cycle. Thus the total (cumulative) number of sign changes indicates how many half-cycles the sinusoid has been through - assuming of course that samples are taken at least in each half-cycle. Also: plot no_halfcycles against n. 6. Since the ith entry of the vector v = n./(a+b*(n/N)) + w is the actual number of cycles the sinusoid has accumulated up to time i, it follows that no_halfcycles/2 closely approximates v; and thus Y = 2*n/.(no_halfcycles) also closely approximates the straight line a + b*(n/N) 7. The function POLYFIT(X,Y,M) determines the best-fitting polynomial (in the least-squares sense) of degree M to the data set (X,Y) (i.e., the points with respective cordinates in vectors X and Y). It returns the coefficients of that polynomial ***in descending order***. Read the documentation on POLYFIT. Use the second halves of the vectors Y and X = n/N to estimate a and b. (To see why using the entire vectors X and Y may lead to errors, plot Y against X.) 8. Using your esimates of a and b, compute my_v = n./(a+b*(n/N)) ; and my_chirp = cos(2*pi*my_v) ; If your estimates are good, my_chirp should sound the same as chirp_04. Save my_chirp in LABHW_04.mat. This is done using the command save LABHW_04 my_chirp _____________________________________________________________________________________ Submit a zip/rar package containing the following two files (use exact file names as shown): lastname_labhw_04.m The m-file should contain the MATLAB code for steps 1 and 3-8 above. About 15 lines of code, some of which are already provided above, should suffice. You should also include the values obtained for a and b. Insert at least one comment, at the most important line in your code; and additional comments that might help the grader better understand your solution and give you partial credit in case of errors. Please put your name and student ID on the first line. lastname_labhw_04.pdf Plot of no_halfcycles against n (step 5 above). lastname_labhw_04.mat Saved version of my_chirp (step 8 above). The zip/rar package should be named as lastname_labhw_04.zip/rar, and should be uploaded from the upload link on the course lab web page , or if not possible, emailed to enee222S2013@gmail.com.