Write a Matlab function signalx
Question
1 (a) Write a Matlab function signalx that evaluates the following signal at an arbitrary set of points:
⎧⎨⎩ 2et+2, −3≤t≤−1 x(t)= 2e−tcos2πt, −1≤t≤4
0, else
That is, given an input vector of time points, the function should give an output vector with the values of x evaluated at those time points. For time points falling outside [−3, 4], the function should return the value zero.
(b) Use the function signalx to plot x(t) versus t, for −6 ≤ t ≤ 6. To do this, create a vector of sampling times spaced closely enough to get a smooth plot. Generate a corresponding vector using signalx. Then plot one against the other.
(c) Use the function signalx to plot x(t − 3) versus t. (d) Use the function signalx to plot x(3 − t) versus t. (e) Use the function signalx to plot x(2t) versus t.
Convolution
2(a) Write a Matlab function contconv that computes an approximation to continuous-time convolution as follows.
Inputs: Vectors x1 and x2 representing samples of two signals to be convolved. Scalars t1, t2 and dt, representing the starting time for the samples of x1, the starting time for the samples in x2, and the spacing of the samples.
Outputs: Vectors y and t, corresponding to the samples of the convolution output and the sampling times.
(b) Check that your function works by using it to convolve two boxes, 3I[−2,−1] and 4I[1,3], to get a trapezoid (e.g., using the following code fragment):
dt=0.01;%sample spacing
s1 = -2:dt:-1; %sampling times over the interval [-2,-1] s2= 1:dt:3; %sampling times over the interval [1,3]
85
x1=3*ones(length(s1),1); %samples for first box x2=4*ones(length(s2),1); %samples for second box [y,t]= contconv(x1,x2,s1(1),s2(1),dt); figure(1);
plot(t,y);
Check that the trapezoid you get spans the correct interval (based on the analytical answer) and has the correct scaling.