%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

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

댓글을 달려면 로그인하십시오.

답변 (2개)

madhan ravi
madhan ravi 2018년 11월 24일

0 개 추천

plot(t,y(1:numel(t)))
%or
plot(t(1:numel(y)),y)
Walter Roberson
Walter Roberson 2018년 11월 24일

0 개 추천

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.

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

질문:

2018년 11월 23일

답변:

2018년 11월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by