Plot the following continuous time signals over the range t [-7,7] using 1,000 sample points per unit time.

Plot the following continuous time signals over the range t [-7,7] using 1,000 sample points per unit time. ax1t=e-1cos2tt bxt=R{ei2x+/7+r/4} cx3t=-2x1t+1 ax4=ut+2-ut+2ut-2 2. Plot the following three discrete-time signals (using the stem command) over the range n E [-6,6]: ax1[n=cosn/2+/3 (bx2[n]= ()u[-n-1] cx3[n]=2×2[-2n] (dx4[n]=x2[n]x1[n]for this part,consider x[n]and x1[n] as zero outside nE[6,6] Instructions for your plots: 1. Plot the continuous time signals on 4 different axes (4 separate figures) 2. Plot the discrete-time signals on 4 different axes within the same figure using the subplot command. 3. Use the grid command for each set of axes,and use xlabel and ylabel to label each set of axes.Also use title for each set of axes,e.g.,title’1a)’ Turn in 4 continuous-time figures on 4 separate pages and one page containing the 4 subplots for the discrete-time signals. Also turn in your Matlab script.

The Correct Answer and Explanation is:

✅ MATLAB Script

matlabCopyEdit%% Continuous-Time Signals
t = -7:1/1000:7; % 1000 sample points per unit time

% a) x1(t) = e^(-t) * cos(2t)
x1 = exp(-t) .* cos(2*t);
figure;
plot(t, x1); grid on;
xlabel('t'); ylabel('x1(t)');
title('1a) x1(t) = e^{-t} cos(2t)');

% b) x2(t) = Real{e^(i(2t + pi/7 + pi/4))}
x2 = real(exp(1i*(2*t + pi/7 + pi/4)));
figure;
plot(t, x2); grid on;
xlabel('t'); ylabel('x2(t)');
title('1b) x2(t) = Re{e^{i(2t + π/7 + π/4)}}');

% c) x3(t) = -2 * x1(t + 1)
x3 = -2 * exp(-(t + 1)) .* cos(2*(t + 1));
figure;
plot(t, x3); grid on;
xlabel('t'); ylabel('x3(t)');
title('1c) x3(t) = -2 * x1(t + 1)');

% d) x4(t) = u(t + 2) - u(t) + 2u(t - 2)
u = @(t) double(t >= 0);
x4 = u(t + 2) - u(t) + 2*u(t - 2);
figure;
plot(t, x4); grid on;
xlabel('t'); ylabel('x4(t)');
title('1d) x4(t) = u(t + 2) - u(t) + 2u(t - 2)');

%% Discrete-Time Signals
n = -6:6;

% a) x1[n] = cos(n/2 + pi/3)
x1n = cos(n/2 + pi/3);

% b) x2[n] = n * u[-n - 1]
x2n = n .* (n <= -1);

% c) x3[n] = 2 * x2[-2n]
x2_neg2n = interp1(n, x2n, -2*n, 'linear', 0); % zero-padding
x3n = 2 * x2_neg2n;

% d) x4[n] = x2[n] * x1[n], zero outside n in [-6,6]
x4n = x2n .* x1n;

% Plot all discrete signals in one figure with subplots
figure;
subplot(2,2,1); stem(n, x1n); grid on;
xlabel('n'); ylabel('x1[n]');
title('2a) x1[n] = cos(n/2 + π/3)');

subplot(2,2,2); stem(n, x2n); grid on;
xlabel('n'); ylabel('x2[n]');
title('2b) x2[n] = n * u[-n - 1]');

subplot(2,2,3); stem(n, x3n); grid on;
xlabel('n'); ylabel('x3[n]');
title('2c) x3[n] = 2 * x2[-2n]');

subplot(2,2,4); stem(n, x4n); grid on;
xlabel('n'); ylabel('x4[n]');
title('2d) x4[n] = x2[n] * x1[n]');

📘 Explanation

This MATLAB project involves plotting both continuous-time and discrete-time signals using MATLAB’s plot and stem commands, respectively.

In the continuous-time section, we use a high-resolution time vector t with 1000 samples per unit time over the range [-7,7].

  • (1a) plots a decaying cosine function x1(t) = e^{-t}cos(2t); it shows damped oscillations due to the exponential decay.
  • (1b) calculates the real part of a complex exponential. Since e^{iθ} is a complex sinusoid, the real part is just cos(θ), making the signal another cosine wave with phase shift.
  • (1c) applies a time shift and scaling to the original x1(t), plotting x3(t) = -2 * x1(t + 1), which flips and delays the waveform.
  • (1d) uses unit step functions u(t) to construct a piecewise signal: x4(t) = u(t + 2) - u(t) + 2u(t - 2), resulting in discontinuous jumps at the defined points.

For the discrete-time section, the vector n = -6:6 defines our index range.

  • (2a) defines a cosine-based signal x1[n] = cos(n/2 + π/3) and is periodic.
  • (2b) uses a shifted unit step to activate values for n <= -1, giving a ramp for negative indices.
  • (2c) scales and reflects x2[n] to create x3[n] = 2 * x2[-2n].
  • (2d) multiplies x1[n] and x2[n] elementwise to form x4[n], which is defined only within [-6,6].

All figures include labels, grid lines, and titles for clarity. Separate figures are used for continuous-time plots, while discrete signals are arranged using subplot.

Scroll to Top