18-290 Signals and Systems Profs. Byron Yu and Pulkit Grover Fall 2018 Homework 1 This homework is due in class on Thursday, September 6, 9:00am. Instructions Solve all non-matlab problems using only paper and pencil, without resorting to MATLAB or a computer. Please show all necessary steps to get the final answer. For MATLAB problems, include all code written to generate solutions. Ask any questions using the Q&A Board on Piazza, rather than emailing the course staff. Remember to label your axes and title your plots. Please submit Part One and Part Two on separate papers. Make sure each part is labeled with your name and AndrewID and separately stapled. Part One 1. (8 points) Consider the DT signal given by the algorithm: x[0] = 1 x[1] = 2 (a) Plot the signal x[n] for 0 n 11. x[n] = x[n 1] x[n 2] (b) Determine if the signal is periodic, and if so find its fundamental period. 2. (8 points) Consider the CT signal given by the fomula: (a) Plot the signal x(t) for 3 t 3. x(t) = 2 cos 2 (2πt/3) (b) Determine if the signal is periodic, and if so find its fundamental period.
2 Homework 1 3. (12 points) Determine if each of the following signals is periodic and, if so, find its fundamental period: (a) x(t) = sin 2 (2πt) (b) x(t) = e t cos(2πt) (c) x(t) = cos( 2π 3 t) + sin( π 2 t) (d) x(t) = cos(2πt) + cos( 2πt) 4. (10 points) (a) Consider the following DT signal: x[n] = {( 1 2) n 0 n 20 0 otherwise Determine the total energy and average power of x[n]. (b) Consider the following CT signal: 3t 0 t 5 x(t) = 15 5 < t 10 0 otherwise Determine the total energy and average power of x(t). 5. (12 points) Decompose the following signals into their odd and even components. Simplify your answer to the simplest expression: (a) x(t) = 10t 5 + 4t 4 t 3 t 2 1 (b) x(t) = 1 + t cos(t) + t 3 sin 2 (t) + t 4 cos(2t) sin(2t) (c) x[n] = cos(n) + sin(2n) + ( 1) n + ( 1) n sin( π 7 n) (d) x(t) = sin(3t) sin(2t) sin(t) (Hint: sin( x) = sin(x))
Homework 1 3 Part Two (Separate Paper) 6. (10 points) A pulse x(t) is defined by: x(t) = (a) Determine the total energy of x(t). { A cos(ωt) sin(ωt) 0 t T 0 otherwise (b) A differentiator is applied to x(t), defined by: y(t) = d dt x(t) Determine the resulting output y(t) of the differentiator. energy of y(t). Determine the total 7. (10 points) MATLAB Commands Please download MATLAB from the following website, which also provides instructions on how to do so. ECE students can choose to install the standalone edition in order to use MATLAB off campus. http://www.cmu.edu/computing/software/all/matlab/index.html When you start MATLAB, there are two windows to note: a workspace, which contains the current variables; a command window, which allows for the input of commands. When MATLAB is first started, both should be empty except for the command window prompt. >> You can create variables like in other programming languages: >> a = 2 You will note that the variable a now appears in the workspace. Once you have created variables, they will be saved in the workspace and you can use them in your new commands without having to define them again. Square brackets are used to create matrices. Columns are separated by spaces (or commas), and rows are separated by semicolons. Try the following commands in your MATLAB command window. To get information about any command, you can type help <name of the command>. >> b = [1 3 5] >> c = [1; 3; 4] >> d = [1 2 3; 5 6 7]
4 Homework 1 Try the following MATLAB operators: >> b*c >> b+b >> b+c >> d*c Note that if the dimensions do not agree, you cannot use certain operators. MATLAB has a large library of commands that help to manipulate your matrices. Try the following commands, and briefly explain what each of the commands do. Note that MATLAB indexing starts at 1, rather than 0 in many other programming languages. >> a = zeros (3, 4) >> b = ones (2, 5) >> c = eye (4) >> d = size (a) >> abs ([ -5, 3]) >> ceil (3.4) >> help floor >> e = [2:3:10] >> f = e >> g = e (2) >> h = cos (pi /2) >> k = exp (1.0) >> ex1 = linspace (1, 5, 4) >> ex1 = [ ex1 ; ex1 *2] >> n = ex1 (1, 2) >> p = ex1 (1, :) >> m = ex1 (1, 2: end ) >> q = [p m] >> cmplx = 3-2 i >> real ( cmplx ) >> imag ( cmplx ) >> abs ( cmplx ) >> angle ( cmplx ) >> 5^2 >> 3 == 3 >> 3 == 2 >> 3 ~= 1 >> whos >> clear a b
Homework 1 5 There are many other built-in functions in MATLAB. MATLAB has excellent documentation, so there are plenty of online resources for helping you find the functions you need. 8. (10 points) MATLAB Plots Now we will get to one of the powerful tools of MATLAB: plots. In order to use the plot function, you need a vector of values for the x-axis and one for the y-axis. You can use plot(x, y) to create a continuous line plot. >> x = [ -2:2] >> y = [1 4 4 7 3] >> plot (x, y) You can instead use stem(x, y) to plot discrete points in a stem plot. >> stem (x, y) Now, use these tools to make the following plots. Make sure to title your plots and label the axes. In order to do so, try help xlabel, help ylabel, and help title for instructions. (a) Odd component of y as both a continuous line plot and a discrete stem plot. (b) Even component of y as both a continuous line plot and a discrete stem plot. 9. (10 points) Matlab Functions A square wave, which is also called a pulse wave, is a periodic function that alternates between two values. The duty cycle is the percent of the period in which the signal is at its maximum value. The figure below shows a 1 Hz square wave with equal duration at the maximum value +1 and minimum value 0. So, its duty cycle is 50%. Now use the functions you examined in question 8 and write your own square wave generator. The specifics are:
6 Homework 1 The output variable mywave should be a square wave that has a fixed frequency of 1 Hz and alternates between 1 and 0. The signal lasts for 3 seconds. The input variable dutycycle ranges from 0 to 100 and it controls the duration of the maximum value, i.e. the fraction of time for which the signal is at its maximum value, expressed as a percentage. To define a function in Matlab, click on the yellow plus sign on the top left corner of the Matlab interface and type in the code below. function mywave = WaveGenerator ( dutycycle ) % your code here end Then save and name the.m file the same name as the function name under your current working directory. That is, you should save your script as WaveGenerator.m. In your submission, provide the code for this function. A hint for this problem is to use zeros and ones command. First, lets look at the first 0.5 seconds with a 0.01 second interval. That is, lets look at the value of the square wave plotted above at time points 0.01, 0.02,..., 0.5. The amplitude at these time points are always 1. So, to get the first half period of a square wave, use the command as follows: posvalue = ones (1,50); posvalue is a 1 50 vector that represents the first 0.5 seconds of the wave. Similarly, we can use zeros to generate the other half period of the wave. Then, concatenate two parts together to get a 1 100 vector for the whole period. Last, repmat function (for more information, use help repmat) allows you to repeat one period multiple times. In order to generate signals with different duty cycles, you only need to change the number of 1s and 0s. 10. (9 points) Put it all together Now, it is time to use your wavegenerator and the functions you learned from question 9 and plot a pulse wave function with 50% duty cycle and 85% duty cycle. To give you an example, the code below plots the 20% duty cycle square wave. t = 0.01:0.01:3; y = WaveGenerator (20); plot (t,y) title ( 20% duty cycle square wave ) xlabel ( Time (s) ) ylabel ( Amplitude )
Homework 1 7 In your submission, you only need to show the two plots for 50% and 85% duty cycle. If you can generate plots that look like the figure above, you have already finished your first 18290 homework! Yeah! But if you are a perfectionist, you can try command axis or adjust LineWidth for plot to make the plot prettier. 11. (1 point) How many hours did this homework take?