In the name of Allah Chapter 2 First, we will see the syntax of three main functions that will be used in this exercise called: conv filter lsim conv: The MATLAB function y[n] = conv computes the sum of: +∞ ∑ h[k ] x[n − k ] k = −∞ Let x[ n ] and h[ n ] be discrete finite-length sequences. If x[ n ] is nonzero only on the interval of [ sx, fx ] and h[ n ] is nonzero only on the interval of[ sh, fh ], then LX = length( x ) = ( fx – sx + 1) and LH = length( h ) = ( fh – sh + 1).You can easily verify that y[ n ] can be nonzero only on the interval of [ sx + sh, fx + fh ] and LY = length( y ) = LX + LH – 1. The syntax of the command is y = conv( x, h ) where x and y are the vectors containing the values of the two signals x and h. conv does not return the indices of the y[ n ]; which makes sense because the interval of x and h are not inputted to conv. Example: Suppose that x[ n ] and y[ n ] are as shown in the following figures : We know that the x[ n ] * y[ n ] must be: In MATLAB this is implemented as follow: x = [ 1, 2, 3 ] y = [ 1, 2 ] conv( x, y ) = [ 1, 4, 7, 6 ] Note that the indices are not inputted and they could be implemented by another vector which holds the indices. filter: The filter command computes the output of a causal, LTI system for a given Input when the system is specified by a linear constant-coefficient difference Equation as y = filter (b, a, x). The vectors a and b contain the coefficients of y and x in the equation. The vector x contains the value of the input signal. As like the conv function, the indices of x is not specified (note that the system is causal and time invariant ). The output y, has the same size as x[n]. This is clear, because for determining y in n = n0, usually, x[ n = n0] should be specified. Example: Y[ n ] = x[ n ] + 2x[ n –1 ] then a = [ 1 ], b = [ 1, 2 ], now if x = [ 1 ], then y = [ 1 ] but if x = [ 1, 0, 0 ] then y = [1, 2, 0 ]. lsim: The function lsim can be used to simulate the output of continuous-time, causal LTI systems described by linear constant-coefficient differential equations as y = lsim( b, a, x, t ). The vectors a and b contain the coefficients of y and x in the equation. The t and x have the same size, the vector t contains the time samples for the input and output, x contains the values of the input x( t ) at each time in t, and y contains the simulated values of the output y( t ) at each time in t. The accuracy of the simulated values depends upon how well x and t represent the true function x(t). Hint: Basically, lsim interpolates the pair t, x in much the same way as does plot. For instance, consider the plot produced by the following code: >> t = [0, 1, 2, 5, 8, 9, 10]; >> x = [0, 0, 0, 3, 0, 0, 0]; >> plot(t, x) The function lsim( b, a, x, t ) will consider x( t ) to be on the interval of 0 ≤ t ≤ 10 equal to Example: y′( t ) + ½ y( t ) = x( t ) then a = [ 1 0.5 ], b = [ 1 ]. Now we want to simulate the step response of this system. t = [ 0:10 ], x = ones( 1, 11 ). y = lsim( b, a, x, t ). Note that in this special case, at each value of t, the step response computed by lsim is essentially identical to the true step response because the input signal is precise. ☺see also: impulse(b, a) and step(b, a). Computer-based exercises: 1- Commutative property: Interchange the INPUT and INPULSE RESPONSE you know that x[n]*h[n] = h[n]*x[n] by commutative property. That means the input and impulse response signals can be interchanged, so h can be supposed to be input and x be impulse response. First argue for yourself that x[ n ] * h[ n – n0 ] = x[ n – n0 ] * h[ n ]. After that show this equality for these signals, n0 = 2 : 1 n = 0 −1 n = 2 h[ n] = n=4 3 0 otherwise 3 x[ n] = 1 0 n =1 n=2 otherwise Use subplot and stem to plot both convolutions in a single figure. Name your mfile: p2_1.m 2- Consider an input x[ n ] and impulse response h[ n ] given by: x[ n ] = ((½) ^ ( n – 2 ) ) u[ n – 2 ] h[ n ] = u [ n + 2 ] If you wish to compute the x[n]*h[n] using conv, you must deal appropriately with the infinite length of both x[ n ] and h[ n ]. Assume x[ n ] is zero for n ≥ 25 and h[ n ] is zero for n ≥ 14 and now compute x[n]*h[n]. Argue that only a portion of the output of conv will be valid. Specify which values in the output are valid and which are not. Use stem to plot the convolution and your program should give the interval in which values are valid as output. Name your mfile: p2_2.m 3- Use filter function to solve the exercise No. 2-32 in the textbook. Name your mfile: p2_3.m 4- The pulse response of the continuous-time LTI systems You know that the impulse function can be approximated by a pulse with width ∆ and height 1 / ∆. Think about an RC circuit which R = 1K, and C = 1mf ( i.e. τ = 1 ) connected in series with a voltage source. Output is the voltage of Capacitor. Use impulse function to get impulse response, and for ∆ = 0.1 and 0.2 Get the pulse response with lsim function and plot all three response on one figure using subplot. Perhaps functions zeros and ones can be useful. Name your mfile: p2_4.m Deadline: 82/8/11 No paper is required for computer exercises. Just Zip them and send [email protected]
© Copyright 2026 Paperzz