Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Department of Electrical Engineering Signal Processing Laboratory

Experiment No: 4
Aim: Study of linear convolution and circular convolution

Program:
Linear Convolution
% Prompt user for input signals
x1 = input('Enter signal x1 as a row vector: ');
x2 = input('Enter signal x2 as a row vector: ');

% Compute linear convolution


y_linear = conv(x1, x2);

% Display linear convolution result


disp('Linear Convolution Result:');
disp(y_linear);

% Plot input signals and linear convolution output


subplot(3,1,1);
stem(0:length(x1)-1, x1, 'filled');
title('Signal x1');
xlabel('Index');
ylabel('Amplitude');

subplot(3,1,2);
stem(0:length(x2)-1, x2, 'filled');
title('Signal x2');
xlabel('Index');
ylabel('Amplitude');

subplot(3,1,3);
stem(0:length(y_linear)-1, y_linear, 'filled');
title('Linear Convolution Result');
xlabel('Index');
ylabel('Amplitude');

Circular Convolution
% Prompt user for input signals
x1 = input('Enter signal x1 as a row vector: ');
x2 = input('Enter signal x2 as a row vector: ');

% Compute circular convolution


y_circular = cconv(x1, x2, length(x1));

% Display circular convolution result


disp('Circular Convolution Result:');
disp(y_circular);

% Plot input signals and circular convolution output


subplot(3,1,1);
stem(0:length(x1)-1, x1, 'filled');
title('Signal x1');
xlabel('Index');
Department of Electrical Engineering Signal Processing Laboratory

ylabel('Amplitude');

subplot(3,1,2);
stem(0:length(x2)-1, x2, 'filled');
title('Signal x2');
xlabel('Index');
ylabel('Amplitude');

subplot(3,1,3);
stem(0:length(y_circular)-1, y_circular, 'filled');
title('Circular Convolution Result');
xlabel('Index');
ylabel('Amplitude');

Result:
Linear Convolution
Enter signal x1 as a row vector: [1 2 3]
Enter signal x2 as a row vector: [0.5 0.5 0.5]
Linear Convolution Result:
0.5000 1.5000 3.0000 2.5000 1.5000

Circular Convolution
Enter signal x1 as a row vector: [1 2 3]
Enter signal x2 as a row vector: [0.5 0.5 0.5]
Circular Convolution Result:
3 3 3
Department of Electrical Engineering Signal Processing Laboratory

Conclusion:

You might also like