Starting from:
$35

$29

Computer Assignment 1 Solution


    1) In this part, you will write a MATLAB program to determine the parameters of a given sampled sinusoidal signal.

The le \data.mat" contains a two-dimensional array X. The ith row of X contains a uniformly sampled sinusoid xi[n] = xi(nTs); n = 0; 1; 2; : : : ; N, where

xi(t) = Ci + Ai cos (2 fit +  i):

The sampling rate is fs = 1=Ts = 1000 Hz. The parameters of the ith signal are the d.c.
value Ci, the amplitude Ai, the frequency fi (in Hz), and the phase    i (in degrees).

You will select and use three of the given 10 signals according to your student ID. Select the three signals which are indexed by the last three digits of your ID. If any of these digits is 0, use 10 instead. For example, if your ID is 21098760, you need to use x7(t); x6(t), and x10(t).

    (a) Plot the three signals separately. The sampling rate is su ciently high, so use the plot command instead of stem in plotting. The horizontal axis must be t (time) in seconds. In each plot, indicate which signal is plotted in the plot title.

    (b) For each of the three signals, estimate the values of the parameters Ci; Ai; fi (in Hz), and i (in degrees) by hand from the plots you obtained in part (a). Brie y explain how you estimate each of the four parameters from the plot of a sinusoidal signal.

    (c) Now estimate the parameter values of the three signals automatically in MAT-LAB. That is, write a MATLAB function whose inputs are the sampling rate (in Hz) and a sampled sinusoidal signal x (such as a row of X) and outputs are the estimates of C; A; f (in Hz), and (in degrees). Call the function \[C,A,f,phi] = parameters_of_sin(fs,x)." Assume that x contains at least two periods and the rst sample of x corresponds to t = 0. Explain how you calculate the parameter values. You are not allowed to use advanced methods such as the Fourier transform (e.g., fft command) or curve tting. You must not use

any built-in function or any external toolbox for peak detection.

Write another MATLAB program that obtains the parameter values of the three signal by calling the function parameters_of_sin and displays the three signals in the Command Window in the form of \x_1(t) = -1.30 +2.61 cos(87.01 t +0.80)". The d.c. value, amplitude, frequency, and phase should contain exactly two digits to the right of the decimal point. The phase value must be in radians. There should be \+" or \{" signs to the left of the d.c. value and the phase according to their signs.



1

Hint: To estimate C and A, you may simply use the minimum and maximum values of x since it contains at least one period. The f and may be estimated from the rst peak (i.e., the peak having the smallest t value) and the rst negative peak of x. These peaks correspond to the maximum and minimum values of the sinusoid in the rst period. However, nding these peaks may not be trivial because in sampling the sinusoid, there may not be a sample exactly at the maximum and minimum value of the sinusoid (e.g., see Fig. 4-3 in the textbook), and this behavior may not be the same in all the periods. Therefore, the peak values in the sampled signal may change slightly from period to period, and the rst exact maximum or minimum value of x may reside in another period, which is not desired. To overcome this problem, instead of nding the rst maximum value of x, you may nd the rst value that exceeds C + A A=1000, a value slightly lower than the maximum value of the continuous-time signal. Similarly, for the rst negative peak, you may nd the rst value that is smaller than C A + A=1000, a value slightly greater than the actual minimum value.

    (d) Compare the estimated values of the parameters you obtained in parts (b) and (c). Are they exactly the same? If not, what are the reasons? Explain and discuss.

Note: In this assignment, you are not allowed to use symbolic operations in MATLAB. To modify the styles of the plots, to add labels, and to scale the plots, use only MATLAB commands; do not use the GUI of the gure windows. When your program is executed, the gures must appear exactly the same as you provide in your solution.

Submit the results of your own work in the form of a well-documented report on Moo-dle. Borrowing full or partial code from your peers or elsewhere is not allowed and will be punished. Please include all evidence (plots, screen dumps, MATLAB codes, MATLAB command window print-outs, etc.) as needed in your report. Append your MATLAB code at the end of your assignment, do not upload it separately. The axes of all plots should be scaled and labeled. Typing your report instead of handwriting some parts will be better. Please do not upload any photos/images of your report. Your complete report should be uploaded on Moodle as a single good-quality pdf le by the given deadline. Please try to upload several hours before the deadline to avoid last minute problems that may cause you to miss the deadline. Please DO NOT submit any hardcopies or les by e-mail or on memory stick/CD.















2

More products