Continuous signal, Can anyone help me?

Continuous signal. The signal must be a sum of steps and the user to choose the number of steps and each step also defines the initial time and amplitude, as follows. x (t) = a1u(t-t1)+a2u(t-t2) + …
Can anyone help me

 Accepted Answer

t=0:0.01:10
a1=1;
a2=4;
t1=1;
t2=3;
y=a1*heaviside(t-t1)+a2*heaviside(t-t2)
plot(t,y)

11 Comments

heaviside is in the Symbolic Math Toolbox. Type ver on the command line to see if you have it (I don't).
Manuel commented
Well I Have done this code but …
if true
% code
%Input deg initial value
Deg=input('Input number:\n');
%for each new data values put new amplitude and new initial time
for x = 1:Deg
a(x)=input('input amplitude:\n');
i(x)=input('input initial time:\n');
end
end
At the end of your code add
t=0:0.01:100
out=sum(cell2mat(arrayfun(@(x,y) x*heaviside(t-y),a',i','un',0)))
plot(t,out)
Error using arrayfun All of the input arguments must be of the same size and shape. Previous inputs had size 8 in dimension 1. Input #3 has size 7.
Error in miniProjecto (line 12) out=sum(cell2mat(arrayfun(@(x,y) x*heaviside(t-y),a',i','un',0)))
Type
disp(i)
disp(a)
What did you get?
Manuel
Manuel on 2 Nov 2013
Edited: Manuel on 2 Nov 2013
This shows the values I put input. Example: Deg =3; for each drag input a =1; input i =2 ; y=a(1)u*(t-t(2) disp(deg)=1 input a =3; input i =4 ; y=a(1)u*(t-t(2))+a(3)u*(t-t(4)) disp(deg)=2
input a =1; input i =5 ; y=a(1)u*(t-t(2))+a(3)u*(t-t(4))+a(1)u*(t-t(5)) disp(deg)=3
and y=a(1)u*(t-t(2))+a(3)u*(t-t(4))+a(1)u*(t-t(5))+…+ a(x)u*(t-t(x)) disp(deg)=x
Post the code you tried
if true
Deg=input('Introduza o numero de degraus:\n');
for x = 1:Deg
a=input('Introduza um valor para Amplitude:\n'); i=input('Introduza um valor para o Instante inicial:\n'); disp(i) disp(a)
end
end
Try this
Deg=input('Introduza o numero de degraus:\n');
for x = 1:Deg
a(x)=input('Introduza um valor para Amplitude:\n');
i(x)=input('Introduza um valor para o Instante inicial:\n');
end
t=0:0.01:100
out=sum(cell2mat(arrayfun(@(x,y) x*heaviside(t-y),a',i','un',0)))
plot(t,out)
Is correct can explain me this last 3 code lines?
Try this one, simple to understand
t=0:0.01:100
Deg=input('Input number:\n');
out=zeros(1,numel(t));
for x = 1:Deg
a(x)=input('input amplitude:\n');
i(x)=input('input initial time:\n');
out=out+a(x)*heaviside(t-i(x))
end
plot(t,out)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!