0% found this document useful (0 votes)
2 views2 pages

Manual Convolution and Circular Methods

Uploaded by

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

Manual Convolution and Circular Methods

Uploaded by

hopeless2693
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Convolution

y = conv(x, h); -> inbuilt function

Code:

% Define the input signal

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

% Define the impulse response

h = [1, 1, 1, 1]; % Impulse response h[n]

% Lengths of the input signals

N = length(x);

M = length(h);

% Length of the output signal

L = N + M - 1;

% Initialize the output signal with zeros

y = zeros(1, L);

% Perform the convolution manually

for n = 1:L

% Initialize the sum for the current output element

sum = 0;

for k = 1:N

% Calculate the index for h[n-k]

index_h = n - k + 1;

% Check if the index for h is within bounds

if index_h > 0 && index_h <= M

sum = sum + x(k) * h(index_h);


end

end

% Assign the computed sum to the current output element

y(n) = sum;

end

% Display the result

disp(y);

cconv -> inbuilt function

% Define the input signal x = [1, 2, 3, 4]; % Input signal x[n] % Define the
impulse response h = [1, 1, 1, 1]; % Impulse response h[n] % Ensure both
sequences are of the same length N = max(length(x), length(h));
x_padded = [x zeros(1, N - length(x))]; h_padded = [h zeros(1, N -
length(h))]; % Initialize the output signal with zeros y_circular = zeros(1,
N); % Perform circular convolution manually for n = 1:N for k = 1:N %
Circular indexing index_h = mod(n - k, N) + 1; y_circular(n) = y_circular(n)
+ x_padded(k) * h_padded(index_h); end end

Xcorr -> inbuilt function

for n = 1:L

sum = 0;

for k = 1:N

index_y = n - k + 1;

if index_y > 0 && index_y <= M

sum = sum + x(k) * y(index_y);

end

end

r_xy(n) = sum;

end

You might also like