Page 1 of 1

What is wrong with this MATLAB code ? Please fix it…. Im am trying to create a plot of two waves ref + source for all va

Posted: Thu May 05, 2022 6:58 pm
by answerhappygod
What is wrong with this MATLAB code ? Please fix it…. Im am
trying to create a plot of two waves ref + source for all values of
x and t and show a standing wave with all values of t plotted on
one graph.
%% CODE for plotting Amplitude (y) versus Distance
(x)
% Defining all the parameters
f = 3e9; % f is the
frequency
spd = 2e8; % spd is the speed of
the wave
A = 1; % A is the
Peak Amplitude
lmd = (spd/f); % lmd is the lamda value
L = 2*lmd; % L is the
Transmission line Length
beta = 2*pi/lmd; % beta is the beta value
t = 0:0.125e-9:0.5e-9 %time range
meu = (2*pi*f); % meu is the freq in radian/sec
ph = 180; %reflection phase in
degrees
x = 0:0.0001:L; %defining the x axis
spacing up to L
source = A*sin(beta*x)-(meu*t); %
source wave
ref = A*sin(beta*(L-x)-meu*t-ph); % reflected
wave
plot(x,(ref+source)); %plot
the resultant wave
xlabel ('distance');
ylabel ('amplitude');
grid ('on');
title ('amplitude y versus distance x');