matlab fft2 用法,Matlab自己的fft2没有循环(Matlab own fft2 without loops)

Matlab自己的fft2没有循环(Matlab own fft2 without loops)

我有个问题。

我有一个任务是在Matlab中不使用for循环编写自己的fft2。 有一个计算此任务的公式:

F(u,v)= sum(0到M-1){sum(o到N-1){f(m,n)* e ^( - i * 2pi *(um / M + vn / N)) }}

用两个for循环很容易做到但我不知道如何在没有这些循环的情况下做到这一点,绝对不知道。 我们没有得到教学人员的帮助。 他们甚至没有给出一本书的提示或参考,我们可以在那里读到它。

现在,我想尝试在这里获得帮助。

I have a problem.

I have a task to write an own fft2 without using for-loops in Matlab. There is a formula for computing this task:

F(u,v) = sum (0 to M-1) {sum(o to N-1) {f(m,n)*e^(-i*2pi*(um/M + vn/N))}}

It is easy to do it with two for-loops but I have no idea how to do this without these loops, absolutely no idea. We get no help by the teaching personal. They don't even give a hint or a reference to a book, where we could read about it.

Now, I want to try to get help here.

原文:https://stackoverflow.com/questions/26956249

更新时间:2019-12-06 08:23

最满意答案

你可以做类似的事情来获得2D DFT的矩阵形式。

你需要转换矩阵。 第一个是N-by-N DFT矩阵,它在f的列上运行,如上面的链接所述。 接下来,您需要另一个M-byM DFT矩阵,对f的行进行操作。 最后,你改变了信号

F = Wm * f * Wn;

没有任何循环。 注意,DFT矩阵也可以通过使用类似的东西来构造而没有循环

(1:M)*((1:M)')

Are you familiar with the matrix form of DFT? have a look here: http://en.wikipedia.org/wiki/DFT_matrix

You can do something similar in order to get a matrix form for 2D DFT.

You need to transformation matrices. The first is a N-by-N DFT matrix that operates on the columns of f, as explained in the link above. Next you need another M-byM DFT matrix the operates on the rows of f. Finally, you transformed signal is given by

F = Wm * f * Wn;

without any loops. Note that the DFT matrix can be constructed also without loop by using something like

(1:M)*((1:M)')

2014-11-16

相关问答

假设I是你的输入图像, F是它的傅立叶变换(即F = fft2(I) ) 你可以使用这个代码: F = fftshift(F); % Center FFT

F = abs(F); % Get the magnitude

F = log(F+1); % Use log, for perceptual scaling, and +1 since log(0) is undefined

F = mat2gray(F); % Use mat2gray to scale the image between

...

我假设这是对这个问题的跟进,它描述了你对ImageJ的使用,它提供了方向和频率参数的直接读数。 假设你有一个特定的像素A(i,j) ,那么可以使用以下方法获得像素/周期的方向和频率(由ImageJ类似地获得): center = size(A)/2 + 1;

dx = (j-center(2))/size(A,2);

dy = (center(1)-i-1)/size(A,1);

direction = atan2(dy, dx); % in radians

frequency = 1/sqrt

...

在具有长度L和M一维阵列x和y的情况下,如果mode="full" ,则需要将FFT填充到大小L + M - 1 。 对于2维情况,将该规则应用于每个轴。 使用numpy,你可以计算2-d情况下的大小 np.array(x.shape) + np.array(y.shape) - 1

要实现“有效”模式,您必须计算“完整”结果,然后切出有效部分。 对于1-d,假设L > M ,则有效数据是完整数据中心的L - M + 1元素。 同样,在2-d情况下对每个轴应用相同的规则。 例如, import

...

这看起来像你需要的: FEX 虽然我不确定你为什么不使用2D信息。 This looks like what you need: FEX Although I am not sure why you wouldn't just use the 2D information.

您熟悉DFT的矩阵形式吗? 看看这里: http : //en.wikipedia.org/wiki/DFT_matrix 你可以做类似的事情来获得2D DFT的矩阵形式。 你需要转换矩阵。 第一个是N-by-N DFT矩阵,它在f的列上运行,如上面的链接所述。 接下来,您需要另一个M-byM DFT矩阵,对f的行进行操作。 最后,你改变了信号 F = Wm * f * Wn;

没有任何循环。 注意,DFT矩阵也可以通过使用类似的东西来构造而没有循环 (1:M)*((1:M)')

Are yo

...

OpenCV的FFT实现可能没有Matlab那样优化。 如果您的FFT性能是您所需要的,那么请查看专用的FFT库,如FFTW 。 OpenCV's FFT implementation is probably not as optimized as Matlab's. If you FFT performance is what you require, then take a look at specialized FFT libraries like FFTW.

我能用以下代码得到一个非常好的情节 monolayer = double(imread('TEM_monolayer_graphene.bmp'));

monolayerFFTs = fftshift(fft2(monolayer));

contour(abs(monolayerFFTs));

I was able to get a really good plot with the following code monolayer = double(imread('TEM_monolayer_

...

是。 分别将fftfreq应用于每个空间矢量(x和y)。 然后从那些频率向量创建网格网格。 请注意,如果您希望在输出和新空间频率(使用meshgrid之前)中使用典型表示(空间频谱中心的零频率),则需要使用fftshift 。 Yes. Apply fftfreq to each spatial vector (x and y) separately. Then create a meshgrid from those frequency vectors. Note that you need t

...

使用output1 = output1.' 而不是output1 = output1'因为后者给出了共轭转置,你想要转置。 function [output1, output2] = fft2D(input)

output1 = input.';

output1 = fft(output1);

output1 = output1.';

output1 = fft(output1);

output2 = fft2(input);

end

或者,您可以指定尺寸以进行F

...

很长一段时间fft vs dft和Matlab vs c ++我都问过这个和类似的问题。 我找到的答案是, Matlab有一些内置软件,如MKL,Lapack和BLAS。 他们在场景后面使用c或Fortran库。 他们使用最好的实现。 例如,Matlab中的fft2是基于FFTW的。 (西方最快的傅立叶变换) 他们总是在改进。 对于某些功能,较新版本明显比旧版本快。 另一方面, 您没有使用最新版本的OpenCV,这会对性能产生一些影响。 您没有按照建议使用DFT,您可以通过获得最佳尺寸来提高速度。

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值