I would like to achieve this using if statements and for loops.
Create a function “sigadd” to add two sequences ‘x1’ and ‘x2’.
function [y,n]=sigadd(x1,n1,x2,n2)Where ‘x1’ and ‘x2’ are two sequences and ‘n1’ and ‘n2’ are their respective indices vectors. Add values of ‘x1’ and ‘x2’ at corresponding indices, pad zeros if length of two sequences are not same.
Suppose x1= [1 2 3 4 5 6 7 8 9] with index n1= 3:11 and x2= [2 4 6 8 10 12 14 16 18 20 22 24] with index n2=1:12. Here you can observe that the length of both the signals is not same and the indexes of both the signals are not starting from the same point. So you have to pad zeros before adding both the sequences so that the output y will have the index values starting from 1 up to 12.