sayurabh
Member level 4
function [y,n]=sigadd(x1,n1,x2,n2)
n=min(min(n1),min(n2)):max(max(n1),max(n2));
if(min(n1)>min)
while(min(n1)>min)
x1=[zeros(1,1),x1];
min(n1)=min(n1)-1;
end;
end;
if(min(n2)>min)
while(min(n2)>min)
x2=[zeros(1,1),x2];
min(n2)=min(n2)-1;
end;
end;
if(max(n2)<max)
while(max(n2)<max)
x2=[x2,zeros(1,1)];
max(n2)=max(n2)+1;
end;
end;
if(max(n1)<max)
while(max(n1)<max)
x1=[x1,zeros(1,1)];
max(n1)=max(n1)+1;
end;
end;
y=x1+x2;
i had made the code for working of this code for any dimensions of two array i tried to make both araays avoiding the negastive indexing problem some where is prob matlab is not accepting predefine min function plz check it out code iz easy if u want to understand reply it i will tell u the whole story it i know the code ihad myself it is better then proakis code for addition of wo sgnal moe powerful but some logical error iz coming x1 and x2 are two signal eneterred and the n1 and n2 are th respected lengths of ther signal i mean indexex u understand
n=min(min(n1),min(n2)):max(max(n1),max(n2));
if(min(n1)>min)
while(min(n1)>min)
x1=[zeros(1,1),x1];
min(n1)=min(n1)-1;
end;
end;
if(min(n2)>min)
while(min(n2)>min)
x2=[zeros(1,1),x2];
min(n2)=min(n2)-1;
end;
end;
if(max(n2)<max)
while(max(n2)<max)
x2=[x2,zeros(1,1)];
max(n2)=max(n2)+1;
end;
end;
if(max(n1)<max)
while(max(n1)<max)
x1=[x1,zeros(1,1)];
max(n1)=max(n1)+1;
end;
end;
y=x1+x2;
i had made the code for working of this code for any dimensions of two array i tried to make both araays avoiding the negastive indexing problem some where is prob matlab is not accepting predefine min function plz check it out code iz easy if u want to understand reply it i will tell u the whole story it i know the code ihad myself it is better then proakis code for addition of wo sgnal moe powerful but some logical error iz coming x1 and x2 are two signal eneterred and the n1 and n2 are th respected lengths of ther signal i mean indexex u understand