Line 1: | Line 1: | ||
%Tyler Mattmuller | %Tyler Mattmuller | ||
+ | |||
%hw2 | %hw2 | ||
+ | |||
close all | close all | ||
+ | |||
clear all | clear all | ||
+ | |||
x=input('Enter first array in brackets with commas: ') | x=input('Enter first array in brackets with commas: ') | ||
+ | |||
h=input('Enter second array in brackets with commas: ') | h=input('Enter second array in brackets with commas: ') | ||
+ | |||
m=length(x); | m=length(x); | ||
+ | |||
n=length(h); | n=length(h); | ||
+ | |||
X=[x,zeros(1,n)]; %padding with zeros will allow for convolution to be | X=[x,zeros(1,n)]; %padding with zeros will allow for convolution to be | ||
+ | |||
+ | |||
%preformed even if the second array is not the same size as the first array | %preformed even if the second array is not the same size as the first array | ||
+ | |||
H=[h,zeros(1,m)]; | H=[h,zeros(1,m)]; | ||
+ | |||
for i=1:n+m-1 | for i=1:n+m-1 | ||
+ | |||
Y(i)=0; | Y(i)=0; | ||
+ | |||
for j=1:m | for j=1:m | ||
+ | |||
if(i-j+1>0) | if(i-j+1>0) | ||
+ | |||
Y(i)=Y(i)+X(j)*H(i-j+1); | Y(i)=Y(i)+X(j)*H(i-j+1); | ||
+ | |||
else | else | ||
+ | |||
end | end | ||
+ | |||
end | end | ||
+ | |||
end | end | ||
+ | |||
Y %output convolved array | Y %output convolved array | ||
+ | |||
%z=conv(x,h) %will be the same answer therefor it will have the same | %z=conv(x,h) %will be the same answer therefor it will have the same | ||
+ | |||
%functionality this works as the matlab does not distiquish between | %functionality this works as the matlab does not distiquish between | ||
+ | |||
%stating times of the arrays given | %stating times of the arrays given |
Latest revision as of 11:18, 1 July 2009
%Tyler Mattmuller
%hw2
close all
clear all
x=input('Enter first array in brackets with commas: ')
h=input('Enter second array in brackets with commas: ')
m=length(x);
n=length(h);
X=[x,zeros(1,n)]; %padding with zeros will allow for convolution to be
%preformed even if the second array is not the same size as the first array
H=[h,zeros(1,m)];
for i=1:n+m-1
Y(i)=0;
for j=1:m
if(i-j+1>0)
Y(i)=Y(i)+X(j)*H(i-j+1);
else
end
end
end
Y %output convolved array
%z=conv(x,h) %will be the same answer therefor it will have the same
%functionality this works as the matlab does not distiquish between
%stating times of the arrays given