www.pudn.com > AR_MATLAB.rar > convolution.m


% File: convolution.m 
% ------------------- 
% This file is used to compute the convolution of two sequences. 
 
function [y_output] = convolution(x_input, h_input) 
% y_output: convolution output 
% h_input:  hir filter 
% x_input:  input sequence 
L = length(x_input); % length of input sequence 
M = length(h_input) - 1; % order of hir filter 
y_output = zeros(L + M, 1); 
y_output_cast = zeros(L + M + 1, 1); 
for n = 2: (L + M + 1) 
    y_output_cast(n) = 0; 
    for m = max(1, (n - L)): min((n - 1), (M + 1)) 
        y_output_cast(n) = y_output_cast(n) + h_input(m) * x_input(n - m); 
    end 
end 
for n = 1: (L + M) 
    y_output(n) = y_output_cast(n + 1); 
end