Borrar filtros
Borrar filtros

help me to explain this function of signal addition

13 visualizaciones (últimos 30 días)
Hasnaa Hasaan
Hasnaa Hasaan el 25 de Mzo. de 2023
Comentada: Hasnaa Hasaan el 31 de Mzo. de 2023
I need to under stand the details of this function it seems d
function [y,n] = sigadd(x1,n1,x2,n2)
% implement y(n) = x1(n) + x2 (n)
% [y,n] = sigadd (x1,n1,x2,n2)
% y = sum sequence over n, which include n1 and n2
% x1 = first sequence over n1
% x2 = second sequence over n2 (n2 can be different from n1)
n = min(min(n1),min(n2)): max(max(n1),max(n2)); %duration of y(n)
y1 = zeros(1,length(n)); % initialization
y2 = y1;
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1; % x1 with duration of y
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2; % x2 with duration of y
y = y1 + y2;
ifficult for me

Respuestas (1)

Nithin Kumar
Nithin Kumar el 29 de Mzo. de 2023
Hi Hasaan,
I understand that you are seeking an explanation of the user defined function “sigadd” that you have provided.
  • The function “sigadd” takes four input arguments ‘x1’, ‘n1’, ‘x2’, ‘n2’.
  • The arguments ‘x1’ and ‘n1’ represent the first sequence and its range of indices. In the same way, ‘x2’ and ‘n2’ represent the second sequence and its range of indices respectively.
  • The function first finds the range of indices over which ‘y(n)’ will be defined by computing the minimum and maximum values of ‘n1’ and ‘n2’ respectively.
  • Then, the function initializes two arrays ‘y1’ and ‘y2’ to zeros with the length of ‘n’. These arrays are then used to store ‘x1(n)’ and ‘x2(n)’ respectively.
  • The function then finds the indices of ‘n’ that are within the range of ‘n1’ and ‘n2’ and sets the corresponding elements of ‘y1’ and ‘y2’ to the values of ‘x1’ and ‘x2’ respectively.
Finally, the function calculates the sum of ‘y1’ and ‘y2’ and returns the result as ’y’.
I hope this answer resolves the issue you are encountering.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by