Nitin400

Question- Function for Signal Addition:

Jan 2nd, 2020
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.57 KB | None | 0 0
  1. function [y,n] = sigadd(x1,n1,x2,n2)
  2. % implements y[n] = x1[n] + x2[n]
  3. % y = sum sequence over n, which includes n1 and n2
  4. % x1 = first sequence over n1
  5. % x2 = second sequence over n2 (n2 can be different from n1)
  6. a = [1 2 3]
  7. ax = -2:0
  8. b = [4 5 6]
  9. bx = 0:2
  10. [z,v] = addition(a, ax, b ,bx)
  11. function [add,n3] = addition(x, n1, y, n2)
  12. n3 =min (min(n1) ,min( n2 ) ) : max ( max ( n1 ) , max ( n2 ) );
  13. s1 =zeros(1,length (n3) );
  14. s2 =s1;
  15. s1 (find ( ( n3>=min( n1 ) ) & ( n3 <=max ( n1 ) )==1 ) )=x;
  16. s2 (find ( ( n3>=min ( n2 ) ) & ( n3 <=max ( n2 ))==1) )=y;
  17. add=s1 +s2;
  18. end
Add Comment
Please, Sign In to add comment