conv of two discrete squre pulses in matlab

To convolve two discrete square pulses in MATLAB, you can use the conv function.

Here is an example of how to do it:

main.m
% Define the two square pulses
pulse1 = [zeros(1, 5), ones(1, 10), zeros(1, 5)];
pulse2 = [zeros(1, 8), ones(1, 12), zeros(1, 8)];

% Convolve the two pulses
convolution = conv(pulse1, pulse2);

% Plot the original pulses and the convolution
subplot(3, 1, 1);
stem(pulse1, 'filled');
title('Square Pulse 1');
xlabel('Sample Index');
ylabel('Amplitude');

subplot(3, 1, 2);
stem(pulse2, 'filled');
title('Square Pulse 2');
xlabel('Sample Index');
ylabel('Amplitude');

subplot(3, 1, 3);
stem(convolution, 'filled');
title('Convolution of Square Pulse 1 and Square Pulse 2');
xlabel('Sample Index');
ylabel('Amplitude');
619 chars
26 lines

In this example, pulse1 and pulse2 are two square pulses represented as arrays of ones and zeros. You can modify the pulse shapes and lengths according to your needs. The conv function is then used to calculate the convolution of pulse1 and pulse2. Finally, the original pulses and the convolution result are plotted using the stem function.

Note that in order to visualize the square pulses and the convolution, I have used the subplot and stem functions to create a multi-plot figure.

gistlibby LogSnag