plotting a signal which has two equations

2 次查看(过去 30 天)
I am trying to plot this signal whose eqaution differs according to time
I have created this code but I do not know if it is the right way to do it and how get the values of S_if from if statment to plot it
f0=24*10^8;
B=10^6;
T_sweep=2*10^-3;
fmin=f0-0.5*B;
fmax=f0+0.5*B;
t=0:10^-3:500*10^-3;
r=250;
vt=40;
tao=2*(r-vt*t);
gamma=B/T_sweep;
At=1;
Ar=1;
t_telda=rem(t,T_sweep);
for n=1:250
if (t>=2*n*T_sweep) & (t<(2*n+1)*T_sweep)
S_if=0.5*At*Ar*cos(2*pi*gamma*r*t_telda+2*pi*fmin*tao);
elseif (t>=(2*n+1)*T_sweep) & (t<2*(n+1)*T_sweep)
S_if=0.5*At*Ar*cos(2*pi*gamma*r*t_telda-2*pi*fmax*tao);
end
end
plot(t,S_if)

回答(1 个)

Torsten
Torsten 2023-1-12
编辑:Torsten 2023-1-12
None of the two if conditions is satisfied for your t-array. Thus the array S_if does not exist after the for-loop - even if you change the code to
f0=24*10^8;
B=10^6;
T_sweep=2*10^-3;
fmin=f0-0.5*B;
fmax=f0+0.5*B;
t=0:10^-3:500*10^-3;
r=250;
vt=40;
tao=2*(r-vt*t);
gamma=B/T_sweep;
At=1;
Ar=1;
for n=1:250
t_telda=rem(t(n),T_sweep);
if (t(n)>=2*n*T_sweep) & (t(n)<(2*n+1)*T_sweep)
S_if(n)=0.5*At*Ar*cos(2*pi*gamma*r*t_telda+2*pi*fmin*tao(n));
elseif (t(n)>=(2*n+1)*T_sweep) & (t(n)<2*(n+1)*T_sweep)
S_if(n)=0.5*At*Ar*cos(2*pi*gamma*r*t_telda-2*pi*fmax*tao(n));
end
end
plot(t,S_if)
Unrecognized function or variable 'S_if'.

类别

Help CenterFile Exchange 中查找有关 Spectral Measurements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by