%Signal generator code
disp('Welcome to our signal generation simple application')
sf= input('Please enter sampling frequency:');%sampling frequency
start= input('Please enter signal start point:');%start point
ending= input('Please enter signal end point:');%end point %end is a key word so we couldn't use it as a variable
bp= input('Please enter number of break points');%break points
bpvec=zeros(1,bp);%breaking points vector
if bp~=0
t=linspace(start,ending,(ending-start)*sf);
for i=1:1:bp
bpvec(i)=input('please enter the position of the breaking point');
t1=linspace(start,bpvec(i),(bpvec(i)-start)*sf);
type= menu('type of the sigal partition','Impulse signal','DC signal','Ramp signal','Exponential','Sinusoidal');%type of each partition
switch type
case 1
area=input('please enter the area');
x=zeros(1,length(t1));
x(1)=area;
y1=x;
case 2
amp=input('please enter the amplitude');
x=amp*(ones(1,length(t1)));
y1=x;
case 3
slope=input('please enter the slope');
intercept=input('please enter the intercept');
y1=slope*t1+intercept;
case 4
amp=input('please enter the amplitude');
ex=input('please enter the exponent');
y1=amp*exp(t1*ex);
case 5
amp=input('please enter the amp');
freq=input('please enter the frequency');
phase=input('please enter the phase');
y1=amp*sin((2*pi*freq*t1)+phase);
end
start=bpvec(i);
if i==1
y=y1;
else
y=[y y1];
end
y=[y y1];
end
else %if no break points
t=linspace(start,ending,(ending-start)*sf);
type= menu('Impulse signal','DC signal','Ramp signal','Exponential','Sinusoidal');%type of each partition
switch type
case 1
area=input('please enter the area');
x=zeros(1,length(t));
x(1)=area;
y1=x;
case 2
amp=input('please enter the amplitude');
x=amp.*(ones(1,length(t)));
y1=x;
case 3
slope=input('please enter the slope');
inttercept=input('please enter the intercept');
y1=slope*t+intercept;
case 4
amp=input('please enter the amplitude');
ex=input('please enter the exponent');
y1=amp*exp(t*ex);
case 5
amp=input('please enter the amp');
freq=input('please enter the frequency');
phase=input('please enter the phase');
y1=amp*sin((2*pi*freq*t)+phase);
end
y=y1;
end
plot(t,y)

3 Kommentare

Walter Roberson
Walter Roberson am 23 Nov. 2018
please show the complete error message
youssif wahdan
youssif wahdan am 23 Nov. 2018
Error using plot.
vectors must be the same length
error in miniproject1 line 82
plot(t,y)
Walter Roberson
Walter Roberson am 24 Nov. 2018
what is the
sequence of inputs that trigger the error?

Melden Sie sich an, um zu kommentieren.

Antworten (2)

madhan ravi
madhan ravi am 24 Nov. 2018

0 Stimmen

plot(t,y(1:numel(t)))
%or
plot(t(1:numel(y)),y)
Walter Roberson
Walter Roberson am 24 Nov. 2018

0 Stimmen

You have
if i==1
y=y1;
else
y=[y y1];
end
y=[y y1];
Every iteration of the for i loop, that adds y1 to the end of y twice, so y will be length 2*bp . But you have
t=linspace(start,ending,(ending-start)*sf);
which is a length that is unrelated to bp.

Kategorien

Mehr zu MATLAB finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 23 Nov. 2018

Beantwortet:

am 24 Nov. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by