function [x, n] = signalplus(s1, n1, s2, n2)
% n1 is the sample positions of s1
% n2 is the sample positions of s2
i understood it but i can write in matlab
example:
s1=[2 5 7]; n1=2
s2=[3 2 6]; n2=3
s=s1 + s2 = [3 4 11 7]
thank you :)
i find a code but it not work , i use : sigadd([2 5 7],2,[3 2 6],3) error
function [y,n] = sigadd(x1,n1,x2,n2)
% implements y(n) = x1(n)+x2(n)
% -----------------------------
% [y,n] = sigadd(x1,n1,x2,n2)
% y = sum sequence over n, which includes 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)); y2 = y1; % initialization
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; % sequence addition

 Respuesta aceptada

Geoff Hayes
Geoff Hayes el 7 de Feb. de 2015

0 votos

Syren - presumably you found sigadd.m from the submission by John Proakis at DSP Using MATLAB. In the Chapter 2 folder (CHAP_02/) there is an example file called ex020200.m which invokes the sigadd function as
[x1,n1] = sigadd(2*x11,n11,-3*x12,n12);
where each of the input vectors are 1x13 arrays. I suspect that you will need to do something similar in your example. The n1 and n2 inputs (your 2 and 3) should be arrays such as
n1 = [1 2 3];
n2 = [0 1 2];
with
sigadd([2 5 7],[1 2 3],[3 2 6],[0 1 2])
producing the desired output of
ans =
3 4 11 7
Try the above and see what happens!

Más respuestas (2)

Chidiebere Onuoha
Chidiebere Onuoha el 29 de Jun. de 2018

0 votos

%I hope this will help:
%implements y(n)=x1(n)+x2(n)
% y = sums the sequence over n, which includes n1 and n2
%x1 = first sequence over n1
%x2 = second sequence over n2
function [y,n] = sigadd(x1,x2,n1,n2)
n = min(min(n1), min(n2)): max(max(n1),max(n2));
%duration of y(n)
y1 = zeros(1, length(n));
y2 = y1;
%initialization
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;
%sequence addition
end

3 comentarios

Azmat Ameen
Azmat Ameen el 15 de Dic. de 2020
Editada: Azmat Ameen el 15 de Dic. de 2020
error: not enough input argument.
please guide
Geoff Hayes
Geoff Hayes el 17 de Dic. de 2020
Azmat - please post the full error message and line of code that is generating the error. Also, are you passing the correct/expected number of input arguments into whichever function that you are calling?
Nga Ly
Nga Ly el 17 de Mzo. de 2021
Not enough input arguments.
Error in sigadd (line 4)
n=min(min(n1),min(n2)):max(max(n1),max(n2));

Iniciar sesión para comentar.

buynaa
buynaa el 27 de Nov. de 2022

0 votos

x_1-x_2-5→max
〖〖(x〗_1-1)〗_2≤1
〖x_1+x〗_2≥3,5
0≤x_1≤5
0≤x_2≤5

Categorías

Etiquetas

Aún no se han introducido etiquetas.

Preguntada:

el 7 de Feb. de 2015

Respondida:

el 27 de Nov. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by