0

I'm trying to create a 3d plot to show the amplitude of adding 3 sinusoids of varying phase. The three axes would be: time, frequency and magnitude. I'm just not sure how I can convert what I have into something that the function 3dplot can use. New to this, thanks!

clear;
clc;

inc = 100;
i = 1;
i2 = 1;
for t = 0:(2.413E-9)/inc:2.413E-9 %time range to view signals
for f = 56E9:(64E9-56E9)/inc:64E9 %frequencies from 56ghz - 64ghz

w = 2*pi*f;

wave1 = 0.5*sin(w.*t + (0.25*2));%sinusoids of varying distances, arbitrary amplitude
wave2 = 0.5*sin(w.*t);
wave3 = 0.5*sin(w.*t - (0.25*2));
mag = wave1 + wave2 + wave3;%combining waves

combined(i,i2,i) = mag;
    %f,time,magnitude

i = i + 1;%changing frequency index    
end
i = 1;
i2 = i2 + 1;%changing time index
end

EDIT: Thanks everyone, I think I have what I was looking for.

John Galt
  • 1
  • 1

1 Answers1

0

Here are some suggestions:

  • You probably want to replace combined(i,i2,i) = mag; by combined(i,i2) = mag;. That will create combined as a matrix (2D array) giving magnitude as a function of time and frequency
  • To plot that, use something like surf or imagesc.
  • The code can be vectorized. This makes it more compact, arguably more readable, and faster.
  • The figure changes significantly if you change inc. This may be a sign that the current inc is causing aliasing in the representation. You may want to increase that parameter.
  • You may want to avoid using i as variable name.

Code:

clear;
clc;
inc = 100;
t = 0:(2.413E-9)/inc:2.413E-9; %time range to view signals
f = 56E9:(64E9-56E9)/inc:64E9 %frequencies from 56ghz - 64ghz
w = 2*pi*f;
wave1 = 0.5*sin(bsxfun(@times, w.', t) + (0.25*2));%sinusoidsdistances
wave2 = 0.5*sin(bsxfun(@times, w.', t));
wave3 = 0.5*sin(bsxfun(@times, w.', t) - (0.25*2));
combined = wave1 + wave2 + wave3;%combining waves
%f,time,magnitude
surf(t, f, combined, 'edgecolor', 'none')
xlabel time
ylabel frequency

enter image description here

Luis Mendo
  • 110,752
  • 13
  • 76
  • 147