如何绘制具有变化参数的2d fft变换的3d图 [英] How to plot a 3d graph of 2d fft transformations with a changing parameter

查看:96
本文介绍了如何绘制具有变化参数的2d fft变换的3d图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要制作函数y的2d图的3d图 其中y是函数z的dft,具有作为轴k(x)的w0(y)和幅值(y)(z),其中k是频域中的dft变量,w0是0到4 * pi之间的变化参数/45.

I want to make a 3d plot of 2d plots of function y where y is the dft of function z with having as axis k(x) w0(y) and amplitude(y)(z), where k is the dft variable in frequency domain and w0 is a changing parameter between 0 and 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 your question properly, you wish to have something like this:

x轴是DFT编号,y轴是用于更改时域信号的参数,z是每个信号的FFT的幅度.

The x axis is the DFT number, the y axis is a parameter that changes your time-domain signal and z would be the magnitude of the FFT for each signal.

您需要做的是定义一个点的 2D 网格,其中x是您拥有的FFT点的数量...因此,在您的情况下,该点将为256个点,并且y轴定义从0到4*pi/45的变化的w0项.该网格的结构将使每个定义一个DFT结果.

What you need to do is define a 2D grid of points where x is the number of FFT points you have... so in your case, that'll be 256 points, and the y axis defines your varying w0 term from 0 to 4*pi/45. The structure for this grid will be such that each row defines one DFT result.

为此,请使用 ndgrid ,然后您可以通过以下方式进行操作:

For this, use ndgrid for that, and you do it the 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确定要计算的DFT数量.因此,在您的情况下,该值为256.您可以根据所需的DFT数量来改变它. num_w为您提供0到4*pi/45之间要多少个w0点,然后为

max_dft_number determines how many DFT numbers you want to compute. So in your case, that would be 256. You can vary that according to how many DFT numbers you want. num_w gives you how many w0 points you want between 0 to 4*pi/45, then linspace gives you a set of linearly spaced points from 0 to 4*pi/45 where we have num_w of these points. I set it to 10 here to give a good illustration.

一旦有了这个,只需使用XY并将其替换为上面的代码.您没有定义w1w2,所以我假设它是常量:

Once you have this, simply use X and Y and substitute it into your code above. You don't define w1 and w2, so 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 over each row
y = abs(fft(z, [], 2)); %// Change - FFT first, then magnitude after.  Apply to each row

我必须使用bsxfunx1 + x2的每个上应用汉明窗口.请记住,每一行都是特定w0参数的DFT结果.我还必须转置hamming(256),因为默认输出是一列.在这种情况下,使用@timesbsxfun将复制汉明窗系数,以便每一行都乘以同一窗.如果为fft提供矩阵,则默认情况下,它将FFT应用于矩阵的每一列.我们不想要那样,我们想将其应用于每个,因此您需要执行fft(z,[],2);来实现.

I had to use bsxfun to apply the Hamming window on each row of x1 + x2. Remember, each row is a DFT result for a particular w0 parameter. I also had to transpose hamming(256) as the default output is a column. bsxfun in this case with the use of @times will duplicate the Hamming window coefficients so that every row gets multiplied by the same window. If you provide a matrix to fft, by default it applies the FFT over each column of a matrix. We don't want that, and we want to apply this to every row, and so you would need to do fft(z,[],2); to do that.

现在,要最终获得所需的图,您所要做的就是使用

Now, to finally achieve your desired plot, all you have to do is use the waterfall function, which takes in a set 2D grid coordinates and the corresponding output in the z direction. It assumes that each row is an individual trace of a 3D function.... just like what you wanted.

所以:

waterfall(n, w0, y);
xlabel('DFT number');
ylabel('w0');
zlabel('Magnitude');
colormap([0 0 0]); %// Make plot all black
view(-12,64); %// Adjust view for better look

我们得到:

这篇关于如何绘制具有变化参数的2d fft变换的3d图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆