Plotting a Surf of my waveform
조회 수: 2 (최근 30일)
이전 댓글 표시
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
채택된 답변
Star Strider
2017년 11월 28일
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
Star Strider
2017년 11월 29일
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!
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!