Plotting a Surf of my waveform
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Nathan Kennedy
le 28 Nov 2017
Commenté : Star Strider
le 29 Nov 2017
Hi, my waveform is
sampling = 1 / (1*10^6); t = 0: sampling :0.05 ; %Sample Rate
f = (30 : 1 : 35)* (10^3); %Frequency Range
for a = 1:length(f) -1
y(a,:) = cos (2*pi .* f(a) .* t)
end
plot (t, sum(y)) % my waveform of 5 frequencies combined
xlim ([0 3] *10^-3) ; ylim([-6 6])
I am trying to get a 3d plot of my waveform.
So I think it should be
surf(t, new_value, y)
How do I declare the new_value to get my 3dimensional shape and how to properly scale the grid to X limits in the 2d plot? Totally stumped and getting blank figures appearing Ive also tried the below to get the grid dimensions equal to my sampling
[x,y] = meshgrid(0:sampling:0.05)
0 commentaires
Réponse acceptée
Star Strider
le 28 Nov 2017
I am not entirely certain what you want to do.
If I understand your Question, you can take advantage of vector multiplication to create a matrix of your frequencies and time, then just use mesh or surf to plot it. You do not even need meshgrid.
sampling = 1 / (1E+6);
t = 0: sampling :0.05 ; %Sample Rate
f = (30 : 1 : 35)* (1E+3); %Frequency Range
y = cos (2*pi .* f' * t);
figure(1)
mesh(t, f, y)
xlabel('Time')
ylabel('Frequency')
zlabel('Amplitude')
6 commentaires
Star Strider
le 29 Nov 2017
I can’t run your code because I don’t have the constants. However just looking at your code, I would plot it as:
plot((start_t : sampling : end_t),new_sum_z)
Initialise *‘z’*as:
z = zeros(size(y));
Since ‘new_sum_z’ is a vector, you cannot use it with the surface plot functions. Note that if you simply use repmat to create a matrix from it, the plot will duplicate the vector, and not change with respect to frequency.
Also, ‘x’ and ‘y’ will have the same results for length. Preallocating is good, however since you’re summing ‘z’ over time for each frequency in the loop, the result will always be a vector, not a matrix, and will always occupy the same memory locations. There is no reason to preallocate here.
I gave you the code that will plot the surface as functions of both time and frequency. I have no idea what you are doing.
Good luck!
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Surface and Mesh Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!