matlab - How to plot a 3d graph of 2d fft transformations with a changing parameter -
i want make 3d plot of 2d plots of function y y dft of function z having axis k(x) w0(y) , amplitude(y)(z), k dft variable in frequency domain , w0 changing parameter between 0 , 4*pi/45.
n=(0:255); x1 = exp(n.*(w1*1j)); x2 = 0.8.*exp(n*((w2-w0)).*1j); z =hamming(256)*(x1+x2); y = fft(abs(z))
if i'm interpreting question properly, wish have this:
the x
axis dft number, y
axis parameter changes time-domain signal , z
magnitude of fft each signal.
what need define 2d grid of points x
number of fft points have... in case, that'll 256 points, , y
axis defines varying w0
term 0 4*pi/45
. structure grid such each row defines 1 dft result.
for this, use ndgrid
that, , following way:
max_dft_number = 256; num_w = 10; [w0,n] = ndgrid(linspace(0,4*pi/45,num_w), 0:max_dft_number-1);
max_dft_number
determines how many dft numbers want compute. in case, 256. can vary according how many dft numbers want. num_w
gives how many w0
points want between 0 4*pi/45
, linspace
gives set of linearly spaced points 0 4*pi/45
have num_w
of these points. set 10 here give illustration.
once have this, use x
, y
, substitute code above. don't define w1
, w2
, i'll assume it's constant:
w1 = 0.1; w2 = 0.2; x1 = exp(n.*(w1*1j)); %// change - vectorized x2 = 0.8.*exp(n.*((w2-w0)).*1j); %// change - vectorized z = bsxfun(@times,hamming(max_dft_number).', x1+x2); %// change - make sure hamming window applies on each row y = abs(fft(z, [], 2)); %// change - fft first, magnitude after. apply each row
i had use bsxfun
apply hamming window on each row of x1 + x2
. remember, each row dft result particular w0
parameter. had transpose hamming(256)
default output column. bsxfun
in case use of @times
duplicate hamming window coefficients every row gets multiplied same window. if provide matrix fft
, default applies fft on each column of matrix. don't want that, , want apply every row, , need fft(z,[],2);
that.
now, achieve desired plot, have use waterfall
function, takes in set 2d grid coordinates , corresponding output in z
direction. assumes each row individual trace of 3d function.... wanted.
so:
waterfall(n, w0, y); xlabel('dft number'); ylabel('w0'); zlabel('magnitude'); colormap([0 0 0]); %// make plot black view(-12,64); %// adjust view better
we get:
Comments
Post a Comment