0% found this document useful (0 votes)
16 views1 page

To Perform Linear Convolution Upon Two Given Discrete Time Signals

code

Uploaded by

saurish gahlaut
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views1 page

To Perform Linear Convolution Upon Two Given Discrete Time Signals

code

Uploaded by

saurish gahlaut
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

% Define two discrete-time signals

x = [1, 2, 3, 4]; % Example signal x[n]


h = [1, -1, 2]; % Example signal h[n]

% 1. Linear Convolution using MATLAB's conv function


y_conv = conv(x, h); % Convolution using built-in function

% Display the result


disp('Linear Convolution using conv function:');
disp(y_conv);

% Plot the result


n_conv = 0:length(y_conv)-1;
figure;
subplot(2, 1, 1);
stem(n_conv, y_conv, 'filled');
title('Linear Convolution using MATLAB conv function');
xlabel('n');
ylabel('Amplitude');
grid on;

% 2. Linear Convolution using Convolution Sum Formula


% Initialize the output signal y
N = length(x) + length(h) - 1; % Length of the convolution output
y_manual = zeros(1, N); % Initialize output signal

% Compute the convolution manually


for n = 1:N
for k = 1:length(x)
if (n - k + 1 > 0) && (n - k + 1 <= length(h))
y_manual(n) = y_manual(n) + x(k) * h(n - k + 1);
end
end
end

% Display the result


disp('Linear Convolution using manual sum formula:');
disp(y_manual);

% Plot the result


subplot(2, 1, 2);
stem(0:N-1, y_manual, 'filled');
title('Linear Convolution using Sum Formula');
xlabel('n');
ylabel('Amplitude');
grid on;

You might also like