plotting a signal which has two equations

1 visualizzazione (ultimi 30 giorni)
Moussa Ihab
Moussa Ihab il 12 Gen 2023
Modificato: Torsten il 12 Gen 2023
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)

Risposte (1)

Torsten
Torsten il 12 Gen 2023
Modificato: Torsten il 12 Gen 2023
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'.

Community Treasure Hunt

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

Start Hunting!

Translated by