Lab6 Discrete-Time Signals and Systems
Watch video entitled Module 6 Discrete-Time Signals in MATLABWork the lab activity below using MATLAB.Include answers for Problems and include MATLAB coding along with any output plots that support solutions into a Word document entitled Lab6_StudentID. Where your student id is substituted in the file name.Upload file Lab6_StudentID.Activity 1:
A discrete-time system can be described in one of two ways. One is by the unit-pulse response of the system, and the other is by the difference equation. In the first case, if we are given an input and want to find the output, we have to convolve the system response with the input signal. In the second case, we have to solve the difference equation for the output when the input signal is substituted into the difference equation. The result should be the same no matter what approach is used.
A discrete-time system has the following unit-pulse response:
for
Correspondingly, the following difference equation describes the behavior of the system:
Use the Matlab command conv to calculate the response of the system to a unit step input, x[n]=u[n]. Consider . Show what you type into the Matlab command window. Also, submit a plot of the output. Be sure to label your axes.Matlab Tip: Remember that you can easily get help on a command in Matlab by typing help with the command at the prompt:
EDUhelp conv
Matlab Tip: Also, dont forget that in Matlab when you do certain operations on an array element-by-element, you must precede the operator with a period. For instance, in Matlab, if you define an array n as follows:
EDUn=[0:20];
then the first term of the unit-pulse response is written as 0.5.^n
Matlab Tip: Sometimes it is useful to know the size of arrays you have created. This can be done in several ways. For example, you can use the command size:
EDU size(n)
ans =
1 21
The size of the array is returned. In this case, the array n has a size of 1 row by 21 columns.
Alternatively, you can switch the display from the Current Directory to the Workspace. Then all current variables and arrays and their sizes are displayed. Just click on Workspace in the upper left corner as indicated below.
Use the Matlab function recur to calculate the response of the system to a unit step input, x[n]=u[n]. Again consider . Show all that you type into the Matlab command window. Submit a plot of the output with the axes labeled.The Matlab function recur is not a function which comes with Matlab or any of the toolboxes you have installed. Instead, it is a that must be added to your Matlab directory.
The Matlab function recur can be found in a zip file at the Mathworks site at the following location:
http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=2148
Extract the file recur.m to the current directory shown at the top of the Matlab window.
On the other hand, you can copy and paste the script below into a text file like Notepad and save it as recur.m in the current directory shown at the top of the Matlab window.
function y = recur(a,b,n,x,x0,y0);
%
% y = recur(a,b,n,x,x0,y0)
% solves for y[n] from:
% y[n] + a1*y[n-1] + a2*y[n-2] + an*y[n-N]
% = b0*x[n] + b1*x[n-1] + + bm*x[n-M]
%
% a, b, n, x, x0 and y0 are vectors
% a = [a1 a2 aN]
% b = [b0 b1 bM]
% n contains the time values for which the solution will be computed
% y0 contains the initial conditions for y, in order,
% i.e., y0 = [y[n0-N], y[n0-N+1], ,y[n0-1]]
% where n0 represents the first element of n
% x0 contains the initial conditions on x, in order
% i.e., x0 = [x[n0-M],,x[n0-1]]
% the output, y, has length(n)
%
N = length(a);
M = length(b)-1;
if length(y0) ~= N,
error(Lengths of a and y0 must match)
end
if length(x0) ~= M,
error(Length of x0 must match length of b-1)
end
y = [y0 zeros(1,length(n))];
x = [x0 x];
a1 = a(length(a):-1:1); % reverses the elements in a
b1 = b(length(b):-1:1);
for i=N+1:N+length(n),
y(i) = -a1*y(i-N:i-1) + b1*x(i-N:i-N+M);
end
y = y(N+1:N+length(n));
To get information on how to use the function, at the Matlab prompt, type:
EDUhelp recur
It might be helpful to change the index of the difference equation such that the highest index is n rather than n+2.
Are your plots the same? If not, why not?
Lab5 The Fourier Series and Fourier Transform
Watch video entitled Module 5 Fourier Transform in MATLABPerform activity 1 below for the lab assignment using MATLAB.Include answers for Problems and include MATLAB coding along with any output plots that support solutions into a Word document entitled Lab5_StudentID. Where your student id is substituted in the file name.Upload file Lab5_StudentID.Activity 1:
A continuous time function is shown below in figure 1. This signal is a sinc function defined as y(t) = sinc(t). The Fourier transform of this signal is a rectangle function.
1. Use the function linspace to create a vector of time values from -5 t 5. Next, plot the function shown in figure 1 using the sinc function for y(t) = sinc(t).
2. Using Matlab and the command fft, show that the Fourier transform pair is indeed a rectangle function. Use the command fftshift to center your plot. Dont forget that the Fourier transform is complex, with both magnitude and phase. Your result should be the same as figure 2. Show both your m-file code and plot.
Matlab tip: The following commands are useful when working with the Fourier transform:
abs gives the magnitude of a complex number (or absolute value of a real number)
angle gives the angle of a complex number, in radians
[Note: The fft command does not give the exact transform for a continuous time signal, which we have in this case. For instance, the magnitude will not be correct. However, in order to obtain the general shape including relative magnitudes, it can be quite useful.]
Using the same time values, plot the continuous time function defined as y(t) = sinc(2t).Plot the transform pair for this signal.Questions:
What is the cause of the ringing seen on top of the rectangular pulse shown in figure 2?In step 3 above, the sinc function gets compressed by a factor of 2, as seen by comparing the graphs in the time domain. What happened to the rectangular pulse in the frequency domain? What property does this represent?
Reviews
There are no reviews yet.