Laboratory 1 Discrete and Continuous-Time Signals
Laboratory 1 Discrete and Continuous-Time Signals
Laboratory 1 Discrete and Continuous-Time Signals
This lab was adapted from Lab1 of ECE438 Digital Signal Processing with Applications course at Purdue University, USA.
2 MATLAB REVIEW
Practically all lab tasks in the EE325 lab will be performed using Matlab. Matlab (MATrix LABoratory) is a technical computing environment for numerical analysis, matrix computation, signal processing, and graphics. In this section, we will review some of its basic functions.
computes the matrix product of a and b to generate a scalar value for c of 14 = 1 * 1 + 2 * 2 + 3 * 3. Often, you may want to apply an operation to each element of a vector. For example, you may want to square each value of a. In this case, you may use the following command. c = a.*a The dot before the * tells Matlab that the multiplication should be applied to each corresponding element of a. Therefore the .* operation is not a matrix operation. The dot convention works with many other Matlab commands such as divide ./, and power .^. An error results if you try to perform element-wise operations on matrices that arent the same size. Note also that while the operation a. performs a transpose on the matrix a, the operation a performs a conjugate transpose on a (transposes the matrix and conjugates each number in the matrix).
1 2
INLAB REPORT: Hand in your calculations of these two integrals. Show all work. (This can be hand written)
plot(n2,w) As you can see, it is important to have many points to make the signal appear smooth. But how many points are enough for numerical calculations? In the following sections we will examine the effect of the sampling interval on the accuracy of computations.
INLAB REPORT: Submit a soft copy of the plots of the discrete-time function and two continuous-time functions. Label them with the title command, and include your name. Comment on the accuracy of each of the continuous time plots.
To see the effects of using a different number of points to represent a continuous-time signal, write a Matlab function for numerically computing the integral of the function sin2(5t) over the interval [0, 2]. The syntax of the function should be I=integ1(N) where I is the result and N is the number of rectangles used to approximate the integral. This function should use the sum command and it should not contain any for loops! This lab was adapted from Lab1 of ECE438 Digital Signal Processing with Applications course at Purdue University, USA.
Note: Since Matlab is an interpreted language, for loops are relatively slow. Therefore, we will avoid using loops whenever possible. Next write an m-file script that evaluates I(N) for 1 N 100, stores the result in a vector and plots the resulting vector as a function of N. This m-file script may contain for loops. Repeat this procedure for a second function J=integ2(N) which numerically computes the integral of exp(t) on the interval [0, 1]. INLAB REPORT: Submit plots of I(N) and J(N) versus N. Use the subplot command to put both plots on a single figure. Also submit your Matlab code for each function. Compare your results to the analytical solutions from Section 3.1. Explain why I(5) = I(10) = 0.
signal1(t) where t is a vector containing values of time. Note that this Matlab function is valid for any real-valued time, t, so y = signal1(t) yields samples of a continuous-time function. First plot the function using the plot command. Experiment with different values for the sampling period and the starting and ending times, and choose values that yield an accurate representation of the signal. Be sure to show the corresponding times in your plot using a command similar to plot(t,y). Next write individual Matlab functions to compute the minimum, maximum, and approximate energy of this particular signal. Each of these functions should just accept an input vector of times, t, and should call signal1(t) within the body of the function. You may use the built-in Matlab functions min and max. Again, you will need to experiment with the sampling period, and the starting and ending times so that your computations of the min, max, and energy are accurate. Remember the definition of the energy is = | 1 |
INLAB REPORT: Submit a plot of the function, and the computed values of the min, max, and energy. Explain your choice of the sampling period, and the starting and ending times. Also, submit the code for your energy function.
5 SPECIAL FUNCTIONS
Plot the following two continuous-time functions over the specified intervals. Write separate script files if you prefer. Use the subplot command to put both plots in a single figure, and be sure to label the time axes. for [10 , 10 ] for [2, 2]
Hint: The function rect(t) may be computed in Matlab by using a Boolean expression. For example, if t=-10:0.1:10, then y = rect(t) may be computed using the Matlab command y = (abs(t)<=0.5) Write an .m-script file to stem the following discrete-time function for a = 0.8, a = 1.0 and a = 1.5. Use the subplot command to put all three plots in a single figure. Issue the command orient(tall) just prior to printing to prevent crowding of the subplots.
This lab was adapted from Lab1 of ECE438 Digital Signal Processing with Applications course at Purdue University, USA.
10
for
[20, 20]
and
[1, 10]
Hint: The unit step function y = u(n) may be computed in Matlab using the command y = (n>=0) , where n is a vector of values of time indices. INLAB REPORT: Submit all three figures, for a total of 8 plots. Also submit your Matlab .m-files.
6 SAMPLING
The word sampling refers to the conversion of a continuous-time signal into a discrete-time signal. The signal is converted by taking its value, or sample, at uniformly spaced points in time. The time between two consecutive samples is called the sampling period. For example, a sampling period of 0.1 seconds implies that the value of the signal is stored every 0.1 seconds. Consider the signal f(t) = sin(2t). We may form a discrete-time signal, x(n), by sampling this signal with a period of Ts. In this case, = = sin 2
Use the stem command to plot the function f(Tsn) defined above for the following values of Ts and n. Use the subplot command to put all the plots in a single figure, and scale the plots properly with the axis command.
1 2 3 4
= , 0 = , 0 =
, 0
30; 30; 9;
100;
[0,100, 1,1]
, 0
INLAB REPORT: Submit a copy of the figure containing all four subplots. Discuss your results. How does the sampled version of the signal with Ts = 1/10 compare to those with Ts = 1/3, Ts = 1/2 and Ts = 10/9?
This lab was adapted from Lab1 of ECE438 Digital Signal Processing with Applications course at Purdue University, USA.