Experiment 4 - 10281
Experiment 4 - 10281
Post Lab 1:
% Exp 4-1
% Parameters
a = 1; % Decay rate for x1(t)
T = 1; % Duration for x1(t) and x2(t)
% Time vectors with a finer resolution
t1 = 0:0.01:T; % Time vector for x1(t) from 0 to T
t2 = 0:0.01:2*T; % Time vector for x2(t) from 0 to 2T
x1 = exp(-a * t1); % x1(t) = e^(-at) for 0 <= t <= T
x2 = ones(size(t2)); % x2(t) = 1 for 0 <= t <= 2T
% Convolution
y = conv(x1, x2, 'full'); % Compute convolution
t_y = linspace(0, T + 2*T, length(y)); % Time vector for the convolution result
% Plotting
figure;
% Plot x1(t)
subplot(3, 1, 1);
plot(t1, x1, 'b', 'LineWidth', 2);
title('Signal x1(t) = e^{-at}');
xlabel('Time (t)');
ylabel('Amplitude');
xlim([0 T]);
grid on;
% Plot x2(t)
subplot(3, 1, 2);
plot(t2, x2, 'r', 'LineWidth', 2);
title('Signal x2(t) = 1');
xlabel('Time (t)');
ylabel('Amplitude');
xlim([0 2*T]);
grid on;
% Plot convolution result
subplot(3, 1, 3);
plot(t_y, y, 'k', 'LineWidth', 2);
title('Convolution of x1(t) and x2(t)');
xlabel('Time (t)');
ylabel('Amplitude');
xlim([0 T + 2*T]);
grid on;
% Exp4-2
% Define the time vector
t = 0:0.01:10; % Time from 0 to 10 with 0.01 increments
% Define the signals
x1 = exp(-3 * t); % x1(t) = e^(-3t)u(t)
x2 = t; % x2(t) = t * u(t)
% Perform convolution
y = conv(x1, x2, 'same') * 0.01; % 'same' to get the same size as the input vectors, scaled by the
time step
% Plot the original signals and the result
subplot(3,1,1);
plot(t, x1);
title('Signal x1(t) = e^{-3t}u(t)');
xlabel('t');
ylabel('x1(t)');
subplot(3,1,2);
plot(t, x2);
title('Signal x2(t) = t * u(t)');
xlabel('t');
ylabel('x2(t)');
subplot(3,1,3);
plot(t, y);
title('Convolution Result y(t) = x1(t) * x2(t)');
xlabel('t');
ylabel('y(t)');
% Display the result
disp('The result of the convolution y(t) = x1(t) * x2(t) is:');
disp(y);
% Exp 4-3
% Define the discrete signals
x1 = [4, 4, 2, 1, 5, 1];
x2 = [6, 4, 2, 1, 3, 1];
% Perform convolution
y = conv(x1, x2);
% Define the time vectors for plotting
n1 = 0:length(x1)-1; % Time indices for x1
n2 = 0:length(x2)-1; % Time indices for x2
ny = 0:length(y)-1; % Time indices for the result
% Plot the original signals and the convolution result
subplot(3,1,1);
stem(n1, x1, 'filled');
title('Signal x1(n)');
xlabel('n');
ylabel('x1(n)');
subplot(3,1,2);
stem(n2, x2, 'filled');
title('Signal x2(n)');
xlabel('n');
ylabel('x2(n)');
subplot(3,1,3);
stem(ny, y, 'filled');
title('Convolution Result y(n) = x1(n) * x2(n)');
xlabel('n');
ylabel('y(n)');
% Display the result
disp('The result of the convolution y(n) = x1(n) * x2(n) is:');
disp(y);
% Exp 4-4
% Define the discrete signals
x1 = [6, 4, 1, 7, 6, 3];
% Define the unit step function u(n-2)
n_step = 0:10; % Define the range of n for the step function
x2 = double(n_step >= 2); % u(n-2) = 1 for n >= 2, otherwise 0
% Perform convolution
y = conv(x1, x2);
% Define the time vectors for plotting
n1 = 0:length(x1)-1; % Time indices for x1
n2 = n_step; % Time indices for x2
ny = 0:length(y)-1; % Time indices for the result
% Plot the original signals and the convolution result
subplot(3,1,1);
stem(n1, x1, 'filled');
title('Signal x1(n)');
xlabel('n');
ylabel('x1(n)');
subplot(3,1,2);
stem(n2, x2, 'filled');
title('Signal x2(n) = u(n-2)');
xlabel('n');
ylabel('x2(n)');
subplot(3,1,3);
stem(ny, y, 'filled');
title('Convolution Result y(n) = x1(n) * x2(n)');
xlabel('n');
ylabel('y(n)');
% Display the result
disp('The result of the convolution y(n) = x1(n) * x2(n) is:');
disp(y);