MATLAB: How to plot 3d vectors along x-axis as well y-axis to demonstrate the production of circularly polarised light

3d plotcircularly polarised wavephysicsplot3vectorvector plotwaves

I want to demonstrate formation of circularly and elliptically polarised light with superimposing two waves with phose difference pi/4 (one wave should be in xz plane and other shold be in yz plane).
As demonstrated below:
here green and blue should be the two waves and red must be the output.
i wrote code of
For plotting 2 periods of the signal
fs = 100000; %100KHz sampling frequency
f = 1000; %1KHz signal frequency
t = 0:1/fs:2*(1/f);
x = sin(2*pi*f*t);
y = sin(2*pi*f*t+pi/2);
plot3(t,x)
hold on
plot3(t,y)
hold on
plot3(t,x,y)
xlabel ("x");
ylabel ("y");
zlabel ("z");
output:
so here blue and red waves was supposed to be in xy and yz axis respectively but they are in same plane and the output wave is yellow in color.
I gues what I am plotting is not with vector diagram but just a scalar. so how to plot a vector?
also how will i get the resulted wave? with code
plot3(t,x,y)
or
plot3(t,x+y)?
what is the difference between both?
in theory it should be x+y

Best Answer

You need to provide a vector of zeros (here ‘zv’), then plot that as the ‘y’ and ‘z’ values for the two sine curves:
fs = 100000; %100KHz sampling frequency
f = 1000; %1KHz signal frequency
t = 0:1/fs:2*(1/f);
x = sin(2*pi*f*t);
y = sin(2*pi*f*t+pi/2);
zv = zeros(size(t));
plot3(t,x,zv)
hold on
plot3(t,zv,y)
hold on
plot3(t,x,y)
xlabel ("x");
ylabel ("y");
zlabel ("z");
grid on
set(gca, 'YTick',[-1 1], 'ZTick',[-1 1])
axis square
I added the grid call to give a reference, and limited the tick values to the extremes only so as not to interfere with the plotted data. The ‘axis square’ call is for aesthetics only. It is not necessary for the code to work.